Module: ChronoModel::Adapter::MigrationsModules::Stable

Included in:
ChronoModel::Adapter::Migrations
Defined in:
lib/chrono_model/adapter/migrations_modules/stable.rb

Instance Method Summary collapse

Instance Method Details

#add_index(table_name, column_name, **options) ⇒ Object

If adding an index to a temporal table, add it to the one in the temporal schema and to the history one. If the ‘:unique` option is present, it is removed from the index created in the history table.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/chrono_model/adapter/migrations_modules/stable.rb', line 11

def add_index(table_name, column_name, **options)
  return super unless is_chrono?(table_name)

  transaction do
    on_temporal_schema { super }

    # Uniqueness constraints do not make sense in the history table
    options = options.dup.tap { |o| o.delete(:unique) } if options[:unique].present?

    on_history_schema { super(table_name, column_name, **options) }
  end
end

#remove_index(table_name, column_name = nil, **options) ⇒ Object

If removing an index from a temporal table, remove it both from the temporal and the history schemas.



27
28
29
30
31
32
33
34
35
# File 'lib/chrono_model/adapter/migrations_modules/stable.rb', line 27

def remove_index(table_name, column_name = nil, **options)
  return super unless is_chrono?(table_name)

  transaction do
    on_temporal_schema { super }

    on_history_schema { super }
  end
end