Skip to content
Snippets Groups Projects
Commit dfaad30d authored by Krasimir Angelov's avatar Krasimir Angelov :two:
Browse files

Prepare FKs for converting notes.id to bigint

We need these Fks in order to swap `notes.id` and
`notes.id_convert_to_bigint`. As it takes a lot of time to
create them, we have to do it _async_ for GitLab.com.

See #392815.

Changelog: other
parent 021ea81f
No related branches found
No related tags found
1 merge request!120816Prepare FKs for converting notes.id to bigint
# frozen_string_literal: true
class AddUniqueNotesIdConvertToBigintForGitlabCom < Gitlab::Database::Migration[2.1]
include Gitlab::Database::MigrationHelpers::ConvertToBigint
disable_ddl_transaction!
TABLE_NAME = :notes
INDEX_NAME = :index_notes_on_id_convert_to_bigint
def up
return unless should_run?
# This was created async for GitLab.com with
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/119913
# and will replace the existing PK index when we swap the integer and bigint columns in
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/119705
add_concurrent_index TABLE_NAME, :id_convert_to_bigint,
unique: true,
name: INDEX_NAME
end
def down
return unless should_run?
remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME)
end
private
def should_run?
com_or_dev_or_test_but_not_jh?
end
end
# frozen_string_literal: true
class AddReferencingBigintFksForNotesOnGitlabCom < Gitlab::Database::Migration[2.1]
include Gitlab::Database::MigrationHelpers::ConvertToBigint
disable_ddl_transaction!
REFERENCING_FOREIGN_KEYS = [
[:todos, :fk_91d1f47b13, :note_id, :cascade],
[:incident_management_timeline_events, :fk_d606a2a890, :promoted_from_note_id, :nullify],
[:system_note_metadata, :fk_d83a918cb1, :note_id, :cascade],
[:diff_note_positions, :fk_rails_13c7212859, :note_id, :cascade],
[:epic_user_mentions, :fk_rails_1c65976a49, :note_id, :cascade],
[:suggestions, :fk_rails_33b03a535c, :note_id, :cascade],
[:issue_user_mentions, :fk_rails_3861d9fefa, :note_id, :cascade],
[:note_diff_files, :fk_rails_3d66047aeb, :diff_note_id, :cascade],
[:snippet_user_mentions, :fk_rails_4d3f96b2cb, :note_id, :cascade],
[:design_user_mentions, :fk_rails_8de8c6d632, :note_id, :cascade],
[:vulnerability_user_mentions, :fk_rails_a18600f210, :note_id, :cascade],
[:commit_user_mentions, :fk_rails_a6760813e0, :note_id, :cascade],
[:merge_request_user_mentions, :fk_rails_c440b9ea31, :note_id, :cascade],
[:note_metadata, :fk_rails_d853224d37, :note_id, :cascade],
[:alert_management_alert_user_mentions, :fk_rails_eb2de0cdef, :note_id, :cascade],
[:timelogs, :fk_timelogs_note_id, :note_id, :nullify]
]
def up
return unless should_run?
REFERENCING_FOREIGN_KEYS.each do |(from_table, name, column, on_delete)|
temporary_name = "#{name}_tmp"
# This will replace the existing FKs when
# we swap the integer and bigint columns in
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/119705
add_concurrent_foreign_key(
from_table,
:notes,
column: column,
target_column: :id_convert_to_bigint,
name: temporary_name,
on_delete: on_delete,
reverse_lock_order: true,
validate: false)
prepare_async_foreign_key_validation from_table, column, name: temporary_name
end
end
def down
return unless should_run?
REFERENCING_FOREIGN_KEYS.each do |(from_table, name, column, _)|
temporary_name = "#{name}_tmp"
unprepare_async_foreign_key_validation from_table, column, name: temporary_name
with_lock_retries do
remove_foreign_key_if_exists(
from_table,
:notes,
name: temporary_name,
reverse_lock_order: true
)
end
end
end
private
def should_run?
com_or_dev_or_test_but_not_jh?
end
end
5f7e7d5b4af1a2e022e64ba2098c9e6be15853b2242334a41b4d53c5454201fe
\ No newline at end of file
ab3a2fa247fa1170aa38ec0471f136b479d715137138929a4d690f7b6022d022
\ No newline at end of file
......@@ -31528,6 +31528,8 @@ CREATE INDEX index_notes_on_created_at ON notes USING btree (created_at);
 
