class Cauchy::Migration

Constants

CREATION_SETTINGS

Attributes

new_schema[RW]
schema[RW]

Public Class Methods

new(schema, new_schema) click to toggle source
# File lib/cauchy/migration.rb, line 13
def initialize(schema, new_schema)
  @schema = schema
  @new_schema = new_schema
end

Public Instance Methods

changed_settings() click to toggle source
# File lib/cauchy/migration.rb, line 35
def changed_settings
  new_schema.settings.select do |name, setting|
    schema.settings[name] != setting
  end.to_h
end
changes_creation_settings?() click to toggle source
# File lib/cauchy/migration.rb, line 45
def changes_creation_settings?
  schema.settings.slice(*CREATION_SETTINGS).except(*removed_settings) !=
    new_schema.settings.slice(*CREATION_SETTINGS)
end
changes_existing_mappings?() click to toggle source
# File lib/cauchy/migration.rb, line 27
def changes_existing_mappings?
  (new_schema.types & schema.types).any? do |type|
    mapping, new_mapping = schema.mapping_for(type), new_schema.mapping_for(type)
    common_fields = mapping.keys & new_mapping.keys
    mapping.slice(*common_fields) != new_mapping.slice(*common_fields)
  end
end
changes_mappings?() click to toggle source
# File lib/cauchy/migration.rb, line 18
def changes_mappings?
  (new_schema.types - schema.types).any? ||
    (new_schema.types & schema.types).any? do |type|
      mapping, new_mapping = schema.mapping_for(type), new_schema.mapping_for(type)
      removed_fields = mapping.keys - new_mapping.keys
      mapping.except(*removed_fields) != new_mapping
    end
end
changes_settings?() click to toggle source
# File lib/cauchy/migration.rb, line 41
def changes_settings?
  changed_settings.present?
end
mappings_diffs() click to toggle source
# File lib/cauchy/migration.rb, line 62
def mappings_diffs
  (schema.mappings.keys | new_schema.mappings.keys).map do |type|
    diff = Diffy::Diff.new(
      JSON.pretty_generate(schema.mappings[type] || {}) + "\n",
      JSON.pretty_generate(new_schema.mappings[type] || {}) + "\n",
      context: 3
    )
    [type, diff]
  end.to_h
end
removed_settings() click to toggle source
# File lib/cauchy/migration.rb, line 50
def removed_settings
  schema.settings.keys - new_schema.settings.keys
end
requires_reindex?() click to toggle source
# File lib/cauchy/migration.rb, line 54
def requires_reindex?
  changes_creation_settings? || changes_existing_mappings?
end
settings_diff() click to toggle source
# File lib/cauchy/migration.rb, line 73
def settings_diff
  Diffy::Diff.new(
    JSON.pretty_generate(schema.settings.except(*removed_settings)) + "\n",
    JSON.pretty_generate(new_schema.settings.except(*removed_settings)) + "\n",
    context: 3
  )
end
up_to_date?() click to toggle source
# File lib/cauchy/migration.rb, line 58
def up_to_date?
  !(changes_settings? || changes_mappings?)
end