diff --git a/db/docs/batched_background_migrations/backfill_snippet_user_mentions_snippet_organization_id.yml b/db/docs/batched_background_migrations/backfill_snippet_user_mentions_snippet_organization_id.yml new file mode 100644 index 0000000000000000000000000000000000000000..a8ae221afabeffeb31d4ceb0830b1af7c99ea0e9 --- /dev/null +++ b/db/docs/batched_background_migrations/backfill_snippet_user_mentions_snippet_organization_id.yml @@ -0,0 +1,8 @@ +--- +migration_job_name: BackfillSnippetUserMentionsSnippetOrganizationId +description: Backfills sharding key `snippet_user_mentions.snippet_organization_id` from `snippets`. +feature_category: source_code_management +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/180836 +milestone: '17.10' +queued_migration_version: 20250209004158 +finalized_by: # version of the migration that finalized this BBM diff --git a/db/docs/batched_background_migrations/backfill_snippet_user_mentions_snippet_project_id.yml b/db/docs/batched_background_migrations/backfill_snippet_user_mentions_snippet_project_id.yml new file mode 100644 index 0000000000000000000000000000000000000000..6b7aa11d0c93ef1cae04fa0a936ea298bade832b --- /dev/null +++ b/db/docs/batched_background_migrations/backfill_snippet_user_mentions_snippet_project_id.yml @@ -0,0 +1,8 @@ +--- +migration_job_name: BackfillSnippetUserMentionsSnippetProjectId +description: Backfills sharding key `snippet_user_mentions.snippet_project_id` from `snippets`. +feature_category: source_code_management +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/180836 +milestone: '17.10' +queued_migration_version: 20250209004153 +finalized_by: # version of the migration that finalized this BBM diff --git a/db/docs/snippet_user_mentions.yml b/db/docs/snippet_user_mentions.yml index 6593be58448a1b21fd2bb7f6e55ee92bd09a5bae..b00fa10cc412d3070145c05e3e2ddcfb0ab4cf57 100644 --- a/db/docs/snippet_user_mentions.yml +++ b/db/docs/snippet_user_mentions.yml @@ -29,3 +29,6 @@ desired_sharding_key: table: snippets sharding_key: organization_id belongs_to: snippet +desired_sharding_key_migration_job_name: +- BackfillSnippetUserMentionsSnippetProjectId +- BackfillSnippetUserMentionsSnippetOrganizationId diff --git a/db/migrate/20250209004149_add_snippet_project_id_to_snippet_user_mentions.rb b/db/migrate/20250209004149_add_snippet_project_id_to_snippet_user_mentions.rb new file mode 100644 index 0000000000000000000000000000000000000000..06e99cda5a601f544d9719f93b4a9f5b58a50c1d --- /dev/null +++ b/db/migrate/20250209004149_add_snippet_project_id_to_snippet_user_mentions.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddSnippetProjectIdToSnippetUserMentions < Gitlab::Database::Migration[2.2] + milestone '17.10' + + def change + add_column :snippet_user_mentions, :snippet_project_id, :bigint + end +end diff --git a/db/migrate/20250209004154_add_snippet_organization_id_to_snippet_user_mentions.rb b/db/migrate/20250209004154_add_snippet_organization_id_to_snippet_user_mentions.rb new file mode 100644 index 0000000000000000000000000000000000000000..f40b1e1c469588696c4654ec35ead50c18cf33d6 --- /dev/null +++ b/db/migrate/20250209004154_add_snippet_organization_id_to_snippet_user_mentions.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class AddSnippetOrganizationIdToSnippetUserMentions < Gitlab::Database::Migration[2.2] + milestone '17.10' + + def change + add_column :snippet_user_mentions, :snippet_organization_id, :bigint + end +end diff --git a/db/post_migrate/20250209004150_index_snippet_user_mentions_on_snippet_project_id.rb b/db/post_migrate/20250209004150_index_snippet_user_mentions_on_snippet_project_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..3d739f341e28e3ada177edd9285b7e066fcd9523 --- /dev/null +++ b/db/post_migrate/20250209004150_index_snippet_user_mentions_on_snippet_project_id.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class IndexSnippetUserMentionsOnSnippetProjectId < Gitlab::Database::Migration[2.2] + milestone '17.10' + disable_ddl_transaction! + + INDEX_NAME = 'index_snippet_user_mentions_on_snippet_project_id' + + def up + add_concurrent_index :snippet_user_mentions, :snippet_project_id, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :snippet_user_mentions, INDEX_NAME + end +end diff --git a/db/post_migrate/20250209004151_add_snippet_user_mentions_snippet_project_id_fk.rb b/db/post_migrate/20250209004151_add_snippet_user_mentions_snippet_project_id_fk.rb new file mode 100644 index 0000000000000000000000000000000000000000..b1928b6f6816f463169a1627b98ce7c41353dfef --- /dev/null +++ b/db/post_migrate/20250209004151_add_snippet_user_mentions_snippet_project_id_fk.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AddSnippetUserMentionsSnippetProjectIdFk < Gitlab::Database::Migration[2.2] + milestone '17.10' + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :snippet_user_mentions, :projects, column: :snippet_project_id, on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :snippet_user_mentions, column: :snippet_project_id + end + end +end diff --git a/db/post_migrate/20250209004152_add_snippet_user_mentions_snippet_project_id_trigger.rb b/db/post_migrate/20250209004152_add_snippet_user_mentions_snippet_project_id_trigger.rb new file mode 100644 index 0000000000000000000000000000000000000000..8b2985370bf22e9843df2a92dc892cdcb4efb870 --- /dev/null +++ b/db/post_migrate/20250209004152_add_snippet_user_mentions_snippet_project_id_trigger.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddSnippetUserMentionsSnippetProjectIdTrigger < Gitlab::Database::Migration[2.2] + milestone '17.10' + + def up + install_sharding_key_assignment_trigger( + table: :snippet_user_mentions, + sharding_key: :snippet_project_id, + parent_table: :snippets, + parent_sharding_key: :project_id, + foreign_key: :snippet_id + ) + end + + def down + remove_sharding_key_assignment_trigger( + table: :snippet_user_mentions, + sharding_key: :snippet_project_id, + parent_table: :snippets, + parent_sharding_key: :project_id, + foreign_key: :snippet_id + ) + end +end diff --git a/db/post_migrate/20250209004153_queue_backfill_snippet_user_mentions_snippet_project_id.rb b/db/post_migrate/20250209004153_queue_backfill_snippet_user_mentions_snippet_project_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..851570fa0f88a4447cc602fb7a84dde449ae585a --- /dev/null +++ b/db/post_migrate/20250209004153_queue_backfill_snippet_user_mentions_snippet_project_id.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +class QueueBackfillSnippetUserMentionsSnippetProjectId < Gitlab::Database::Migration[2.2] + milestone '17.10' + restrict_gitlab_migration gitlab_schema: :gitlab_main_cell + + MIGRATION = "BackfillSnippetUserMentionsSnippetProjectId" + DELAY_INTERVAL = 2.minutes + BATCH_SIZE = 1000 + SUB_BATCH_SIZE = 100 + + def up + queue_batched_background_migration( + MIGRATION, + :snippet_user_mentions, + :id, + :snippet_project_id, + :snippets, + :project_id, + :snippet_id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + delete_batched_background_migration( + MIGRATION, + :snippet_user_mentions, + :id, + [ + :snippet_project_id, + :snippets, + :project_id, + :snippet_id + ] + ) + end +end diff --git a/db/post_migrate/20250209004155_index_snippet_user_mentions_on_snippet_organization_id.rb b/db/post_migrate/20250209004155_index_snippet_user_mentions_on_snippet_organization_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..93e9e1e3bb63b4eeeb40e678a3ffe6853a9168d7 --- /dev/null +++ b/db/post_migrate/20250209004155_index_snippet_user_mentions_on_snippet_organization_id.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class IndexSnippetUserMentionsOnSnippetOrganizationId < Gitlab::Database::Migration[2.2] + milestone '17.10' + disable_ddl_transaction! + + INDEX_NAME = 'index_snippet_user_mentions_on_snippet_organization_id' + + def up + add_concurrent_index :snippet_user_mentions, :snippet_organization_id, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :snippet_user_mentions, INDEX_NAME + end +end diff --git a/db/post_migrate/20250209004156_add_snippet_user_mentions_snippet_organization_id_fk.rb b/db/post_migrate/20250209004156_add_snippet_user_mentions_snippet_organization_id_fk.rb new file mode 100644 index 0000000000000000000000000000000000000000..c2db38637e6977a1f8ec1e237706e2095837aefd --- /dev/null +++ b/db/post_migrate/20250209004156_add_snippet_user_mentions_snippet_organization_id_fk.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddSnippetUserMentionsSnippetOrganizationIdFk < Gitlab::Database::Migration[2.2] + milestone '17.10' + disable_ddl_transaction! + + def up + add_concurrent_foreign_key :snippet_user_mentions, :organizations, column: :snippet_organization_id, + on_delete: :cascade + end + + def down + with_lock_retries do + remove_foreign_key :snippet_user_mentions, column: :snippet_organization_id + end + end +end diff --git a/db/post_migrate/20250209004157_add_snippet_user_mentions_snippet_organization_id_trigger.rb b/db/post_migrate/20250209004157_add_snippet_user_mentions_snippet_organization_id_trigger.rb new file mode 100644 index 0000000000000000000000000000000000000000..1a1240eb47977c91805ee310609d442368d9e935 --- /dev/null +++ b/db/post_migrate/20250209004157_add_snippet_user_mentions_snippet_organization_id_trigger.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddSnippetUserMentionsSnippetOrganizationIdTrigger < Gitlab::Database::Migration[2.2] + milestone '17.10' + + def up + install_sharding_key_assignment_trigger( + table: :snippet_user_mentions, + sharding_key: :snippet_organization_id, + parent_table: :snippets, + parent_sharding_key: :organization_id, + foreign_key: :snippet_id + ) + end + + def down + remove_sharding_key_assignment_trigger( + table: :snippet_user_mentions, + sharding_key: :snippet_organization_id, + parent_table: :snippets, + parent_sharding_key: :organization_id, + foreign_key: :snippet_id + ) + end +end diff --git a/db/post_migrate/20250209004158_queue_backfill_snippet_user_mentions_snippet_organization_id.rb b/db/post_migrate/20250209004158_queue_backfill_snippet_user_mentions_snippet_organization_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..520235454b6c5d5aa53a0f734227a82a3b69926e --- /dev/null +++ b/db/post_migrate/20250209004158_queue_backfill_snippet_user_mentions_snippet_organization_id.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +class QueueBackfillSnippetUserMentionsSnippetOrganizationId < Gitlab::Database::Migration[2.2] + milestone '17.10' + restrict_gitlab_migration gitlab_schema: :gitlab_main_cell + + MIGRATION = "BackfillSnippetUserMentionsSnippetOrganizationId" + DELAY_INTERVAL = 2.minutes + BATCH_SIZE = 1000 + SUB_BATCH_SIZE = 100 + + def up + queue_batched_background_migration( + MIGRATION, + :snippet_user_mentions, + :id, + :snippet_organization_id, + :snippets, + :organization_id, + :snippet_id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + delete_batched_background_migration( + MIGRATION, + :snippet_user_mentions, + :id, + [ + :snippet_organization_id, + :snippets, + :organization_id, + :snippet_id + ] + ) + end +end diff --git a/db/schema_migrations/20250209004149 b/db/schema_migrations/20250209004149 new file mode 100644 index 0000000000000000000000000000000000000000..f5879fab2d40b56e72213f1777dba5105c3237c8 --- /dev/null +++ b/db/schema_migrations/20250209004149 @@ -0,0 +1 @@ +2b7d3200dbb39701dc29899fa9a91cb8fd6f4524c2dd18fa83809f3986000eb6 \ No newline at end of file diff --git a/db/schema_migrations/20250209004150 b/db/schema_migrations/20250209004150 new file mode 100644 index 0000000000000000000000000000000000000000..4191c06dc6ca0bc792c3bb7e03b2a362cff0eb13 --- /dev/null +++ b/db/schema_migrations/20250209004150 @@ -0,0 +1 @@ +889bd985841d24ba0726a7401e8bc41f8d85469c3c7ab70299eef09121203a9a \ No newline at end of file diff --git a/db/schema_migrations/20250209004151 b/db/schema_migrations/20250209004151 new file mode 100644 index 0000000000000000000000000000000000000000..fb57321ce9db6a96ff56bee69d78c747cdf0601a --- /dev/null +++ b/db/schema_migrations/20250209004151 @@ -0,0 +1 @@ +fbdf2c73b97679360386e74734f0be035f64bfc15abe62ff45fb761fb640568f \ No newline at end of file diff --git a/db/schema_migrations/20250209004152 b/db/schema_migrations/20250209004152 new file mode 100644 index 0000000000000000000000000000000000000000..5934d9500023cbd8f36f5294fbd3ff08473c0b87 --- /dev/null +++ b/db/schema_migrations/20250209004152 @@ -0,0 +1 @@ +ac9d9f71b29435b1283b52cc8bf0f90a1e6ff456fd4003e84152096a17ebfaab \ No newline at end of file diff --git a/db/schema_migrations/20250209004153 b/db/schema_migrations/20250209004153 new file mode 100644 index 0000000000000000000000000000000000000000..57b3fc39e52d26aed69cfd6caffd6eb7506dbcd0 --- /dev/null +++ b/db/schema_migrations/20250209004153 @@ -0,0 +1 @@ +707bb0c8657cd871427511c75efdc70e8745e8d38b9cf7491cb78e5e132b9452 \ No newline at end of file diff --git a/db/schema_migrations/20250209004154 b/db/schema_migrations/20250209004154 new file mode 100644 index 0000000000000000000000000000000000000000..0750302634f4f27b60788899a3c25aa4e6b4310d --- /dev/null +++ b/db/schema_migrations/20250209004154 @@ -0,0 +1 @@ +b9a499b4bfcd8933f92cf9e1f66da493e615d1cff94233271a280d4506ad6287 \ No newline at end of file diff --git a/db/schema_migrations/20250209004155 b/db/schema_migrations/20250209004155 new file mode 100644 index 0000000000000000000000000000000000000000..0b5eaadc812d8653c3e2116d3384ecda69abe422 --- /dev/null +++ b/db/schema_migrations/20250209004155 @@ -0,0 +1 @@ +cc669986d1c2e8896173e076c846a65e1bbe7d0fd4c438d80b90d3515d0d036f \ No newline at end of file diff --git a/db/schema_migrations/20250209004156 b/db/schema_migrations/20250209004156 new file mode 100644 index 0000000000000000000000000000000000000000..f520c863013127b4d526f2d88f816be4a49f0eb6 --- /dev/null +++ b/db/schema_migrations/20250209004156 @@ -0,0 +1 @@ +398980e7624f9591314c8117929c02c65a259a29f00c662e737b94429739c309 \ No newline at end of file diff --git a/db/schema_migrations/20250209004157 b/db/schema_migrations/20250209004157 new file mode 100644 index 0000000000000000000000000000000000000000..e20f1c3ff7817fca92d0a047f37c5893fd50315f --- /dev/null +++ b/db/schema_migrations/20250209004157 @@ -0,0 +1 @@ +38c5a2c2fb5e72a01c6b8004076f62b51403fefd0c9e4014ab7bfcad7db7ab98 \ No newline at end of file diff --git a/db/schema_migrations/20250209004158 b/db/schema_migrations/20250209004158 new file mode 100644 index 0000000000000000000000000000000000000000..58eb1c3741926826e1500aedf180cd587b446017 --- /dev/null +++ b/db/schema_migrations/20250209004158 @@ -0,0 +1 @@ +60c6ea7a1a479512f661ae542f430f1ddb6abe30a57bb2a301de4ef4e9bfed53 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 53517c277cc575522376413c1a2c0f9682984c3c..54d7f6789e87723b2ed512daef59b6b946fe6ba8 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2406,6 +2406,22 @@ RETURN NEW; END $$; +CREATE FUNCTION trigger_7495f5e0efcb() RETURNS trigger + LANGUAGE plpgsql + AS $$ +BEGIN +IF NEW."snippet_project_id" IS NULL THEN + SELECT "project_id" + INTO NEW."snippet_project_id" + FROM "snippets" + WHERE "snippets"."id" = NEW."snippet_id"; +END IF; + +RETURN NEW; + +END +$$; + CREATE FUNCTION trigger_765cae42cd77() RETURNS trigger LANGUAGE plpgsql AS $$ @@ -2883,6 +2899,22 @@ RETURN NEW; END $$; +CREATE FUNCTION trigger_93a5b044f4e8() RETURNS trigger + LANGUAGE plpgsql + AS $$ +BEGIN +IF NEW."snippet_organization_id" IS NULL THEN + SELECT "organization_id" + INTO NEW."snippet_organization_id" + FROM "snippets" + WHERE "snippets"."id" = NEW."snippet_id"; +END IF; + +RETURN NEW; + +END +$$; + CREATE FUNCTION trigger_94514aeadc50() RETURNS trigger LANGUAGE plpgsql AS $$ @@ -22076,7 +22108,9 @@ CREATE TABLE snippet_user_mentions ( mentioned_users_ids bigint[], mentioned_projects_ids bigint[], mentioned_groups_ids bigint[], - note_id bigint + note_id bigint, + snippet_project_id bigint, + snippet_organization_id bigint ); CREATE SEQUENCE snippet_user_mentions_id_seq @@ -35680,6 +35714,10 @@ CREATE INDEX index_snippet_repository_storage_moves_on_state ON snippet_reposito CREATE UNIQUE INDEX index_snippet_user_mentions_on_note_id ON snippet_user_mentions USING btree (note_id) WHERE (note_id IS NOT NULL); +CREATE INDEX index_snippet_user_mentions_on_snippet_organization_id ON snippet_user_mentions USING btree (snippet_organization_id); + +CREATE INDEX index_snippet_user_mentions_on_snippet_project_id ON snippet_user_mentions USING btree (snippet_project_id); + CREATE INDEX index_snippets_on_author_id ON snippets USING btree (author_id); CREATE INDEX index_snippets_on_content_trigram ON snippets USING gin (content gin_trgm_ops); @@ -39076,6 +39114,8 @@ CREATE TRIGGER trigger_70d3f0bba1de BEFORE INSERT OR UPDATE ON compliance_framew CREATE TRIGGER trigger_740afa9807b8 BEFORE INSERT OR UPDATE ON subscription_user_add_on_assignments FOR EACH ROW EXECUTE FUNCTION trigger_740afa9807b8(); +CREATE TRIGGER trigger_7495f5e0efcb BEFORE INSERT OR UPDATE ON snippet_user_mentions FOR EACH ROW EXECUTE FUNCTION trigger_7495f5e0efcb(); + CREATE TRIGGER trigger_765cae42cd77 BEFORE INSERT OR UPDATE ON bulk_import_trackers FOR EACH ROW EXECUTE FUNCTION trigger_765cae42cd77(); CREATE TRIGGER trigger_77d9fbad5b12 BEFORE INSERT OR UPDATE ON packages_debian_project_distribution_keys FOR EACH ROW EXECUTE FUNCTION trigger_77d9fbad5b12(); @@ -39142,6 +39182,8 @@ CREATE TRIGGER trigger_90fa5c6951f1 BEFORE INSERT OR UPDATE ON dast_profiles_tag CREATE TRIGGER trigger_9259aae92378 BEFORE INSERT OR UPDATE ON packages_build_infos FOR EACH ROW EXECUTE FUNCTION trigger_9259aae92378(); +CREATE TRIGGER trigger_93a5b044f4e8 BEFORE INSERT OR UPDATE ON snippet_user_mentions FOR EACH ROW EXECUTE FUNCTION trigger_93a5b044f4e8(); + CREATE TRIGGER trigger_94514aeadc50 BEFORE INSERT OR UPDATE ON deployment_approvals FOR EACH ROW EXECUTE FUNCTION trigger_94514aeadc50(); CREATE TRIGGER trigger_951ac22c24d7 BEFORE INSERT OR UPDATE ON required_code_owners_sections FOR EACH ROW EXECUTE FUNCTION trigger_951ac22c24d7(); @@ -40255,6 +40297,9 @@ ALTER TABLE ONLY subscription_user_add_on_assignments ALTER TABLE ONLY merge_requests_approval_rules_approver_users ADD CONSTRAINT fk_725cca295c FOREIGN KEY (approval_rule_id) REFERENCES merge_requests_approval_rules(id) ON DELETE CASCADE; +ALTER TABLE ONLY snippet_user_mentions + ADD CONSTRAINT fk_7280faac49 FOREIGN KEY (snippet_project_id) REFERENCES projects(id) ON DELETE CASCADE; + ALTER TABLE ONLY zentao_tracker_data ADD CONSTRAINT fk_72a0e59cd8 FOREIGN KEY (instance_integration_id) REFERENCES instance_integrations(id) ON DELETE CASCADE; @@ -41149,6 +41194,9 @@ ALTER TABLE ONLY project_control_compliance_statuses ALTER TABLE ONLY protected_branches ADD CONSTRAINT fk_de9216e774 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE; +ALTER TABLE ONLY snippet_user_mentions + ADD CONSTRAINT fk_def441dfc3 FOREIGN KEY (snippet_organization_id) REFERENCES organizations(id) ON DELETE CASCADE; + ALTER TABLE ONLY work_item_number_field_values ADD CONSTRAINT fk_df27ad8c35 FOREIGN KEY (work_item_id) REFERENCES issues(id) ON DELETE CASCADE; diff --git a/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_organization_id.rb b/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_organization_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..11ae10c9bc842c5c6c36f96a37b8958acd7096d4 --- /dev/null +++ b/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_organization_id.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + class BackfillSnippetUserMentionsSnippetOrganizationId < BackfillDesiredShardingKeyJob + operation_name :backfill_snippet_user_mentions_snippet_organization_id + feature_category :source_code_management + end + end +end diff --git a/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_project_id.rb b/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_project_id.rb new file mode 100644 index 0000000000000000000000000000000000000000..46670571c40b8ab9f0b99723184e2c86269b7985 --- /dev/null +++ b/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_project_id.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + class BackfillSnippetUserMentionsSnippetProjectId < BackfillDesiredShardingKeyJob + operation_name :backfill_snippet_user_mentions_snippet_project_id + feature_category :source_code_management + end + end +end diff --git a/spec/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_organization_id_spec.rb b/spec/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_organization_id_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..2c7b28345e5e090c07e04dedaff140d0c78b8f87 --- /dev/null +++ b/spec/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_organization_id_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetUserMentionsSnippetOrganizationId, + feature_category: :source_code_management, + schema: 20250209004154 do + include_examples 'desired sharding key backfill job' do + let(:batch_table) { :snippet_user_mentions } + let(:backfill_column) { :snippet_organization_id } + let(:backfill_via_table) { :snippets } + let(:backfill_via_column) { :organization_id } + let(:backfill_via_foreign_key) { :snippet_id } + end +end diff --git a/spec/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_project_id_spec.rb b/spec/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_project_id_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..afbbc17545932569e05bd39d01d8de87e8e63be8 --- /dev/null +++ b/spec/lib/gitlab/background_migration/backfill_snippet_user_mentions_snippet_project_id_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetUserMentionsSnippetProjectId, + feature_category: :source_code_management, + schema: 20250209004149 do + include_examples 'desired sharding key backfill job' do + let(:batch_table) { :snippet_user_mentions } + let(:backfill_column) { :snippet_project_id } + let(:backfill_via_table) { :snippets } + let(:backfill_via_column) { :project_id } + let(:backfill_via_foreign_key) { :snippet_id } + end +end diff --git a/spec/lib/gitlab/database/sharding_key_spec.rb b/spec/lib/gitlab/database/sharding_key_spec.rb index aaad4a76fa40b20976db018ad45540171d3195e3..65026b133f06fe0f67267eb2fadc863f2c8243f5 100644 --- a/spec/lib/gitlab/database/sharding_key_spec.rb +++ b/spec/lib/gitlab/database/sharding_key_spec.rb @@ -211,6 +211,7 @@ # To add a table to this list, create an issue under https://gitlab.com/groups/gitlab-org/-/epics/11670. # Use https://gitlab.com/gitlab-org/gitlab/-/issues/476206 as an example. work_in_progress = { + "snippet_user_mentions" => "https://gitlab.com/gitlab-org/gitlab/-/issues/517825", "bulk_import_failures" => "https://gitlab.com/gitlab-org/gitlab/-/issues/517824", "organization_users" => 'https://gitlab.com/gitlab-org/gitlab/-/issues/476210', "push_rules" => 'https://gitlab.com/gitlab-org/gitlab/-/issues/476212', diff --git a/spec/migrations/20250209004153_queue_backfill_snippet_user_mentions_snippet_project_id_spec.rb b/spec/migrations/20250209004153_queue_backfill_snippet_user_mentions_snippet_project_id_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..a3e22e5725ebe3f3d7a21a4c70ac7955f3969b28 --- /dev/null +++ b/spec/migrations/20250209004153_queue_backfill_snippet_user_mentions_snippet_project_id_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe QueueBackfillSnippetUserMentionsSnippetProjectId, feature_category: :source_code_management do + let!(:batched_migration) { described_class::MIGRATION } + + it 'schedules a new batched migration' do + reversible_migration do |migration| + migration.before -> { + expect(batched_migration).not_to have_scheduled_batched_migration + } + + migration.after -> { + expect(batched_migration).to have_scheduled_batched_migration( + table_name: :snippet_user_mentions, + column_name: :id, + interval: described_class::DELAY_INTERVAL, + batch_size: described_class::BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE, + gitlab_schema: :gitlab_main_cell, + job_arguments: [ + :snippet_project_id, + :snippets, + :project_id, + :snippet_id + ] + ) + } + end + end +end diff --git a/spec/migrations/20250209004158_queue_backfill_snippet_user_mentions_snippet_organization_id_spec.rb b/spec/migrations/20250209004158_queue_backfill_snippet_user_mentions_snippet_organization_id_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..5e9a5b82ff39b5a957fcff51c7faf6cbedfb9a3c --- /dev/null +++ b/spec/migrations/20250209004158_queue_backfill_snippet_user_mentions_snippet_organization_id_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe QueueBackfillSnippetUserMentionsSnippetOrganizationId, feature_category: :source_code_management do + let!(:batched_migration) { described_class::MIGRATION } + + it 'schedules a new batched migration' do + reversible_migration do |migration| + migration.before -> { + expect(batched_migration).not_to have_scheduled_batched_migration + } + + migration.after -> { + expect(batched_migration).to have_scheduled_batched_migration( + table_name: :snippet_user_mentions, + column_name: :id, + interval: described_class::DELAY_INTERVAL, + batch_size: described_class::BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE, + gitlab_schema: :gitlab_main_cell, + job_arguments: [ + :snippet_organization_id, + :snippets, + :organization_id, + :snippet_id + ] + ) + } + end + end +end