CREATE INDEX index_notes_on_discussion_id ON notes USING btree (discussion_id);
 
CREATE UNIQUE INDEX index_notes_on_id_convert_to_bigint ON notes USING btree (id_convert_to_bigint);
CREATE INDEX index_notes_on_id_where_confidential ON notes USING btree (id) WHERE (confidential = true);
 
CREATE INDEX index_notes_on_id_where_internal ON notes USING btree (id) WHERE (internal = true);
......@@ -35123,6 +35125,9 @@ ALTER TABLE ONLY protected_tags
ALTER TABLE ONLY todos
ADD CONSTRAINT fk_91d1f47b13 FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY todos
ADD CONSTRAINT fk_91d1f47b13_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY dast_site_profiles_builds
ADD CONSTRAINT fk_94e80df60e FOREIGN KEY (dast_site_profile_id) REFERENCES dast_site_profiles(id) ON DELETE CASCADE;
 
......@@ -35414,6 +35419,9 @@ ALTER TABLE ONLY ci_sources_pipelines
ALTER TABLE ONLY incident_management_timeline_events
ADD CONSTRAINT fk_d606a2a890 FOREIGN KEY (promoted_from_note_id) REFERENCES notes(id) ON DELETE SET NULL;
 
ALTER TABLE ONLY incident_management_timeline_events
ADD CONSTRAINT fk_d606a2a890_tmp FOREIGN KEY (promoted_from_note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE SET NULL NOT VALID;
ALTER TABLE ONLY lists
ADD CONSTRAINT fk_d6cf4279f7 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
 
......@@ -35435,6 +35443,9 @@ ALTER TABLE ONLY ci_pipelines
ALTER TABLE ONLY system_note_metadata
ADD CONSTRAINT fk_d83a918cb1 FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY system_note_metadata
ADD CONSTRAINT fk_d83a918cb1_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY sbom_occurrences
ADD CONSTRAINT fk_d857c6edc1 FOREIGN KEY (component_id) REFERENCES sbom_components(id) ON DELETE CASCADE;
 
......@@ -35750,6 +35761,9 @@ ALTER TABLE ONLY bulk_imports
ALTER TABLE ONLY diff_note_positions
ADD CONSTRAINT fk_rails_13c7212859 FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY diff_note_positions
ADD CONSTRAINT fk_rails_13c7212859_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY analytics_cycle_analytics_aggregations
ADD CONSTRAINT fk_rails_13c8374c7a FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
 
......@@ -35813,6 +35827,9 @@ ALTER TABLE ONLY board_assignees
ALTER TABLE ONLY epic_user_mentions
ADD CONSTRAINT fk_rails_1c65976a49 FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY epic_user_mentions
ADD CONSTRAINT fk_rails_1c65976a49_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY approver_groups
ADD CONSTRAINT fk_rails_1cdcbd7723 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
 
......@@ -35972,6 +35989,9 @@ ALTER TABLE ONLY alert_management_alert_metric_images
ALTER TABLE ONLY suggestions
ADD CONSTRAINT fk_rails_33b03a535c FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY suggestions
ADD CONSTRAINT fk_rails_33b03a535c_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY requirements
ADD CONSTRAINT fk_rails_33fed8aa4e FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL;
 
......@@ -36002,6 +36022,9 @@ ALTER TABLE ONLY packages_debian_project_distribution_keys
ALTER TABLE ONLY issue_user_mentions
ADD CONSTRAINT fk_rails_3861d9fefa FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY issue_user_mentions
ADD CONSTRAINT fk_rails_3861d9fefa_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY namespace_settings
ADD CONSTRAINT fk_rails_3896d4fae5 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
 
......@@ -36029,6 +36052,9 @@ ALTER TABLE ONLY cluster_groups
ALTER TABLE ONLY note_diff_files
ADD CONSTRAINT fk_rails_3d66047aeb FOREIGN KEY (diff_note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY note_diff_files
ADD CONSTRAINT fk_rails_3d66047aeb_tmp FOREIGN KEY (diff_note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY snippet_user_mentions
ADD CONSTRAINT fk_rails_3e00189191 FOREIGN KEY (snippet_id) REFERENCES snippets(id) ON DELETE CASCADE;
 
......@@ -36134,6 +36160,9 @@ ALTER TABLE ONLY scim_identities
ALTER TABLE ONLY snippet_user_mentions
ADD CONSTRAINT fk_rails_4d3f96b2cb FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY snippet_user_mentions
ADD CONSTRAINT fk_rails_4d3f96b2cb_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY protected_environment_approval_rules
ADD CONSTRAINT fk_rails_4e554f96f5 FOREIGN KEY (protected_environment_id) REFERENCES protected_environments(id) ON DELETE CASCADE;
 
......@@ -36563,6 +36592,9 @@ ALTER TABLE ONLY approval_merge_request_rules_approved_approvers
ALTER TABLE ONLY design_user_mentions
ADD CONSTRAINT fk_rails_8de8c6d632 FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY design_user_mentions
ADD CONSTRAINT fk_rails_8de8c6d632_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY clusters_kubernetes_namespaces
ADD CONSTRAINT fk_rails_8df789f3ab FOREIGN KEY (environment_id) REFERENCES environments(id) ON DELETE SET NULL;
 
......@@ -36692,6 +36724,9 @@ ALTER TABLE ONLY project_aliases
ALTER TABLE ONLY vulnerability_user_mentions
ADD CONSTRAINT fk_rails_a18600f210 FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY vulnerability_user_mentions
ADD CONSTRAINT fk_rails_a18600f210_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY todos
ADD CONSTRAINT fk_rails_a27c483435 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
 
......@@ -36719,6 +36754,9 @@ ALTER TABLE ONLY cluster_projects
ALTER TABLE ONLY commit_user_mentions
ADD CONSTRAINT fk_rails_a6760813e0 FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY commit_user_mentions
ADD CONSTRAINT fk_rails_a6760813e0_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY vulnerability_identifiers
ADD CONSTRAINT fk_rails_a67a16c885 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
 
......@@ -36929,6 +36967,9 @@ ALTER TABLE ONLY project_wiki_repositories
ALTER TABLE ONLY merge_request_user_mentions
ADD CONSTRAINT fk_rails_c440b9ea31 FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY merge_request_user_mentions
ADD CONSTRAINT fk_rails_c440b9ea31_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY user_achievements
ADD CONSTRAINT fk_rails_c44f5b3b25 FOREIGN KEY (achievement_id) REFERENCES achievements(id) ON DELETE CASCADE;
 
......@@ -37043,6 +37084,9 @@ ALTER TABLE ONLY packages_rpm_metadata
ALTER TABLE ONLY note_metadata
ADD CONSTRAINT fk_rails_d853224d37 FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY note_metadata
ADD CONSTRAINT fk_rails_d853224d37_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY merge_request_reviewers
ADD CONSTRAINT fk_rails_d9fec24b9d FOREIGN KEY (merge_request_id) REFERENCES merge_requests(id) ON DELETE CASCADE;
 
......@@ -37184,6 +37228,9 @@ ALTER TABLE ONLY protected_branch_unprotect_access_levels
ALTER TABLE ONLY alert_management_alert_user_mentions
ADD CONSTRAINT fk_rails_eb2de0cdef FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE CASCADE;
 
ALTER TABLE ONLY alert_management_alert_user_mentions
ADD CONSTRAINT fk_rails_eb2de0cdef_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE CASCADE NOT VALID;
ALTER TABLE ONLY snippet_statistics
ADD CONSTRAINT fk_rails_ebc283ccf1 FOREIGN KEY (snippet_id) REFERENCES snippets(id) ON DELETE CASCADE;
 
......@@ -37334,6 +37381,9 @@ ALTER TABLE ONLY timelogs
ALTER TABLE ONLY timelogs
ADD CONSTRAINT fk_timelogs_note_id FOREIGN KEY (note_id) REFERENCES notes(id) ON DELETE SET NULL;
 
ALTER TABLE ONLY timelogs
ADD CONSTRAINT fk_timelogs_note_id_tmp FOREIGN KEY (note_id) REFERENCES notes(id_convert_to_bigint) ON DELETE SET NULL NOT VALID;
ALTER TABLE ONLY u2f_registrations
ADD CONSTRAINT fk_u2f_registrations_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
 
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment