Module: Gitlab::Database::MigrationHelpers::AutomaticLockWritesOnTables

Extended by:
ActiveSupport::Concern
Included in:
Gitlab::Database::Migration::V2_1
Defined in:
lib/gitlab/database/migration_helpers/automatic_lock_writes_on_tables.rb

Instance Method Summary collapse

Instance Method Details

#exec_migration(connection, direction) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab/database/migration_helpers/automatic_lock_writes_on_tables.rb', line 13

def exec_migration(connection, direction)
  db_config_name = Gitlab::Database.db_config_name(connection)
  db_info = Gitlab::Database.all_database_connections.fetch(db_config_name)
  return super if db_info.lock_gitlab_schemas.empty?
  return super if automatic_lock_on_writes_disabled?

  # This compares the tables only on the `public` schema. Partitions are not affected
  tables = connection.tables
  super
  new_tables = connection.tables - tables

  new_tables.each do |table_name|
    lock_writes_on_table(connection, table_name) if should_lock_writes_on_table?(db_info, table_name)
  end
end