Module: Elastics::Tasks::Migrations
- Included in:
- Elastics::Tasks
- Defined in:
- lib/elastics/tasks/migrations.rb
Instance Method Summary collapse
- #migrate(options = {}) ⇒ Object
- #migrate!(options = {}) ⇒ Object
- #models_to_reindex(options = {}) ⇒ Object
- #reindex(options = {}) ⇒ Object
Instance Method Details
#migrate(options = {}) ⇒ Object
4 5 6 7 |
# File 'lib/elastics/tasks/migrations.rb', line 4 def migrate( = {}) create_indices() put_mappings() end |
#migrate!(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/elastics/tasks/migrations.rb', line 9 def migrate!( = {}) = .merge version: :next drop_indices() create_indices() put_mappings() reindex() if .fetch(:reindex, true) forward_aliases() end |
#models_to_reindex(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/elastics/tasks/migrations.rb', line 30 def models_to_reindex( = {}) indices = [:indices].try!(:map, &:to_s) types = [:types].try!(:map, &:to_s) models = Elastics.models.select do |model| next if indices && !indices.include?(model.elastics_index_base) next if types && !types.include?(model.elastics_type_name) true end models.reject { |model| models.find { |other| model < other } } end |
#reindex(options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/elastics/tasks/migrations.rb', line 18 def reindex( = {}) version = .fetch(:version, :current) Rails.application.eager_load! if defined?(Rails) VersionManager.use_version version do models_to_reindex().each do |model| log "Reindexing #{model.elastics_index_base} into " \ "#{model.elastics_index_name}/#{model.elastics_type_name}" model.reindex_elastics end end end |