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

Add FK for bigint conversion for .com

1. A FK needed for the bigint conversion work
for system_note_metadata's id column is added
added to the com database and validated asynchronously.

2. A unique index added in an earlier MR in the same milestone is no-oped.
The index should be added together when the FK is synchronously added.
To restore the dev environment to a consistent state,
a migration is added to remove the unique index.

Changelog: other
上级 313f1614
No related branches found
No related tags found
无相关合并请求
......@@ -5,14 +5,15 @@ class AddUniqueIndexToSystemNoteMetadataOnIdConvertToBigint < Gitlab::Database::
milestone '16.9'
TABLE_NAME = :system_note_metadata
INDEX_NAME = 'index_system_note_metadata_pkey_on_id_convert_to_bigint'
def up
add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: INDEX_NAME
# no-op
# The index has been created asynchronously for GitLab.com
# The index is going to be used to back a primary key and a foreign key.
# Dropping the index would require dropping any foreign key associated with the index
# thus the index and the foreign key must be added in the same migration.
end
def down
remove_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: INDEX_NAME
# no-op
end
end
# frozen_string_literal: true
class DropUniqueIndexToSystemNoteMetadataOnIdConvertToBigint < Gitlab::Database::Migration[2.2]
disable_ddl_transaction!
milestone '16.9'
TABLE_NAME = :system_note_metadata
INDEX_NAME = 'index_system_note_metadata_pkey_on_id_convert_to_bigint'
def up
return if Gitlab.com?
remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME
end
def down
return if Gitlab.com?
add_concurrent_index TABLE_NAME, :id_convert_to_bigint, unique: true, name: INDEX_NAME
end
end
# frozen_string_literal: true
class AddFkToResourceLinkEventsSystemNoteMetadataIdConvertToBigintForCom < Gitlab::Database::Migration[2.2]
include Gitlab::Database::MigrationHelpers::ConvertToBigint # for the method `com_or_dev_or_test_but_not_jh?`
disable_ddl_transaction!
milestone '16.9'
TABLE_NAME = :resource_link_events
COLUMN = :system_note_metadata_id
TARGET_TABLE_NAME = :system_note_metadata
TARGET_COLUMN = :id_convert_to_bigint
INDEX_NAME = 'index_system_note_metadata_pkey_on_id_convert_to_bigint'
FK_NAME = 'fk_system_note_metadata_id_convert_to_bigint'
def up
return unless com_or_dev_or_test_but_not_jh?
add_concurrent_index(TARGET_TABLE_NAME, :id_convert_to_bigint, unique: true, name: INDEX_NAME)
add_concurrent_foreign_key(
TABLE_NAME,
TARGET_TABLE_NAME,
name: FK_NAME,
column: COLUMN,
target_column: TARGET_COLUMN,
on_delete: :cascade,
validate: false
)
end
def down
return unless com_or_dev_or_test_but_not_jh?
with_lock_retries do
remove_foreign_key_if_exists(
TABLE_NAME,
TARGET_TABLE_NAME,
name: FK_NAME,
reverse_lock_order: true
)
end
remove_concurrent_index_by_name(TARGET_TABLE_NAME, INDEX_NAME)
end
end
# frozen_string_literal: true
class ValidateFkOnResourceLinkEventsSystemNoteMetadataIdForCom < Gitlab::Database::Migration[2.2]
include Gitlab::Database::MigrationHelpers::ConvertToBigint # for the method `com_or_dev_or_test_but_not_jh?`
milestone '16.9'
TABLE_NAME = :resource_link_events
COLUMN = :system_note_metadata_id
FK_NAME = 'fk_system_note_metadata_id_convert_to_bigint'
def up
return unless com_or_dev_or_test_but_not_jh?
prepare_async_foreign_key_validation TABLE_NAME, COLUMN, name: FK_NAME
end
def down
return unless com_or_dev_or_test_but_not_jh?
unprepare_async_foreign_key_validation TABLE_NAME, COLUMN, name: FK_NAME
end
end
5b627596a1f7113560661563b1064fd57f6cfcf7dc59dd659156f0498a9b0b48
\ No newline at end of file
9d9a1ea947c9649bdd21a645136f89387c1035c6e8a6dea1866be65db40f77fa
\ No newline at end of file
95181aec9fa75ae026e79e8c617dc0e7a30387580eda194022e9295944d811be
\ No newline at end of file
......@@ -41090,6 +41090,9 @@ ALTER TABLE ONLY integrations
ALTER TABLE ONLY merge_requests
ADD CONSTRAINT fk_source_project FOREIGN KEY (source_project_id) REFERENCES projects(id) ON DELETE SET NULL;
 
ALTER TABLE ONLY resource_link_events
ADD CONSTRAINT fk_system_note_metadata_id_convert_to_bigint FOREIGN KEY (system_note_metadata_id) REFERENCES system_note_metadata(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY timelogs
ADD CONSTRAINT fk_timelogs_issues_issue_id FOREIGN KEY (issue_id) REFERENCES issues(id) ON DELETE CASCADE;
 
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册