diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-22 15:08:21 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-22 15:08:21 +0000 |
commit | 8099b2824b5c3316af68fd8a5b9247c676a6d38b (patch) | |
tree | 8dafc7d7cd75d1020ae30cc905e9852bc3bb9804 /db | |
parent | f7b08f4264cfe86b35051778699dafc55efdbf5d (diff) | |
download | gitlab-ce-8099b2824b5c3316af68fd8a5b9247c676a6d38b.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
5 files changed, 116 insertions, 7 deletions
diff --git a/db/post_migrate/20230301020246_ensure_mr_user_mentions_note_id_bigint_backfill_is_finished_for_gitlab_dot_com.rb b/db/post_migrate/20230301020246_ensure_mr_user_mentions_note_id_bigint_backfill_is_finished_for_gitlab_dot_com.rb new file mode 100644 index 00000000000..90941af4eb2 --- /dev/null +++ b/db/post_migrate/20230301020246_ensure_mr_user_mentions_note_id_bigint_backfill_is_finished_for_gitlab_dot_com.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +class EnsureMrUserMentionsNoteIdBigintBackfillIsFinishedForGitlabDotCom < Gitlab::Database::Migration[2.1] + include Gitlab::Database::MigrationHelpers::ConvertToBigint + + restrict_gitlab_migration gitlab_schema: :gitlab_main + disable_ddl_transaction! + + def up + return unless should_run? + + ensure_batched_background_migration_is_finished( + job_class_name: 'CopyColumnUsingBackgroundMigrationJob', + table_name: 'merge_request_user_mentions', + column_name: 'id', + job_arguments: [['note_id'], ['note_id_convert_to_bigint']] + ) + end + + def down + # no-op + end + + private + + def should_run? + com_or_dev_or_test_but_not_jh? + end +end diff --git a/db/post_migrate/20230301020356_swap_merge_request_user_mentions_note_id_to_bigint.rb b/db/post_migrate/20230301020356_swap_merge_request_user_mentions_note_id_to_bigint.rb new file mode 100644 index 00000000000..11468a5844e --- /dev/null +++ b/db/post_migrate/20230301020356_swap_merge_request_user_mentions_note_id_to_bigint.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +class SwapMergeRequestUserMentionsNoteIdToBigint < Gitlab::Database::Migration[2.1] + include Gitlab::Database::MigrationHelpers::ConvertToBigint + + disable_ddl_transaction! + + TABLE_NAME = 'merge_request_user_mentions' + + def up + return unless should_run? + + swap + end + + def down + return unless should_run? + + swap + + add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true, + name: 'index_merge_request_user_mentions_note_id_convert_to_bigint', + where: 'note_id_convert_to_bigint IS NOT NULL' + + add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint, + name: 'fk_merge_request_user_mentions_note_id_convert_to_bigint', + on_delete: :cascade, + validate: false + end + + def swap + # This will replace the existing index_merge_request_user_mentions_on_note_id + add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true, + name: 'index_merge_request_user_mentions_note_id_convert_to_bigint', + where: 'note_id_convert_to_bigint IS NOT NULL' + + # This will replace the existing merge_request_user_mentions_on_mr_id_and_note_id_index + add_concurrent_index TABLE_NAME, [:merge_request_id, :note_id_convert_to_bigint], unique: true, + name: 'mr_user_mentions_on_mr_id_and_note_id_convert_to_bigint_index' + + # This will replace the existing merge_request_user_mentions_on_mr_id_index + add_concurrent_index TABLE_NAME, :merge_request_id, unique: true, + name: 'merge_request_user_mentions_on_mr_id_index_convert_to_bigint', + where: 'note_id_convert_to_bigint IS NULL' + + # This will replace the existing fk_rails_c440b9ea31 + add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint, + name: 'fk_merge_request_user_mentions_note_id_convert_to_bigint', + on_delete: :cascade + + with_lock_retries(raise_on_exhaustion: true) do + execute "LOCK TABLE notes, #{TABLE_NAME} IN ACCESS EXCLUSIVE MODE" + + execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id TO note_id_tmp" + execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_convert_to_bigint TO note_id" + execute "ALTER TABLE #{TABLE_NAME} RENAME COLUMN note_id_tmp TO note_id_convert_to_bigint" + + function_name = Gitlab::Database::UnidirectionalCopyTrigger + .on_table(TABLE_NAME, connection: connection) + .name(:note_id, :note_id_convert_to_bigint) + execute "ALTER FUNCTION #{quote_table_name(function_name)} RESET ALL" + + execute 'DROP INDEX IF EXISTS index_merge_request_user_mentions_on_note_id' + rename_index TABLE_NAME, 'index_merge_request_user_mentions_note_id_convert_to_bigint', + 'index_merge_request_user_mentions_on_note_id' + + execute 'DROP INDEX IF EXISTS merge_request_user_mentions_on_mr_id_and_note_id_index' + rename_index TABLE_NAME, 'mr_user_mentions_on_mr_id_and_note_id_convert_to_bigint_index', + 'merge_request_user_mentions_on_mr_id_and_note_id_index' + + execute 'DROP INDEX IF EXISTS merge_request_user_mentions_on_mr_id_index' + rename_index TABLE_NAME, 'merge_request_user_mentions_on_mr_id_index_convert_to_bigint', + 'merge_request_user_mentions_on_mr_id_index' + + execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT IF EXISTS fk_rails_c440b9ea31" + rename_constraint(TABLE_NAME, 'fk_merge_request_user_mentions_note_id_convert_to_bigint', 'fk_rails_c440b9ea31') + end + end + + def should_run? + com_or_dev_or_test_but_not_jh? + end +end diff --git a/db/schema_migrations/20230301020246 b/db/schema_migrations/20230301020246 new file mode 100644 index 00000000000..678aa0c10ee --- /dev/null +++ b/db/schema_migrations/20230301020246 @@ -0,0 +1 @@ +750ba0f9e60a72a8f8b2901d55d3fc763fe24ac2e8b6422b833d529230ec3a7f
\ No newline at end of file diff --git a/db/schema_migrations/20230301020356 b/db/schema_migrations/20230301020356 new file mode 100644 index 00000000000..d9feebb01c6 --- /dev/null +++ b/db/schema_migrations/20230301020356 @@ -0,0 +1 @@ +8a2a061050e8c2209e70498c6d1ebc68f557643565bbf93852ab6599ff819aa7
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index effbb09213e..527f20b0c99 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -18125,11 +18125,11 @@ ALTER SEQUENCE merge_request_reviewers_id_seq OWNED BY merge_request_reviewers.i CREATE TABLE merge_request_user_mentions ( id bigint NOT NULL, merge_request_id integer NOT NULL, - note_id integer, + note_id_convert_to_bigint integer, mentioned_users_ids integer[], mentioned_projects_ids integer[], mentioned_groups_ids integer[], - note_id_convert_to_bigint bigint + note_id bigint ); CREATE SEQUENCE merge_request_user_mentions_id_seq @@ -30888,8 +30888,6 @@ CREATE UNIQUE INDEX index_merge_request_reviewers_on_merge_request_id_and_user_i CREATE INDEX index_merge_request_reviewers_on_user_id ON merge_request_reviewers USING btree (user_id); -CREATE UNIQUE INDEX index_merge_request_user_mentions_note_id_convert_to_bigint ON merge_request_user_mentions USING btree (note_id_convert_to_bigint) WHERE (note_id_convert_to_bigint IS NOT NULL); - CREATE UNIQUE INDEX index_merge_request_user_mentions_on_note_id ON merge_request_user_mentions USING btree (note_id) WHERE (note_id IS NOT NULL); CREATE INDEX index_merge_requests_closing_issues_on_issue_id ON merge_requests_closing_issues USING btree (issue_id); @@ -35057,9 +35055,6 @@ ALTER TABLE ONLY issues ALTER TABLE ONLY geo_event_log ADD CONSTRAINT fk_geo_event_log_on_geo_event_id FOREIGN KEY (geo_event_id) REFERENCES geo_events(id) ON DELETE CASCADE; -ALTER TABLE ONLY merge_request_user_mentions - ADD CONSTRAINT fk_merge_request_user_mentions_note_id_convert_to_bigint FOREIGN KEY (note_id_convert_to_bigint) REFERENCES notes(id) ON DELETE CASCADE NOT VALID; - ALTER TABLE ONLY path_locks ADD CONSTRAINT fk_path_locks_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE; |