Class: Mv::Core::Services::CreateMigrationValidatorsTable

Inherits:
Object
  • Object
show all
Defined in:
lib/mv/core/services/create_migration_validators_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db = ::ActiveRecord::Base.connection) ⇒ CreateMigrationValidatorsTable

Returns a new instance of CreateMigrationValidatorsTable.



8
9
10
# File 'lib/mv/core/services/create_migration_validators_table.rb', line 8

def initialize db = ::ActiveRecord::Base.connection
  @db = db
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



5
6
7
# File 'lib/mv/core/services/create_migration_validators_table.rb', line 5

def db
  @db
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mv/core/services/create_migration_validators_table.rb', line 12

def execute
  unless data_source_exists?(:migration_validators)
    ::ActiveRecord::Migration.say_with_time('initialize migration_validators table') do
      create_table(:migration_validators) do |table|
        table.string :table_name, null: false
        table.string :column_name, null: false
        table.string :validation_type, null: false
        table.string :options
      end

      add_index(:migration_validators,
                [:table_name, :column_name, :validation_type],
                name: 'unique_idx_on_migration_validators')
    end
  end
end