Module: Izolenta::ActiveRecordMigration

Defined in:
lib/izolenta/active_record_migration.rb

Defined Under Namespace

Modules: Helpers

Instance Method Summary collapse

Instance Method Details

#delegate_uniqueness(origin_table, column, **options) ⇒ Object

options:

wrapper_function: 'some_func' # some_func should be defined prior


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/izolenta/active_record_migration.rb', line 8

def delegate_uniqueness(origin_table, column, **options)
  helper_table_name = "#{column}_#{origin_table}_uniqs"

  reversible do |dir|
    dir.up do
      Helpers.create_helper_table(helper_table_name, column,
        Helpers.get_new_column_type(origin_table, column, **options))
      add_index(helper_table_name, column, unique: true)

      Helpers.create_sync_trigger(origin_table, column, helper_table_name, options)
    end

    dir.down do
      drop_table(helper_table_name)
      Helpers.drop_sync_trigger(origin_table, column)
    end
  end
end