Class: ElasticsearchRecord::SchemaMigration

Inherits:
Base
  • Object
show all
Defined in:
lib/elasticsearch_record/schema_migration.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_versionsObject



36
37
38
# File 'lib/elasticsearch_record/schema_migration.rb', line 36

def all_versions
  order(:version).pluck(:version)
end

.create_tableObject



16
17
18
19
20
21
22
# File 'lib/elasticsearch_record/schema_migration.rb', line 16

def create_table
  unless connection.table_exists?(table_name)
    connection.create_table(table_name, id: false) do |t|
      t.string :version, **connection.internal_string_options_for_primary_key
    end
  end
end

.drop_tableObject



24
25
26
# File 'lib/elasticsearch_record/schema_migration.rb', line 24

def drop_table
  connection.drop_table table_name, if_exists: true
end

.normalize_migration_number(number) ⇒ Object



28
29
30
# File 'lib/elasticsearch_record/schema_migration.rb', line 28

def normalize_migration_number(number)
  "%.3d" % number.to_i
end

.normalized_versionsObject



32
33
34
# File 'lib/elasticsearch_record/schema_migration.rb', line 32

def normalized_versions
  all_versions.map { |v| normalize_migration_number v }
end

.primary_keyObject



8
9
10
# File 'lib/elasticsearch_record/schema_migration.rb', line 8

def primary_key
  "version"
end

.table_exists?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/elasticsearch_record/schema_migration.rb', line 40

def table_exists?
  connection.data_source_exists?(table_name)
end

.table_nameObject



12
13
14
# File 'lib/elasticsearch_record/schema_migration.rb', line 12

def table_name
  "#{table_name_prefix}#{schema_migrations_table_name}#{table_name_suffix}"
end

Instance Method Details

#versionObject



45
46
47
# File 'lib/elasticsearch_record/schema_migration.rb', line 45

def version
  super.to_i
end