Class: Mv::Core::Migration::Base

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mv/core/migration/base.rb

Constant Summary collapse

SUPPORTED_METHODS =
%i{ add_column remove_column rename_column 
change_column rename_table drop_table}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



20
21
22
23
# File 'lib/mv/core/migration/base.rb', line 20

def initialize()
  @operations_list = Mv::Core::Migration::Operations::List.new
  @operations_factory = Mv::Core::Migration::Operations::Factory.new()
end

Instance Attribute Details

#operations_factoryObject (readonly)

Returns the value of attribute operations_factory.



18
19
20
# File 'lib/mv/core/migration/base.rb', line 18

def operations_factory
  @operations_factory
end

#operations_listObject (readonly)

Returns the value of attribute operations_list.



18
19
20
# File 'lib/mv/core/migration/base.rb', line 18

def operations_list
  @operations_list
end

Instance Method Details

#add_column(table_name, column_name, opts) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/mv/core/migration/base.rb', line 57

def add_column table_name, column_name, opts
  return unless opts.present?
  
  unless disabled_validations?
    operation = operations_factory.create_operation(:add_column, table_name, column_name, opts)
    operations_list.add_operation(operation)
  end
end

#executeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mv/core/migration/base.rb', line 35

def execute
  if operations_list.present?
    Mv::Core::Services::CreateMigrationValidatorsTable.new.execute
    
    constraints_loader = Mv::Core::Services::LoadConstraints.new(operations_list.tables)

    old_constraints = constraints_loader.execute

    operations_list.execute()

    new_constraints = constraints_loader.execute

    constraints_comparizon = Mv::Core::Services::CompareConstraintArrays.new(old_constraints, new_constraints)
                                                                             .execute

    Mv::Core::Services::SynchronizeConstraints.new(constraints_comparizon[:added], 
                                                   constraints_comparizon[:updated], 
                                                   constraints_comparizon[:deleted])
                                              .execute
  end
end

#with_suppressed_validationsObject



66
67
68
69
70
# File 'lib/mv/core/migration/base.rb', line 66

def with_suppressed_validations
  disable_validations!
  yield
  enable_validations!
end