Skip to content
代码片段 群组 项目
未验证 提交 f6015519 编辑于 作者: Pedro Pombeiro's avatar Pedro Pombeiro 提交者: GitLab
浏览文件

No-op 20250307080100 migration and retry in 20250307080101

Changelog: other
上级 0fc836b0
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true # frozen_string_literal: true
class SwitchRecordChangeTrackingToPCiRunnerMachinesTable < Gitlab::Database::Migration[2.2] class SwitchRecordChangeTrackingToPCiRunnerMachinesTable < Gitlab::Database::Migration[2.2]
include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers
disable_ddl_transaction!
milestone '17.10' milestone '17.10'
PARTITIONED_TABLE = :ci_runner_machines
TABLES = %i[
instance_type_ci_runner_machines group_type_ci_runner_machines project_type_ci_runner_machines ci_runner_machines
].freeze
def up def up
# Remove current LFK trigger that is currently assigned to ci_runner_machines_archived, due to the call to # no-op due to https://gitlab.com/gitlab-com/gl-infra/production/-/issues/19476, retried in
# replace_with_partitioned_table: # RetrySwitchRecordChangeTrackingToPCiRunnerMachinesTable
# CREATE TRIGGER ci_runner_machines_loose_fk_trigger AFTER DELETE ON ci_runner_machines_archived
# REFERENCING OLD TABLE AS old_table
# FOR EACH STATEMENT EXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records();
drop_trigger(:ci_runner_machines_archived, :ci_runner_machines_loose_fk_trigger, if_exists: true)
# Reattaching the new trigger function to the existing partitioned tables
# but with an overridden table name
TABLES.each do |table|
with_lock_retries do
untrack_record_deletions(table)
track_record_deletions_override_table_name(table, PARTITIONED_TABLE)
end
end
end end
def down def down
TABLES.each do |table| # no-op
with_lock_retries do
untrack_record_deletions(table)
end
end
# Mimic track_record_deletions but in a way to restore the previous state
# (i.e. trigger on ci_runner_machines_archived but still named ci_runner_machines_loose_fk_trigger)
execute(<<~SQL.squish)
CREATE TRIGGER #{record_deletion_trigger_name(PARTITIONED_TABLE)}
AFTER DELETE ON ci_runner_machines_archived REFERENCING OLD TABLE AS old_table
FOR EACH STATEMENT
EXECUTE FUNCTION #{INSERT_FUNCTION_NAME}();
SQL
end end
end end
# frozen_string_literal: true
class RetrySwitchRecordChangeTrackingToPCiRunnerMachinesTable < Gitlab::Database::Migration[2.2]
include Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers
disable_ddl_transaction!
milestone '17.10'
PARTITIONED_TABLE = :ci_runner_machines
TABLES = %i[
instance_type_ci_runner_machines group_type_ci_runner_machines project_type_ci_runner_machines ci_runner_machines
].freeze
def up
# Remove current LFK trigger that is currently assigned to ci_runner_machines_archived, due to the call to
# replace_with_partitioned_table:
# CREATE TRIGGER ci_runner_machines_loose_fk_trigger AFTER DELETE ON ci_runner_machines_archived
# REFERENCING OLD TABLE AS old_table
# FOR EACH STATEMENT EXECUTE FUNCTION insert_into_loose_foreign_keys_deleted_records();
with_lock_retries do
# rubocop:disable Migration/WithLockRetriesDisallowedMethod -- false positive
drop_trigger(:ci_runner_machines_archived, :ci_runner_machines_loose_fk_trigger)
# rubocop:enable Migration/WithLockRetriesDisallowedMethod
end
# Reattaching the new trigger function to the existing partitioned tables
# but with an overridden table name
TABLES.each do |table|
with_lock_retries do
untrack_record_deletions(table)
track_record_deletions_override_table_name(table, PARTITIONED_TABLE)
end
end
end
def down
TABLES.each do |table|
with_lock_retries do
untrack_record_deletions(table)
end
end
# Mimic track_record_deletions but in a way to restore the previous state
# (i.e. trigger on ci_runner_machines_archived but still named ci_runner_machines_loose_fk_trigger)
with_lock_retries do
execute(<<~SQL.squish)
CREATE TRIGGER #{record_deletion_trigger_name(PARTITIONED_TABLE)}
AFTER DELETE ON ci_runner_machines_archived REFERENCING OLD TABLE AS old_table
FOR EACH STATEMENT
EXECUTE FUNCTION #{INSERT_FUNCTION_NAME}();
SQL
end
end
end
3c998c5fb4772cdd55ce6018628cc76189793c2d4afd03de2a9affa98d0025a8
\ No newline at end of file
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册