diff options
| author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 06:07:11 +0000 |
|---|---|---|
| committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-17 06:07:11 +0000 |
| commit | 75621c94b5dbe233edd72c3d8cc602fed25e84d2 (patch) | |
| tree | a38d832241e66a2e296e276493bff0260bfc9712 /db | |
| parent | 9bf8cb8d34039f3cef9e1b2f812ce634f2bebe69 (diff) | |
| download | gitlab-ce-75621c94b5dbe233edd72c3d8cc602fed25e84d2.tar.gz | |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
5 files changed, 160 insertions, 0 deletions
diff --git a/db/post_migrate/20230516032545_add_unique_notes_id_convert_to_bigint_for_gitlab_com.rb b/db/post_migrate/20230516032545_add_unique_notes_id_convert_to_bigint_for_gitlab_com.rb new file mode 100644 index 00000000000..330bf23434d --- /dev/null +++ b/db/post_migrate/20230516032545_add_unique_notes_id_convert_to_bigint_for_gitlab_com.rb @@ -0,0 +1,34 @@ +# 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 diff --git a/db/post_migrate/20230516033729_add_referencing_bigint_fks_for_notes_on_gitlab_com.rb b/db/post_migrate/20230516033729_add_referencing_bigint_fks_for_notes_on_gitlab_com.rb new file mode 100644 index 00000000000..0cc77d43625 --- /dev/null +++ b/db/post_migrate/20230516033729_add_referencing_bigint_fks_for_notes_on_gitlab_com.rb @@ -0,0 +1,74 @@ +# 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 diff --git a/db/schema_migrations/20230516032545 b/db/schema_migrations/20230516032545 new file mode 100644 index 00000000000..d9c5caaa3fd --- /dev/null +++ b/db/schema_migrations/20230516032545 @@ -0,0 +1 @@ +5f7e7d5b4af1a2e022e64ba2098c9e6be15853b2242334a41b4d53c5454201fe
\ No newline at end of file diff --git a/db/schema_migrations/20230516033729 b/db/schema_migrations/20230516033729 new file mode 100644 index 00000000000..128f8154d29 --- /dev/null +++ b/db/schema_migrations/20230516033729 @@ -0,0 +1 @@ +ab3a2fa247fa1170aa38ec0471f136b479d715137138929a4d690f7b6022d022
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index ed00829cb6e..013b0e67c9a 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -31559,6 +31559,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); @@ -35156,6 +35158,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; @@ -35447,6 +35452,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; @@ -35468,6 +35476,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; @@ -35783,6 +35794,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; @@ -35846,6 +35860,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; @@ -36005,6 +36022,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; @@ -36035,6 +36055,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; @@ -36062,6 +36085,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; @@ -36167,6 +36193,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; @@ -36596,6 +36625,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; @@ -36725,6 +36757,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; @@ -36752,6 +36787,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; @@ -36962,6 +37000,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; @@ -37079,6 +37120,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; @@ -37220,6 +37264,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; @@ -37370,6 +37417,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; |
