Module: Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers

Includes:
SchemaHelpers
Defined in:
lib/gitlab/database/migration_helpers/loose_foreign_key_helpers.rb

Constant Summary collapse

DELETED_RECORDS_INSERT_FUNCTION_NAME =
'insert_into_loose_foreign_keys_deleted_records'

Instance Method Summary collapse

Methods included from SchemaHelpers

#assert_not_in_transaction_block, #create_comment, #create_trigger, #create_trigger_function, #drop_function, #drop_trigger, #function_exists?, #object_name, #tmp_table_name, #trigger_exists?, #with_lock_retries

Instance Method Details

#track_record_deletions(table) ⇒ Object


11
12
13
14
15
16
17
18
# File 'lib/gitlab/database/migration_helpers/loose_foreign_key_helpers.rb', line 11

def track_record_deletions(table)
  execute(<<~SQL)
  CREATE TRIGGER #{record_deletion_trigger_name(table)}
  AFTER DELETE ON #{table} REFERENCING OLD TABLE AS old_table
  FOR EACH STATEMENT
  EXECUTE FUNCTION #{DELETED_RECORDS_INSERT_FUNCTION_NAME}();
  SQL
end

#untrack_record_deletions(table) ⇒ Object


20
21
22
# File 'lib/gitlab/database/migration_helpers/loose_foreign_key_helpers.rb', line 20

def untrack_record_deletions(table)
  drop_trigger(table, record_deletion_trigger_name(table))
end