diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-12 12:14:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-12 12:14:57 +0300 |
commit | 60e7627c998b74d48df10b9a7759d6038a1f139c (patch) | |
tree | 9b643b2e776ea868f4e1546cf1f1fd40bbb10e0f /db | |
parent | 913af9b06edd2eff6cba93b1daca6c061b93be91 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'db')
5 files changed, 102 insertions, 7 deletions
diff --git a/db/post_migrate/20230403041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com.rb b/db/post_migrate/20230403041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com.rb new file mode 100644 index 00000000000..e2a08276343 --- /dev/null +++ b/db/post_migrate/20230403041917_swap_issue_user_mentions_note_id_to_bigint_for_gitlab_dot_com.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +class SwapIssueUserMentionsNoteIdToBigintForGitlabDotCom < Gitlab::Database::Migration[2.1] + include Gitlab::Database::MigrationHelpers::ConvertToBigint + + disable_ddl_transaction! + + TABLE_NAME = 'issue_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_issue_user_mentions_on_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_issue_user_mentions_note_id_convert_to_bigint', + on_delete: :cascade, + validate: false + end + + def swap + # This will replace the existing index_issue_user_mentions_on_note_id + add_concurrent_index TABLE_NAME, :note_id_convert_to_bigint, unique: true, + name: 'index_issue_user_mentions_on_note_id_convert_to_bigint', + where: 'note_id_convert_to_bigint IS NOT NULL' + + # This will replace the existing issue_user_mentions_on_issue_id_and_note_id_index + add_concurrent_index TABLE_NAME, [:issue_id, :note_id_convert_to_bigint], unique: true, + name: 'tmp_issue_user_mentions_on_issue_id_and_note_id_index' + + # This will replace the existing issue_user_mentions_on_issue_id_index + add_concurrent_index TABLE_NAME, :issue_id, unique: true, + name: 'tmp_issue_user_mentions_on_issue_id_index', + where: 'note_id_convert_to_bigint IS NULL' + + # This will replace the existing fk_rails_3861d9fefa + add_concurrent_foreign_key TABLE_NAME, :notes, column: :note_id_convert_to_bigint, + name: 'fk_issue_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_issue_user_mentions_on_note_id' + rename_index TABLE_NAME, 'index_issue_user_mentions_on_note_id_convert_to_bigint', + 'index_issue_user_mentions_on_note_id' + + execute 'DROP INDEX IF EXISTS issue_user_mentions_on_issue_id_and_note_id_index' + rename_index TABLE_NAME, 'tmp_issue_user_mentions_on_issue_id_and_note_id_index', + 'issue_user_mentions_on_issue_id_and_note_id_index' + + execute 'DROP INDEX IF EXISTS issue_user_mentions_on_issue_id_index' + rename_index TABLE_NAME, 'tmp_issue_user_mentions_on_issue_id_index', + 'issue_user_mentions_on_issue_id_index' + + execute "ALTER TABLE #{TABLE_NAME} DROP CONSTRAINT IF EXISTS fk_rails_3861d9fefa" + rename_constraint(TABLE_NAME, 'fk_issue_user_mentions_note_id_convert_to_bigint', 'fk_rails_3861d9fefa') + end + end + + def should_run? + com_or_dev_or_test_but_not_jh? + end +end diff --git a/db/post_migrate/20230410111251_async_validate_fk_projects_creator_id.rb b/db/post_migrate/20230410111251_async_validate_fk_projects_creator_id.rb new file mode 100644 index 00000000000..b1ac2469c78 --- /dev/null +++ b/db/post_migrate/20230410111251_async_validate_fk_projects_creator_id.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +class AsyncValidateFkProjectsCreatorId < Gitlab::Database::Migration[2.1] + TABLE_NAME = :projects + COLUMN_NAME = :creator_id + FK_NAME = :fk_03ec10b0d3 + + def up + prepare_async_foreign_key_validation TABLE_NAME, COLUMN_NAME, name: FK_NAME + end + + def down + unprepare_async_foreign_key_validation TABLE_NAME, COLUMN_NAME, name: FK_NAME + end +end diff --git a/db/schema_migrations/20230403041917 b/db/schema_migrations/20230403041917 new file mode 100644 index 00000000000..bc3e2d3b2e2 --- /dev/null +++ b/db/schema_migrations/20230403041917 @@ -0,0 +1 @@ +3387abc29b2c499b8c1fafa8543f504d02cbca189b38f26a3776786416fa5820
\ No newline at end of file diff --git a/db/schema_migrations/20230410111251 b/db/schema_migrations/20230410111251 new file mode 100644 index 00000000000..37a559a91e7 --- /dev/null +++ b/db/schema_migrations/20230410111251 @@ -0,0 +1 @@ +4955274e8f504af6e06432bd195e64eb6c520118a50f7da19af2fcf5872459cf
\ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index a09543d9a57..1fe90c6f031 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -17365,11 +17365,11 @@ ALTER SEQUENCE issue_tracker_data_id_seq OWNED BY issue_tracker_data.id; CREATE TABLE issue_user_mentions ( id bigint NOT NULL, issue_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 issue_user_mentions_id_seq @@ -30802,8 +30802,6 @@ CREATE INDEX index_issue_tracker_data_on_integration_id ON issue_tracker_data US CREATE UNIQUE INDEX index_issue_user_mentions_on_note_id ON issue_user_mentions USING btree (note_id) WHERE (note_id IS NOT NULL); -CREATE UNIQUE INDEX index_issue_user_mentions_on_note_id_convert_to_bigint ON issue_user_mentions USING btree (note_id_convert_to_bigint) WHERE (note_id_convert_to_bigint IS NOT NULL); - CREATE INDEX index_issues_on_author_id ON issues USING btree (author_id); CREATE INDEX index_issues_on_author_id_and_id_and_created_at ON issues USING btree (author_id, id, created_at); @@ -35269,9 +35267,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 issue_user_mentions - ADD CONSTRAINT fk_issue_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 ml_candidate_metrics ADD CONSTRAINT fk_ml_candidate_metrics_on_candidate_id FOREIGN KEY (candidate_id) REFERENCES ml_candidates(id) ON DELETE CASCADE; |