From 0dd488772122cc5bcbd6e5454faf36d35f9e414e Mon Sep 17 00:00:00 2001 From: hustewart Date: Mon, 20 Oct 2025 13:29:00 -0400 Subject: [PATCH 01/23] Backfill organization_id on pool_repositories This commit provides the batched background migration to backfill organization_id on pool_repositories. Additionally it provides the following: - database trigger to set organization_id to cover scenarios where model hooks are skipped - concurrent index on organization_id - foreign key constraint (NOT VALID) on organization_id - NOT NULL (NOT VALID) constraint on organization_id - specs The trigger was causing test cases to fail where we want to test that there is no organization_id, because it was getting added on INSERT. This commit temporarily drops the trigger for those tests and then addds it back. Changelog: added --- ...fill_pool_repositories_organization_id.yml | 8 + ...arding_key_trigger_to_pool_repositories.rb | 49 ++++ ...kfill_pool_repositories_organization_id.rb | 26 ++ ...to_pool_repositories_on_organization_id.rb | 19 ++ ...to_pool_repositories_on_organization_id.rb | 18 ++ ...raint_to_pool_repositories_sharding_key.rb | 21 ++ db/schema_migrations/20251006152354 | 1 + db/schema_migrations/20251008204550 | 1 + db/schema_migrations/20251008204839 | 1 + db/schema_migrations/20251008205011 | 1 + db/schema_migrations/20251008205112 | 1 + db/structure.sql | 35 ++- ...kfill_pool_repositories_organization_id.rb | 68 +++++ ..._pool_repositories_organization_id_spec.rb | 245 ++++++++++++++++++ ..._pool_repositories_organization_id_spec.rb | 26 ++ spec/models/pool_repository_spec.rb | 65 ++++- 16 files changed, 582 insertions(+), 3 deletions(-) create mode 100644 db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml create mode 100644 db/migrate/20251006152354_add_sharding_key_trigger_to_pool_repositories.rb create mode 100644 db/post_migrate/20251008204550_queue_backfill_pool_repositories_organization_id.rb create mode 100644 db/post_migrate/20251008204839_add_concurrent_index_to_pool_repositories_on_organization_id.rb create mode 100644 db/post_migrate/20251008205011_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb create mode 100644 db/post_migrate/20251008205112_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb create mode 100644 db/schema_migrations/20251006152354 create mode 100644 db/schema_migrations/20251008204550 create mode 100644 db/schema_migrations/20251008204839 create mode 100644 db/schema_migrations/20251008205011 create mode 100644 db/schema_migrations/20251008205112 create mode 100644 lib/gitlab/background_migration/backfill_pool_repositories_organization_id.rb create mode 100644 spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb create mode 100644 spec/migrations/20251008204550_queue_backfill_pool_repositories_organization_id_spec.rb diff --git a/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml b/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml new file mode 100644 index 00000000000000..c691c54601a809 --- /dev/null +++ b/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml @@ -0,0 +1,8 @@ +--- +migration_job_name: BackfillPoolRepositoriesOrganizationId +description: Backfills organization_id on pool_repositories +feature_category: source_code_management +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/208322 +milestone: '18.6' +queued_migration_version: 20251008204550 +finalized_by: # version of the migration that finalized this BBM diff --git a/db/migrate/20251006152354_add_sharding_key_trigger_to_pool_repositories.rb b/db/migrate/20251006152354_add_sharding_key_trigger_to_pool_repositories.rb new file mode 100644 index 00000000000000..b64a9a811c6b91 --- /dev/null +++ b/db/migrate/20251006152354_add_sharding_key_trigger_to_pool_repositories.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +class AddShardingKeyTriggerToPoolRepositories < Gitlab::Database::Migration[2.3] + include Gitlab::Database::SchemaHelpers + + milestone '18.5' + + TABLE_NAME = 'pool_repositories' + TRIGGER_FUNCTION_NAME = 'pool_repositories_sharding_key' + TRIGGER_NAME = "trigger_#{TRIGGER_FUNCTION_NAME}" + + def up + execute(<<~SQL) + CREATE OR REPLACE FUNCTION #{TRIGGER_FUNCTION_NAME}() RETURNS TRIGGER AS $$ + BEGIN + IF NEW.organization_id IS NOT NULL THEN + RETURN NEW; + END IF; + + IF NEW.source_project_id IS NOT NULL THEN + SELECT p.organization_id + INTO NEW.organization_id + FROM projects p + WHERE p.id = NEW.source_project_id; + + IF NEW.organization_id IS NOT NULL THEN + RETURN NEW; + END IF; + END IF; + + NEW.organization_id := 1; + RETURN NEW; + END; + $$ LANGUAGE plpgsql; + SQL + + create_trigger( + TABLE_NAME, + TRIGGER_NAME, + TRIGGER_FUNCTION_NAME, + fires: 'BEFORE INSERT OR UPDATE' + ) + end + + def down + drop_trigger(TABLE_NAME, TRIGGER_NAME) + drop_function(TRIGGER_FUNCTION_NAME) + end +end diff --git a/db/post_migrate/20251008204550_queue_backfill_pool_repositories_organization_id.rb b/db/post_migrate/20251008204550_queue_backfill_pool_repositories_organization_id.rb new file mode 100644 index 00000000000000..ba6533f150ade8 --- /dev/null +++ b/db/post_migrate/20251008204550_queue_backfill_pool_repositories_organization_id.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class QueueBackfillPoolRepositoriesOrganizationId < Gitlab::Database::Migration[2.3] + milestone '18.5' + + # Select the applicable gitlab schema for your batched background migration + restrict_gitlab_migration gitlab_schema: :gitlab_main_org + + MIGRATION = "BackfillPoolRepositoriesOrganizationId" + BATCH_SIZE = 1000 + SUB_BATCH_SIZE = 100 + + def up + queue_batched_background_migration( + MIGRATION, + :pool_repositories, + :id, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + delete_batched_background_migration(MIGRATION, :pool_repositories, :id, []) + end +end diff --git a/db/post_migrate/20251008204839_add_concurrent_index_to_pool_repositories_on_organization_id.rb b/db/post_migrate/20251008204839_add_concurrent_index_to_pool_repositories_on_organization_id.rb new file mode 100644 index 00000000000000..e3bac648c53bea --- /dev/null +++ b/db/post_migrate/20251008204839_add_concurrent_index_to_pool_repositories_on_organization_id.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddConcurrentIndexToPoolRepositoriesOnOrganizationId < Gitlab::Database::Migration[2.3] + disable_ddl_transaction! + milestone '18.5' + + INDEX_NAME = 'index_pool_repositories_on_organization_id' + + def up + add_concurrent_index :pool_repositories, :organization_id, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :pool_repositories, INDEX_NAME + end +end diff --git a/db/post_migrate/20251008205011_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb b/db/post_migrate/20251008205011_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb new file mode 100644 index 00000000000000..907b14f429bc83 --- /dev/null +++ b/db/post_migrate/20251008205011_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddNotValidForeignKeyConstraintToPoolRepositoriesOnOrganizationId < Gitlab::Database::Migration[2.3] + disable_ddl_transaction! + milestone '18.5' + + def up + add_concurrent_foreign_key( + :pool_repositories, :organizations, + column: :organization_id, + on_delete: :cascade, validate: false + ) + end + + def down + remove_foreign_key_if_exists :pool_repositories, column: :organization_id + end +end diff --git a/db/post_migrate/20251008205112_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb b/db/post_migrate/20251008205112_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb new file mode 100644 index 00000000000000..4ba30a844afd80 --- /dev/null +++ b/db/post_migrate/20251008205112_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddNotValidNotNullConstraintToPoolRepositoriesShardingKey < Gitlab::Database::Migration[2.3] + disable_ddl_transaction! + milestone '18.5' + + def up + add_not_null_constraint( + :pool_repositories, + :organization_id, + validate: false + ) + end + + def down + remove_not_null_constraint(:pool_repositories, :organization_id) + end +end diff --git a/db/schema_migrations/20251006152354 b/db/schema_migrations/20251006152354 new file mode 100644 index 00000000000000..523aba5134d453 --- /dev/null +++ b/db/schema_migrations/20251006152354 @@ -0,0 +1 @@ +c2b4ba3e5371c3fede2f389d510cd51bdba4d3041c1019dbc494aff229cae014 \ No newline at end of file diff --git a/db/schema_migrations/20251008204550 b/db/schema_migrations/20251008204550 new file mode 100644 index 00000000000000..802985d18497ba --- /dev/null +++ b/db/schema_migrations/20251008204550 @@ -0,0 +1 @@ +d29283ae3c5e7c7e66dafdcd44b09dc04324fb5bd9e1d1d3e7256d1bfe5251a1 \ No newline at end of file diff --git a/db/schema_migrations/20251008204839 b/db/schema_migrations/20251008204839 new file mode 100644 index 00000000000000..605b92a9862f30 --- /dev/null +++ b/db/schema_migrations/20251008204839 @@ -0,0 +1 @@ +f91d6d5b07adc9a3d9b48247306b70d5d62e3a4e9e3b0922da169ebd5717b4f7 \ No newline at end of file diff --git a/db/schema_migrations/20251008205011 b/db/schema_migrations/20251008205011 new file mode 100644 index 00000000000000..1ee92728f549a4 --- /dev/null +++ b/db/schema_migrations/20251008205011 @@ -0,0 +1 @@ +d50f05f057b9f0cebb5ee4988ae12c3d26fe893f0269f933a636c8bc2ac7cc74 \ No newline at end of file diff --git a/db/schema_migrations/20251008205112 b/db/schema_migrations/20251008205112 new file mode 100644 index 00000000000000..995599de3e7b7e --- /dev/null +++ b/db/schema_migrations/20251008205112 @@ -0,0 +1 @@ +d870205ddd464dcfabce49d55730e04b30ad40756d9892ac18c98df208c41d21 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 2188d6e075cd59..b58fe0ac260a53 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -817,6 +817,30 @@ RETURN NEW; END $$; +CREATE FUNCTION pool_repositories_sharding_key() RETURNS trigger + LANGUAGE plpgsql + AS $$ +BEGIN + IF NEW.organization_id IS NOT NULL THEN + RETURN NEW; + END IF; + + IF NEW.source_project_id IS NOT NULL THEN + SELECT p.organization_id + INTO NEW.organization_id + FROM projects p + WHERE p.id = NEW.source_project_id; + + IF NEW.organization_id IS NOT NULL THEN + RETURN NEW; + END IF; + END IF; + + NEW.organization_id := 1; + RETURN NEW; +END; +$$; + CREATE FUNCTION postgres_pg_stat_activity_autovacuum() RETURNS TABLE(query text, query_start timestamp with time zone) LANGUAGE sql SECURITY DEFINER SET search_path TO 'pg_catalog', 'pg_temp' @@ -35107,8 +35131,8 @@ ALTER TABLE merge_request_context_commit_diff_files ALTER TABLE system_note_metadata ADD CONSTRAINT check_9135b6f0b6 CHECK ((namespace_id IS NOT NULL)) NOT VALID; -ALTER TABLE slack_api_scopes - ADD CONSTRAINT check_930d89be0d CHECK ((organization_id IS NOT NULL)) NOT VALID; +ALTER TABLE pool_repositories + ADD CONSTRAINT check_96233d37c0 CHECK ((organization_id IS NOT NULL)) NOT VALID; ALTER TABLE related_epic_links ADD CONSTRAINT check_a6d9d7c276 CHECK ((issue_link_id IS NOT NULL)) NOT VALID; @@ -43709,6 +43733,8 @@ CREATE INDEX index_pm_package_version_licenses_on_pm_package_version_id ON pm_pa CREATE INDEX index_pm_package_versions_on_pm_package_id ON pm_package_versions USING btree (pm_package_id); +CREATE INDEX index_pool_repositories_on_organization_id ON pool_repositories USING btree (organization_id); + CREATE INDEX index_pool_repositories_on_shard_id ON pool_repositories USING btree (shard_id); CREATE UNIQUE INDEX index_pool_repositories_on_source_project_id_and_shard_id ON pool_repositories USING btree (source_project_id, shard_id); @@ -49775,6 +49801,8 @@ CREATE TRIGGER trigger_jira_tracker_data_sharding_key_on_insert BEFORE INSERT ON CREATE TRIGGER trigger_namespaces_traversal_ids_on_update AFTER UPDATE ON namespaces FOR EACH ROW WHEN ((old.traversal_ids IS DISTINCT FROM new.traversal_ids)) EXECUTE FUNCTION insert_namespaces_sync_event(); +CREATE TRIGGER trigger_pool_repositories_sharding_key BEFORE INSERT OR UPDATE ON pool_repositories FOR EACH ROW EXECUTE FUNCTION pool_repositories_sharding_key(); + CREATE TRIGGER trigger_projects_parent_id_on_insert AFTER INSERT ON projects FOR EACH ROW EXECUTE FUNCTION insert_projects_sync_event(); CREATE TRIGGER trigger_projects_parent_id_on_update AFTER UPDATE ON projects FOR EACH ROW WHEN ((old.namespace_id IS DISTINCT FROM new.namespace_id)) EXECUTE FUNCTION insert_projects_sync_event(); @@ -51106,6 +51134,9 @@ ALTER TABLE ONLY scan_result_policy_violations ALTER TABLE ONLY approval_project_rules ADD CONSTRAINT fk_773289d10b FOREIGN KEY (approval_policy_rule_id) REFERENCES approval_policy_rules(id) ON DELETE CASCADE; +ALTER TABLE ONLY pool_repositories + ADD CONSTRAINT fk_775c554d89 FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE NOT VALID; + ALTER TABLE ONLY agent_user_access_project_authorizations ADD CONSTRAINT fk_78034b05d8 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; diff --git a/lib/gitlab/background_migration/backfill_pool_repositories_organization_id.rb b/lib/gitlab/background_migration/backfill_pool_repositories_organization_id.rb new file mode 100644 index 00000000000000..3201f7d329441e --- /dev/null +++ b/lib/gitlab/background_migration/backfill_pool_repositories_organization_id.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +# See https://docs.gitlab.com/ee/development/database/batched_background_migrations.html +# for more information on how to use batched background migrations + +# Update below commented lines with appropriate values. + +module Gitlab + module BackgroundMigration + class BackfillPoolRepositoriesOrganizationId < BatchedMigrationJob + operation_name :backfill_pool_repositories_organization_id + + feature_category :source_code_management + + def perform + each_sub_batch do |sub_batch| + # Case 1: source_project_id is set, get organization from source project (PREFERRED) + connection.exec_update(update_from_source_project_sql(sub_batch)) + + # Case 2: source_project_id is empty, but we can detect organization + # through the member_projects (projects.pool_repository_id relation) + connection.exec_update(update_from_member_projects_sql(sub_batch)) + + # Case 3: No sharding key can be determined - assign default organization_id = 1 + connection.exec_update(update_with_default_organization_sql(sub_batch)) + end + end + + private + + def update_from_source_project_sql(sub_batch) + <<~SQL + UPDATE pool_repositories + SET organization_id = projects.organization_id + FROM projects + WHERE pool_repositories.source_project_id = projects.id + AND pool_repositories.organization_id IS NULL + AND pool_repositories.id IN (#{sub_batch.select(:id).to_sql}) + SQL + end + + def update_from_member_projects_sql(sub_batch) + <<~SQL + UPDATE pool_repositories + SET organization_id = subquery.organization_id + FROM ( + SELECT DISTINCT p.pool_repository_id, p.organization_id + FROM projects p + WHERE p.pool_repository_id IS NOT NULL + ) AS subquery + WHERE pool_repositories.id = subquery.pool_repository_id + AND pool_repositories.organization_id IS NULL + AND pool_repositories.source_project_id IS NULL + AND pool_repositories.id IN (#{sub_batch.select(:id).to_sql}) + SQL + end + + def update_with_default_organization_sql(sub_batch) + <<~SQL + UPDATE pool_repositories + SET organization_id = 1 + WHERE pool_repositories.organization_id IS NULL + AND pool_repositories.id IN (#{sub_batch.select(:id).to_sql}) + SQL + end + end + end +end diff --git a/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb new file mode 100644 index 00000000000000..b1d3e8bf4fafae --- /dev/null +++ b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb @@ -0,0 +1,245 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::BackfillPoolRepositoriesOrganizationId, + feature_category: :source_code_management do + let(:connection) { ApplicationRecord.connection } + + # Create default organization with ID 1 (this is typically the default organization in GitLab) + let!(:default_organization) do + table(:organizations).create!(id: 1, name: 'default', path: 'default') + end + + let!(:organization) { table(:organizations).create!(name: 'organization', path: 'organization') } + let!(:organization2) { table(:organizations).create!(name: 'organization2', path: 'organization2') } + + # Create a shard for pool repositories + let!(:shard) { table(:shards).create!(name: 'default') } + + let!(:group1) do + table(:namespaces).create!(name: 'group1', path: 'group1', type: 'Group', organization_id: organization.id) + end + + let!(:group2) do + table(:namespaces).create!(name: 'group2', path: 'group2', type: 'Group', organization_id: organization2.id) + end + + # Create project namespaces (these are what project_namespace_id references) + let!(:project_namespace1) do + table(:namespaces).create!( + name: 'project1', + path: 'project1', + type: 'Project', + parent_id: group1.id, + organization_id: organization.id + ) + end + + let!(:project_namespace2) do + table(:namespaces).create!( + name: 'project2', + path: 'project2', + type: 'Project', + parent_id: group2.id, + organization_id: organization2.id + ) + end + + let!(:project1) do + table(:projects).create!( + name: 'project1', + path: 'project1', + organization_id: organization.id, + project_namespace_id: project_namespace1.id, + namespace_id: group1.id + ) + end + + let!(:project2) do + table(:projects).create!( + name: 'project2', + path: 'project2', + organization_id: organization2.id, + project_namespace_id: project_namespace2.id, + namespace_id: group2.id + ) + end + + let(:pool_repositories) { table(:pool_repositories) } + let(:migration_args) do + { + start_id: pool_repositories.minimum(:id), + end_id: pool_repositories.maximum(:id), + batch_table: :pool_repositories, + batch_column: :id, + sub_batch_size: 1, + pause_ms: 0, + connection: ApplicationRecord.connection + } + end + + before do + # Temporarily disable the NOT NULL constraint for testing + connection.execute('ALTER TABLE pool_repositories DROP CONSTRAINT IF EXISTS check_96233d37c0') + end + + after do + # Re-enable the constraint after tests + connection.execute( + 'ALTER TABLE pool_repositories ADD CONSTRAINT check_96233d37c0 CHECK (organization_id IS NOT NULL) NOT VALID' + ) + end + + describe '#perform' do + context 'when pool_repository has source_project_id' do + it 'backfills organization_id from source project' do + pool_repo = pool_repositories.create!( + source_project_id: project1.id, + organization_id: nil, + disk_path: 'pool/path1', + state: 'ready', + shard_id: shard.id + ) + + described_class.new(**migration_args).perform + + pool_repo.reload + expect(pool_repo.organization_id).to eq(organization.id) + end + end + + context 'when pool_repository has no source_project_id but has member projects' do + it 'backfills organization_id from member projects' do + # Temporarily disable the trigger for this test + connection.execute('DROP TRIGGER IF EXISTS trigger_pool_repositories_sharding_key ON pool_repositories') + + pool_repo = pool_repositories.create!( + source_project_id: nil, + organization_id: nil, + disk_path: 'pool/path2', + state: 'ready', + shard_id: shard.id + ) + + # Verify it's actually NULL + expect(pool_repo.organization_id).to be_nil + + # Set project2 as a member of the pool + connection.execute( + "UPDATE projects SET pool_repository_id = #{pool_repo.id} WHERE id = #{project2.id}" + ) + + # Re-enable the trigger + connection.execute(<<~SQL) + CREATE TRIGGER trigger_pool_repositories_sharding_key + BEFORE INSERT OR UPDATE ON pool_repositories + FOR EACH ROW + EXECUTE FUNCTION pool_repositories_sharding_key() + SQL + + described_class.new(**migration_args).perform + + pool_repo.reload + + expect(pool_repo.reload.organization_id).to eq(organization2.id) + end + end + + context 'when pool_repository has no source_project_id and no member projects' do + it 'backfills organization_id with default value 1' do + pool_repo = pool_repositories.create!( + source_project_id: nil, + organization_id: nil, + disk_path: 'pool/path3', + state: 'ready', + shard_id: shard.id + ) + + described_class.new(**migration_args).perform + + pool_repo.reload + expect(pool_repo.organization_id).to eq(1) + end + end + + context 'when pool_repository already has organization_id' do + it 'does not change existing organization_id' do + pool_repo = pool_repositories.create!( + source_project_id: project1.id, + organization_id: organization2.id, + disk_path: 'pool/path4', + state: 'ready', + shard_id: shard.id + ) + + described_class.new(**migration_args).perform + + pool_repo.reload + expect(pool_repo.organization_id).to eq(organization2.id) + end + end + + context 'with mixed scenarios' do + it 'handles all cases correctly in priority order' do + # Case 1b: Has source_project_id (trigger handles this correctly) + pool_repo1 = pool_repositories.create!( + source_project_id: project1.id, + organization_id: nil, + disk_path: 'pool/path5', + state: 'ready', + shard_id: shard.id + ) + + # Temporarily disable the trigger for this test + connection.execute('DROP TRIGGER IF EXISTS trigger_pool_repositories_sharding_key ON pool_repositories') + + pool_repositories.create!( + source_project_id: nil, + organization_id: nil, + disk_path: 'pool/path2', + state: 'ready', + shard_id: shard.id + ) + + # Case 2: No source_project_id but has member projects (bypass trigger) + pool_repo2_id = connection.execute(<<~SQL).first['id'] + INSERT INTO pool_repositories (source_project_id, organization_id, disk_path, state, shard_id) + VALUES (NULL, NULL, 'pool/path6', 'ready', #{shard.id}) + RETURNING id + SQL + pool_repo2 = pool_repositories.find(pool_repo2_id) + + connection.execute( + "UPDATE projects SET pool_repository_id = #{pool_repo2.id} WHERE id = #{project2.id}" + ) + + # Case 3: No source_project_id and no member projects (bypass trigger) + pool_repo3_id = connection.execute(<<~SQL).first['id'] + INSERT INTO pool_repositories (source_project_id, organization_id, disk_path, state, shard_id) + VALUES (NULL, NULL, 'pool/path7', 'ready', #{shard.id}) + RETURNING id + SQL + pool_repo3 = pool_repositories.find(pool_repo3_id) + + # Re-enable the trigger + connection.execute(<<~SQL) + CREATE TRIGGER trigger_pool_repositories_sharding_key + BEFORE INSERT OR UPDATE ON pool_repositories + FOR EACH ROW + EXECUTE FUNCTION pool_repositories_sharding_key() + SQL + + described_class.new(**migration_args).perform + + pool_repo1.reload + pool_repo2.reload + pool_repo3.reload + + expect(pool_repo1.organization_id).to eq(organization.id) + expect(pool_repo2.organization_id).to eq(organization2.id) + expect(pool_repo3.organization_id).to eq(1) + end + end + end +end diff --git a/spec/migrations/20251008204550_queue_backfill_pool_repositories_organization_id_spec.rb b/spec/migrations/20251008204550_queue_backfill_pool_repositories_organization_id_spec.rb new file mode 100644 index 00000000000000..7e922356b1ddc3 --- /dev/null +++ b/spec/migrations/20251008204550_queue_backfill_pool_repositories_organization_id_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe QueueBackfillPoolRepositoriesOrganizationId, migration: :gitlab_main_org, 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( + gitlab_schema: :gitlab_main_org, + table_name: :pool_repositories, + column_name: :id, + batch_size: described_class::BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE + ) + } + end + end +end diff --git a/spec/models/pool_repository_spec.rb b/spec/models/pool_repository_spec.rb index cd36b8f9d2b178..46f24ad114f364 100644 --- a/spec/models/pool_repository_spec.rb +++ b/spec/models/pool_repository_spec.rb @@ -10,9 +10,11 @@ it { is_expected.to have_many(:member_projects) } end - describe 'before_validation callbacks' do + describe 'setting organization id' do let_it_be(:project) { create(:project) } let_it_be(:other_organization) { create(:organization) } + let_it_be(:default_organization) { create(:organization, id: 1) } + let_it_be(:shard) { create(:shard) } context 'when organization is not set' do it 'assigns organization from the source project' do @@ -45,6 +47,67 @@ expect(pool_repo.organization).to eq(other_organization) end end + + context 'when model hooks are bypassed' do + context 'when source project is available' do + it 'sets organization_id from the source project via database trigger' do + # Use insert_all to bypass ActiveRecord callbacks and model hooks + result = described_class.insert_all([{ + source_project_id: project.id, + organization_id: nil, + disk_path: 'pool/trigger_test', + state: 'ready', + shard_id: shard.id + }], returning: [:id, :organization_id]) + + pool_repo = described_class.find(result.rows.first[0]) + expect(pool_repo.organization_id).to eq(project.organization_id) + end + end + + context 'when source project is not available' do + it 'sets default organization_id via database trigger' do + # Use insert_all to bypass ActiveRecord callbacks and model hooks + result = described_class.insert_all([{ + source_project_id: nil, + organization_id: nil, + disk_path: 'pool/trigger_default_test', + state: 'ready', + shard_id: shard.id + }], returning: [:id, :organization_id]) + + pool_repo = described_class.find(result.rows.first[0]) + expect(pool_repo.organization_id).to eq(1) + end + end + + context 'when organization_id is already set' do + it 'preserves existing organization_id' do + # Use insert_all to bypass ActiveRecord callbacks and model hooks + result = described_class.insert_all([{ + source_project_id: project.id, + organization_id: other_organization.id, + disk_path: 'pool/trigger_preserve_test', + state: 'ready', + shard_id: shard.id + }], returning: [:id, :organization_id]) + + pool_repo = described_class.find(result.rows.first[0]) + expect(pool_repo.organization_id).to eq(other_organization.id) + end + end + + it 'works during updates when organization_id is cleared' do + pool_repo = create(:pool_repository, source_project: project) + original_org_id = pool_repo.organization_id + + # Use update_all to bypass ActiveRecord callbacks + described_class.where(id: pool_repo.id).update_all(organization_id: nil) + + pool_repo.reload + expect(pool_repo.organization_id).to eq(original_org_id) + end + end end describe 'validations' do -- GitLab From 5399cfa23c06da04c08494991550c291a7fc2b0d Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Thu, 20 Nov 2025 10:22:39 -0800 Subject: [PATCH 02/23] Update/refresh migration timestamps and milestones --- .../backfill_pool_repositories_organization_id.yml | 4 ++-- ...20181040_add_sharding_key_trigger_to_pool_repositories.rb} | 2 +- ...81042_queue_backfill_pool_repositories_organization_id.rb} | 2 +- ...ncurrent_index_to_pool_repositories_on_organization_id.rb} | 2 +- ...key_constraint_to_pool_repositories_on_organization_id.rb} | 2 +- ..._not_null_constraint_to_pool_repositories_sharding_key.rb} | 2 +- db/schema_migrations/20251006152354 | 1 - db/schema_migrations/20251008204550 | 1 - db/schema_migrations/20251008204839 | 1 - db/schema_migrations/20251008205011 | 1 - db/schema_migrations/20251008205112 | 1 - db/schema_migrations/20251120181040 | 1 + db/schema_migrations/20251120181042 | 1 + db/schema_migrations/20251120181044 | 1 + db/schema_migrations/20251120181048 | 1 + db/schema_migrations/20251120181051 | 1 + 16 files changed, 12 insertions(+), 12 deletions(-) rename db/migrate/{20251006152354_add_sharding_key_trigger_to_pool_repositories.rb => 20251120181040_add_sharding_key_trigger_to_pool_repositories.rb} (98%) rename db/post_migrate/{20251008204550_queue_backfill_pool_repositories_organization_id.rb => 20251120181042_queue_backfill_pool_repositories_organization_id.rb} (97%) rename db/post_migrate/{20251008204839_add_concurrent_index_to_pool_repositories_on_organization_id.rb => 20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb} (96%) rename db/post_migrate/{20251008205011_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb => 20251120181048_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb} (95%) rename db/post_migrate/{20251008205112_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb => 20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb} (96%) delete mode 100644 db/schema_migrations/20251006152354 delete mode 100644 db/schema_migrations/20251008204550 delete mode 100644 db/schema_migrations/20251008204839 delete mode 100644 db/schema_migrations/20251008205011 delete mode 100644 db/schema_migrations/20251008205112 create mode 100644 db/schema_migrations/20251120181040 create mode 100644 db/schema_migrations/20251120181042 create mode 100644 db/schema_migrations/20251120181044 create mode 100644 db/schema_migrations/20251120181048 create mode 100644 db/schema_migrations/20251120181051 diff --git a/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml b/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml index c691c54601a809..4c48a80c86bc45 100644 --- a/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml +++ b/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml @@ -3,6 +3,6 @@ migration_job_name: BackfillPoolRepositoriesOrganizationId description: Backfills organization_id on pool_repositories feature_category: source_code_management introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/208322 -milestone: '18.6' -queued_migration_version: 20251008204550 +milestone: '18.7' +queued_migration_version: 20251120181042 finalized_by: # version of the migration that finalized this BBM diff --git a/db/migrate/20251006152354_add_sharding_key_trigger_to_pool_repositories.rb b/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb similarity index 98% rename from db/migrate/20251006152354_add_sharding_key_trigger_to_pool_repositories.rb rename to db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb index b64a9a811c6b91..fea9ea33d4e828 100644 --- a/db/migrate/20251006152354_add_sharding_key_trigger_to_pool_repositories.rb +++ b/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb @@ -3,7 +3,7 @@ class AddShardingKeyTriggerToPoolRepositories < Gitlab::Database::Migration[2.3] include Gitlab::Database::SchemaHelpers - milestone '18.5' + milestone '18.7' TABLE_NAME = 'pool_repositories' TRIGGER_FUNCTION_NAME = 'pool_repositories_sharding_key' diff --git a/db/post_migrate/20251008204550_queue_backfill_pool_repositories_organization_id.rb b/db/post_migrate/20251120181042_queue_backfill_pool_repositories_organization_id.rb similarity index 97% rename from db/post_migrate/20251008204550_queue_backfill_pool_repositories_organization_id.rb rename to db/post_migrate/20251120181042_queue_backfill_pool_repositories_organization_id.rb index ba6533f150ade8..865672efcc7bf5 100644 --- a/db/post_migrate/20251008204550_queue_backfill_pool_repositories_organization_id.rb +++ b/db/post_migrate/20251120181042_queue_backfill_pool_repositories_organization_id.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class QueueBackfillPoolRepositoriesOrganizationId < Gitlab::Database::Migration[2.3] - milestone '18.5' + milestone '18.7' # Select the applicable gitlab schema for your batched background migration restrict_gitlab_migration gitlab_schema: :gitlab_main_org diff --git a/db/post_migrate/20251008204839_add_concurrent_index_to_pool_repositories_on_organization_id.rb b/db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb similarity index 96% rename from db/post_migrate/20251008204839_add_concurrent_index_to_pool_repositories_on_organization_id.rb rename to db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb index e3bac648c53bea..ea8f9bdd8beef0 100644 --- a/db/post_migrate/20251008204839_add_concurrent_index_to_pool_repositories_on_organization_id.rb +++ b/db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb @@ -5,7 +5,7 @@ class AddConcurrentIndexToPoolRepositoriesOnOrganizationId < Gitlab::Database::Migration[2.3] disable_ddl_transaction! - milestone '18.5' + milestone '18.7' INDEX_NAME = 'index_pool_repositories_on_organization_id' diff --git a/db/post_migrate/20251008205011_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb b/db/post_migrate/20251120181048_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb similarity index 95% rename from db/post_migrate/20251008205011_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb rename to db/post_migrate/20251120181048_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb index 907b14f429bc83..aebaf69ad4e422 100644 --- a/db/post_migrate/20251008205011_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb +++ b/db/post_migrate/20251120181048_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb @@ -2,7 +2,7 @@ class AddNotValidForeignKeyConstraintToPoolRepositoriesOnOrganizationId < Gitlab::Database::Migration[2.3] disable_ddl_transaction! - milestone '18.5' + milestone '18.7' def up add_concurrent_foreign_key( diff --git a/db/post_migrate/20251008205112_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb b/db/post_migrate/20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb similarity index 96% rename from db/post_migrate/20251008205112_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb rename to db/post_migrate/20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb index 4ba30a844afd80..0b3ceaa74803a2 100644 --- a/db/post_migrate/20251008205112_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb +++ b/db/post_migrate/20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb @@ -5,7 +5,7 @@ class AddNotValidNotNullConstraintToPoolRepositoriesShardingKey < Gitlab::Database::Migration[2.3] disable_ddl_transaction! - milestone '18.5' + milestone '18.7' def up add_not_null_constraint( diff --git a/db/schema_migrations/20251006152354 b/db/schema_migrations/20251006152354 deleted file mode 100644 index 523aba5134d453..00000000000000 --- a/db/schema_migrations/20251006152354 +++ /dev/null @@ -1 +0,0 @@ -c2b4ba3e5371c3fede2f389d510cd51bdba4d3041c1019dbc494aff229cae014 \ No newline at end of file diff --git a/db/schema_migrations/20251008204550 b/db/schema_migrations/20251008204550 deleted file mode 100644 index 802985d18497ba..00000000000000 --- a/db/schema_migrations/20251008204550 +++ /dev/null @@ -1 +0,0 @@ -d29283ae3c5e7c7e66dafdcd44b09dc04324fb5bd9e1d1d3e7256d1bfe5251a1 \ No newline at end of file diff --git a/db/schema_migrations/20251008204839 b/db/schema_migrations/20251008204839 deleted file mode 100644 index 605b92a9862f30..00000000000000 --- a/db/schema_migrations/20251008204839 +++ /dev/null @@ -1 +0,0 @@ -f91d6d5b07adc9a3d9b48247306b70d5d62e3a4e9e3b0922da169ebd5717b4f7 \ No newline at end of file diff --git a/db/schema_migrations/20251008205011 b/db/schema_migrations/20251008205011 deleted file mode 100644 index 1ee92728f549a4..00000000000000 --- a/db/schema_migrations/20251008205011 +++ /dev/null @@ -1 +0,0 @@ -d50f05f057b9f0cebb5ee4988ae12c3d26fe893f0269f933a636c8bc2ac7cc74 \ No newline at end of file diff --git a/db/schema_migrations/20251008205112 b/db/schema_migrations/20251008205112 deleted file mode 100644 index 995599de3e7b7e..00000000000000 --- a/db/schema_migrations/20251008205112 +++ /dev/null @@ -1 +0,0 @@ -d870205ddd464dcfabce49d55730e04b30ad40756d9892ac18c98df208c41d21 \ No newline at end of file diff --git a/db/schema_migrations/20251120181040 b/db/schema_migrations/20251120181040 new file mode 100644 index 00000000000000..6f9e1c5a803843 --- /dev/null +++ b/db/schema_migrations/20251120181040 @@ -0,0 +1 @@ +d3f0fc55f6b2b23cbd85b872f8e7ebf5073ceaf00a83e92f2f366477d0d7d1a5 \ No newline at end of file diff --git a/db/schema_migrations/20251120181042 b/db/schema_migrations/20251120181042 new file mode 100644 index 00000000000000..16bfe7c48f50c1 --- /dev/null +++ b/db/schema_migrations/20251120181042 @@ -0,0 +1 @@ +954abcba89d003196f82d3f58111a478a446a4e86f699ca33a80d65123bef68f \ No newline at end of file diff --git a/db/schema_migrations/20251120181044 b/db/schema_migrations/20251120181044 new file mode 100644 index 00000000000000..c19fd07d233cd3 --- /dev/null +++ b/db/schema_migrations/20251120181044 @@ -0,0 +1 @@ +123c79cfd3e186b8b0c4de006e8fb97dd777e5febb4137ac7222002e96e68560 \ No newline at end of file diff --git a/db/schema_migrations/20251120181048 b/db/schema_migrations/20251120181048 new file mode 100644 index 00000000000000..0f5fa919bd7ff4 --- /dev/null +++ b/db/schema_migrations/20251120181048 @@ -0,0 +1 @@ +1a1346e82f97abc066415b419847ea19ffc44f7bf6b073ff0dc2f918cbe4001e \ No newline at end of file diff --git a/db/schema_migrations/20251120181051 b/db/schema_migrations/20251120181051 new file mode 100644 index 00000000000000..8bbce22354098b --- /dev/null +++ b/db/schema_migrations/20251120181051 @@ -0,0 +1 @@ +d4ef5203b03679627c155249a5bbfc4f94c616aee304218c4d3fcec51b845ec5 \ No newline at end of file -- GitLab From a633574347ebfd4a7cb4ed180d5aa9085e2779ca Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Tue, 25 Nov 2025 10:16:44 -0800 Subject: [PATCH 03/23] Remove pool_repositories ignored FK declaration in spec --- spec/db/schema_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index 6a231a38f81095..b9059ed2ae7fab 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -159,7 +159,6 @@ p_ci_pipeline_variables: %w[project_id], p_ci_pipelines_config: %w[partition_id project_id], p_ci_stages: %w[project_id], - pool_repositories: %w[organization_id], p_duo_workflows_checkpoints: %w[project_id namespace_id], project_build_artifacts_size_refreshes: %w[last_job_artifact_id], project_data_transfers: %w[project_id namespace_id], -- GitLab From 2c02dee56e014fb5baad2911922b61bc9c408ce9 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Tue, 25 Nov 2025 10:50:38 -0800 Subject: [PATCH 04/23] Move BBM scheduling migration to run last --- .../backfill_pool_repositories_organization_id.yml | 2 +- ...0181151_queue_backfill_pool_repositories_organization_id.rb} | 0 db/schema_migrations/20251120181042 | 1 - db/schema_migrations/20251120181151 | 1 + 4 files changed, 2 insertions(+), 2 deletions(-) rename db/post_migrate/{20251120181042_queue_backfill_pool_repositories_organization_id.rb => 20251120181151_queue_backfill_pool_repositories_organization_id.rb} (100%) delete mode 100644 db/schema_migrations/20251120181042 create mode 100644 db/schema_migrations/20251120181151 diff --git a/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml b/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml index 4c48a80c86bc45..00c955baa23c86 100644 --- a/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml +++ b/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml @@ -4,5 +4,5 @@ description: Backfills organization_id on pool_repositories feature_category: source_code_management introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/208322 milestone: '18.7' -queued_migration_version: 20251120181042 +queued_migration_version: 20251120181151 finalized_by: # version of the migration that finalized this BBM diff --git a/db/post_migrate/20251120181042_queue_backfill_pool_repositories_organization_id.rb b/db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb similarity index 100% rename from db/post_migrate/20251120181042_queue_backfill_pool_repositories_organization_id.rb rename to db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb diff --git a/db/schema_migrations/20251120181042 b/db/schema_migrations/20251120181042 deleted file mode 100644 index 16bfe7c48f50c1..00000000000000 --- a/db/schema_migrations/20251120181042 +++ /dev/null @@ -1 +0,0 @@ -954abcba89d003196f82d3f58111a478a446a4e86f699ca33a80d65123bef68f \ No newline at end of file diff --git a/db/schema_migrations/20251120181151 b/db/schema_migrations/20251120181151 new file mode 100644 index 00000000000000..0f84b3f86eeb35 --- /dev/null +++ b/db/schema_migrations/20251120181151 @@ -0,0 +1 @@ +bb297d681db8f7c5310e17d7634aeba28b6a36b64de51ce30237d50caa53857b \ No newline at end of file -- GitLab From e53f5c73978db57759cdf8c9b13bb328170a2c60 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Thu, 27 Nov 2025 09:08:01 -0800 Subject: [PATCH 05/23] Remove extraneous #reload --- .../backfill_pool_repositories_organization_id_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb index b1d3e8bf4fafae..e70b006d57f2be 100644 --- a/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb +++ b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb @@ -142,7 +142,7 @@ pool_repo.reload - expect(pool_repo.reload.organization_id).to eq(organization2.id) + expect(pool_repo.organization_id).to eq(organization2.id) end end -- GitLab From 0a016f42ca370b062ab781bfa19acb151b294a27 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Thu, 27 Nov 2025 09:08:27 -0800 Subject: [PATCH 06/23] Add load-bearing whitespace for readability --- .../backfill_pool_repositories_organization_id_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb index e70b006d57f2be..d656c6c4858121 100644 --- a/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb +++ b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb @@ -159,6 +159,7 @@ described_class.new(**migration_args).perform pool_repo.reload + expect(pool_repo.organization_id).to eq(1) end end @@ -176,6 +177,7 @@ described_class.new(**migration_args).perform pool_repo.reload + expect(pool_repo.organization_id).to eq(organization2.id) end end -- GitLab From e3b2efff24bae2bb30c1eadcfcf1d30877148f6d Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Wed, 10 Dec 2025 12:06:44 -0800 Subject: [PATCH 07/23] Remove extraneous commenting --- .../backfill_pool_repositories_organization_id.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/gitlab/background_migration/backfill_pool_repositories_organization_id.rb b/lib/gitlab/background_migration/backfill_pool_repositories_organization_id.rb index 3201f7d329441e..269bf5c845f2ea 100644 --- a/lib/gitlab/background_migration/backfill_pool_repositories_organization_id.rb +++ b/lib/gitlab/background_migration/backfill_pool_repositories_organization_id.rb @@ -1,10 +1,5 @@ # frozen_string_literal: true -# See https://docs.gitlab.com/ee/development/database/batched_background_migrations.html -# for more information on how to use batched background migrations - -# Update below commented lines with appropriate values. - module Gitlab module BackgroundMigration class BackfillPoolRepositoriesOrganizationId < BatchedMigrationJob -- GitLab From a1d074a24570b3e9e81f218a54005b797ce7e7b1 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Wed, 10 Dec 2025 12:13:06 -0800 Subject: [PATCH 08/23] Remove extraneous commenting --- ...120181151_queue_backfill_pool_repositories_organization_id.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb b/db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb index 865672efcc7bf5..b7186fe53af01c 100644 --- a/db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb +++ b/db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb @@ -3,7 +3,6 @@ class QueueBackfillPoolRepositoriesOrganizationId < Gitlab::Database::Migration[2.3] milestone '18.7' - # Select the applicable gitlab schema for your batched background migration restrict_gitlab_migration gitlab_schema: :gitlab_main_org MIGRATION = "BackfillPoolRepositoriesOrganizationId" -- GitLab From bf391ba0a4bf0023b5dc4f911e532be4fe8f5dd9 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Wed, 10 Dec 2025 12:30:20 -0800 Subject: [PATCH 09/23] Remove setting org_id in trigger --- ...251120181040_add_sharding_key_trigger_to_pool_repositories.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb b/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb index fea9ea33d4e828..01ba6760de73ad 100644 --- a/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb +++ b/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb @@ -28,7 +28,6 @@ def up END IF; END IF; - NEW.organization_id := 1; RETURN NEW; END; $$ LANGUAGE plpgsql; -- GitLab From d34079bf3aa0b487458bab0b039afdb03b6c4fbb Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Wed, 10 Dec 2025 12:36:06 -0800 Subject: [PATCH 10/23] Remove even more extraneous comments --- ...concurrent_index_to_pool_repositories_on_organization_id.rb | 3 --- ...id_not_null_constraint_to_pool_repositories_sharding_key.rb | 3 --- 2 files changed, 6 deletions(-) diff --git a/db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb b/db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb index ea8f9bdd8beef0..2afe346c037dc9 100644 --- a/db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb +++ b/db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -# See https://docs.gitlab.com/ee/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - class AddConcurrentIndexToPoolRepositoriesOnOrganizationId < Gitlab::Database::Migration[2.3] disable_ddl_transaction! milestone '18.7' diff --git a/db/post_migrate/20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb b/db/post_migrate/20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb index 0b3ceaa74803a2..0edf8b69dbf043 100644 --- a/db/post_migrate/20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb +++ b/db/post_migrate/20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -# See https://docs.gitlab.com/ee/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - class AddNotValidNotNullConstraintToPoolRepositoriesShardingKey < Gitlab::Database::Migration[2.3] disable_ddl_transaction! milestone '18.7' -- GitLab From 31d7aba4c4c377d6a84d0c2dd4ec3a4f2f708b92 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Thu, 11 Dec 2025 11:36:16 -0800 Subject: [PATCH 11/23] Add (and clarify) table connection declarations --- ..._pool_repositories_organization_id_spec.rb | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb index d656c6c4858121..6d9b0ea59a14f3 100644 --- a/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb +++ b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb @@ -6,28 +6,36 @@ feature_category: :source_code_management do let(:connection) { ApplicationRecord.connection } - # Create default organization with ID 1 (this is typically the default organization in GitLab) + let(:namespaces_table) { table(:namespaces) } + let(:organizations_table) { table(:organizations) } + let(:projects_table) { table(:projects) } + let(:pool_repositories_table) { table(:pool_repositories) } + + # Create default organization with ID 1 (this is typically the default + # organization in GitLab) let!(:default_organization) do - table(:organizations).create!(id: 1, name: 'default', path: 'default') + organizations_table.create!(id: 1, name: 'default', path: 'default') end - let!(:organization) { table(:organizations).create!(name: 'organization', path: 'organization') } - let!(:organization2) { table(:organizations).create!(name: 'organization2', path: 'organization2') } + let!(:organization) { organizations_table.create!(name: 'organization', path: 'organization') } + let!(:organization2) { organizations_table.create!(name: 'organization2', path: 'organization2') } # Create a shard for pool repositories + # let!(:shard) { table(:shards).create!(name: 'default') } let!(:group1) do - table(:namespaces).create!(name: 'group1', path: 'group1', type: 'Group', organization_id: organization.id) + namespaces_table.create!(name: 'group1', path: 'group1', type: 'Group', organization_id: organization.id) end let!(:group2) do - table(:namespaces).create!(name: 'group2', path: 'group2', type: 'Group', organization_id: organization2.id) + namespaces_table.create!(name: 'group2', path: 'group2', type: 'Group', organization_id: organization2.id) end # Create project namespaces (these are what project_namespace_id references) + # let!(:project_namespace1) do - table(:namespaces).create!( + namespaces_table.create!( name: 'project1', path: 'project1', type: 'Project', @@ -37,7 +45,7 @@ end let!(:project_namespace2) do - table(:namespaces).create!( + namespaces_table.create!( name: 'project2', path: 'project2', type: 'Project', @@ -47,7 +55,7 @@ end let!(:project1) do - table(:projects).create!( + projects_table.create!( name: 'project1', path: 'project1', organization_id: organization.id, @@ -57,7 +65,7 @@ end let!(:project2) do - table(:projects).create!( + projects_table.create!( name: 'project2', path: 'project2', organization_id: organization2.id, @@ -66,11 +74,10 @@ ) end - let(:pool_repositories) { table(:pool_repositories) } let(:migration_args) do { - start_id: pool_repositories.minimum(:id), - end_id: pool_repositories.maximum(:id), + start_id: pool_repositories_table.minimum(:id), + end_id: pool_repositories_table.maximum(:id), batch_table: :pool_repositories, batch_column: :id, sub_batch_size: 1, @@ -94,7 +101,7 @@ describe '#perform' do context 'when pool_repository has source_project_id' do it 'backfills organization_id from source project' do - pool_repo = pool_repositories.create!( + pool_repo = pool_repositories_table.create!( source_project_id: project1.id, organization_id: nil, disk_path: 'pool/path1', @@ -114,7 +121,7 @@ # Temporarily disable the trigger for this test connection.execute('DROP TRIGGER IF EXISTS trigger_pool_repositories_sharding_key ON pool_repositories') - pool_repo = pool_repositories.create!( + pool_repo = pool_repositories_table.create!( source_project_id: nil, organization_id: nil, disk_path: 'pool/path2', @@ -148,7 +155,7 @@ context 'when pool_repository has no source_project_id and no member projects' do it 'backfills organization_id with default value 1' do - pool_repo = pool_repositories.create!( + pool_repo = pool_repositories_table.create!( source_project_id: nil, organization_id: nil, disk_path: 'pool/path3', @@ -166,7 +173,7 @@ context 'when pool_repository already has organization_id' do it 'does not change existing organization_id' do - pool_repo = pool_repositories.create!( + pool_repo = pool_repositories_table.create!( source_project_id: project1.id, organization_id: organization2.id, disk_path: 'pool/path4', @@ -185,7 +192,7 @@ context 'with mixed scenarios' do it 'handles all cases correctly in priority order' do # Case 1b: Has source_project_id (trigger handles this correctly) - pool_repo1 = pool_repositories.create!( + pool_repo1 = pool_repositories_table.create!( source_project_id: project1.id, organization_id: nil, disk_path: 'pool/path5', @@ -196,7 +203,7 @@ # Temporarily disable the trigger for this test connection.execute('DROP TRIGGER IF EXISTS trigger_pool_repositories_sharding_key ON pool_repositories') - pool_repositories.create!( + pool_repositories_table.create!( source_project_id: nil, organization_id: nil, disk_path: 'pool/path2', @@ -210,7 +217,7 @@ VALUES (NULL, NULL, 'pool/path6', 'ready', #{shard.id}) RETURNING id SQL - pool_repo2 = pool_repositories.find(pool_repo2_id) + pool_repo2 = pool_repositories_table.find(pool_repo2_id) connection.execute( "UPDATE projects SET pool_repository_id = #{pool_repo2.id} WHERE id = #{project2.id}" @@ -222,7 +229,7 @@ VALUES (NULL, NULL, 'pool/path7', 'ready', #{shard.id}) RETURNING id SQL - pool_repo3 = pool_repositories.find(pool_repo3_id) + pool_repo3 = pool_repositories_table.find(pool_repo3_id) # Re-enable the trigger connection.execute(<<~SQL) -- GitLab From 3729f12a5eb68cada7d23e2dec40f7ba7f887d0d Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Thu, 11 Dec 2025 11:56:14 -0800 Subject: [PATCH 12/23] Use find_or_create_by just in case --- .../backfill_pool_repositories_organization_id_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb index 6d9b0ea59a14f3..7b9ee3e51463d1 100644 --- a/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb +++ b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb @@ -13,8 +13,12 @@ # Create default organization with ID 1 (this is typically the default # organization in GitLab) + # let!(:default_organization) do - organizations_table.create!(id: 1, name: 'default', path: 'default') + organizations_table.find_or_create_by!(path: 'default') do |org| + org.id = 1 + org.name = 'default' + end end let!(:organization) { organizations_table.create!(name: 'organization', path: 'organization') } -- GitLab From 16c91d89bcc61257daddafe82f94c9ea14b5fea0 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 12 Dec 2025 08:36:33 -0800 Subject: [PATCH 13/23] Remove extraneous SQL --- ...120181040_add_sharding_key_trigger_to_pool_repositories.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb b/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb index 01ba6760de73ad..e0c08c7c7a5f22 100644 --- a/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb +++ b/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb @@ -22,10 +22,6 @@ def up INTO NEW.organization_id FROM projects p WHERE p.id = NEW.source_project_id; - - IF NEW.organization_id IS NOT NULL THEN - RETURN NEW; - END IF; END IF; RETURN NEW; -- GitLab From 210cb9f526b5dce0d8a965dcc0fb062e662fe4c4 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 12 Dec 2025 09:02:39 -0800 Subject: [PATCH 14/23] Define default organization --- spec/lib/backup/restore/pool_repositories_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/lib/backup/restore/pool_repositories_spec.rb b/spec/lib/backup/restore/pool_repositories_spec.rb index 53419c6a49d7b0..fff8e663012bae 100644 --- a/spec/lib/backup/restore/pool_repositories_spec.rb +++ b/spec/lib/backup/restore/pool_repositories_spec.rb @@ -9,6 +9,8 @@ describe '.reinitialize_pools!' do context 'with a pool without a source project' do + let_it_be(:default_organization) { create(:organization, id: 1) } + let(:pool_repository) { create(:pool_repository, :without_project) } it 'yields a skipped result' do -- GitLab From 70e1a84c7c5119ba8db49f9b519288dc7d063503 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 12 Dec 2025 10:05:30 -0800 Subject: [PATCH 15/23] Updated schema --- db/structure.sql | 5 ----- 1 file changed, 5 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index b58fe0ac260a53..c465e0834a183d 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -830,13 +830,8 @@ BEGIN INTO NEW.organization_id FROM projects p WHERE p.id = NEW.source_project_id; - - IF NEW.organization_id IS NOT NULL THEN - RETURN NEW; - END IF; END IF; - NEW.organization_id := 1; RETURN NEW; END; $$; -- GitLab From 68b616e1983d7233495453773d430a391e0910af Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 12 Dec 2025 11:11:21 -0800 Subject: [PATCH 16/23] More games with default orgs --- spec/lib/backup/restore/pool_repositories_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/backup/restore/pool_repositories_spec.rb b/spec/lib/backup/restore/pool_repositories_spec.rb index fff8e663012bae..77b5e5628dc581 100644 --- a/spec/lib/backup/restore/pool_repositories_spec.rb +++ b/spec/lib/backup/restore/pool_repositories_spec.rb @@ -11,7 +11,7 @@ context 'with a pool without a source project' do let_it_be(:default_organization) { create(:organization, id: 1) } - let(:pool_repository) { create(:pool_repository, :without_project) } + let(:pool_repository) { create(:pool_repository, :without_project, organization: default_organization) } it 'yields a skipped result' do results = [] -- GitLab From 050b0ea43adf4393451dbfda7d9237a9d1d263fb Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 12 Dec 2025 11:52:22 -0800 Subject: [PATCH 17/23] Drop org_id NOT NULL --- ...traint_to_pool_repositories_sharding_key.rb | 18 ------------------ db/schema_migrations/20251120181051 | 1 - db/structure.sql | 3 --- 3 files changed, 22 deletions(-) delete mode 100644 db/post_migrate/20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb delete mode 100644 db/schema_migrations/20251120181051 diff --git a/db/post_migrate/20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb b/db/post_migrate/20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb deleted file mode 100644 index 0edf8b69dbf043..00000000000000 --- a/db/post_migrate/20251120181051_add_not_valid_not_null_constraint_to_pool_repositories_sharding_key.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -class AddNotValidNotNullConstraintToPoolRepositoriesShardingKey < Gitlab::Database::Migration[2.3] - disable_ddl_transaction! - milestone '18.7' - - def up - add_not_null_constraint( - :pool_repositories, - :organization_id, - validate: false - ) - end - - def down - remove_not_null_constraint(:pool_repositories, :organization_id) - end -end diff --git a/db/schema_migrations/20251120181051 b/db/schema_migrations/20251120181051 deleted file mode 100644 index 8bbce22354098b..00000000000000 --- a/db/schema_migrations/20251120181051 +++ /dev/null @@ -1 +0,0 @@ -d4ef5203b03679627c155249a5bbfc4f94c616aee304218c4d3fcec51b845ec5 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index c465e0834a183d..cd4e3a31b08b5a 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -35126,9 +35126,6 @@ ALTER TABLE merge_request_context_commit_diff_files ALTER TABLE system_note_metadata ADD CONSTRAINT check_9135b6f0b6 CHECK ((namespace_id IS NOT NULL)) NOT VALID; -ALTER TABLE pool_repositories - ADD CONSTRAINT check_96233d37c0 CHECK ((organization_id IS NOT NULL)) NOT VALID; - ALTER TABLE related_epic_links ADD CONSTRAINT check_a6d9d7c276 CHECK ((issue_link_id IS NOT NULL)) NOT VALID; -- GitLab From 2d316a7bddfb58b03e945c72da96e45963c21a17 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 12 Dec 2025 12:56:30 -0800 Subject: [PATCH 18/23] Restore constraint accidentally removed in rebase --- db/structure.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/structure.sql b/db/structure.sql index cd4e3a31b08b5a..d0b9734c892615 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -35126,6 +35126,9 @@ ALTER TABLE merge_request_context_commit_diff_files ALTER TABLE system_note_metadata ADD CONSTRAINT check_9135b6f0b6 CHECK ((namespace_id IS NOT NULL)) NOT VALID; +ALTER TABLE slack_api_scopes + ADD CONSTRAINT check_930d89be0d CHECK ((organization_id IS NOT NULL)) NOT VALID; + ALTER TABLE related_epic_links ADD CONSTRAINT check_a6d9d7c276 CHECK ((issue_link_id IS NOT NULL)) NOT VALID; -- GitLab From 55c47f09c6b29b22583045ae74f64c821e4a0e74 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 12 Dec 2025 13:19:16 -0800 Subject: [PATCH 19/23] Remove extraneous constraint twiddling in test --- ...ackfill_pool_repositories_organization_id_spec.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb index 7b9ee3e51463d1..0ac789332e6ef0 100644 --- a/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb +++ b/spec/lib/gitlab/background_migration/backfill_pool_repositories_organization_id_spec.rb @@ -90,18 +90,6 @@ } end - before do - # Temporarily disable the NOT NULL constraint for testing - connection.execute('ALTER TABLE pool_repositories DROP CONSTRAINT IF EXISTS check_96233d37c0') - end - - after do - # Re-enable the constraint after tests - connection.execute( - 'ALTER TABLE pool_repositories ADD CONSTRAINT check_96233d37c0 CHECK (organization_id IS NOT NULL) NOT VALID' - ) - end - describe '#perform' do context 'when pool_repository has source_project_id' do it 'backfills organization_id from source project' do -- GitLab From e9211a691a861eb2428a6ca7c5a71a86f04c806f Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 12 Dec 2025 13:26:04 -0800 Subject: [PATCH 20/23] Correct test that relied on removed trigger --- spec/models/pool_repository_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/models/pool_repository_spec.rb b/spec/models/pool_repository_spec.rb index 46f24ad114f364..624096d296adbd 100644 --- a/spec/models/pool_repository_spec.rb +++ b/spec/models/pool_repository_spec.rb @@ -66,8 +66,9 @@ end context 'when source project is not available' do - it 'sets default organization_id via database trigger' do + it 'does not set the default organization_id' do # Use insert_all to bypass ActiveRecord callbacks and model hooks + # result = described_class.insert_all([{ source_project_id: nil, organization_id: nil, @@ -77,7 +78,7 @@ }], returning: [:id, :organization_id]) pool_repo = described_class.find(result.rows.first[0]) - expect(pool_repo.organization_id).to eq(1) + expect(pool_repo.organization_id).to be_nil end end -- GitLab From 51d7c50df89c35a5d884d9c476fec54950fb8026 Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Fri, 12 Dec 2025 13:46:58 -0800 Subject: [PATCH 21/23] Misaligned something --- db/structure.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/structure.sql b/db/structure.sql index d0b9734c892615..fb4e2bd7ce11d9 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -35127,7 +35127,7 @@ ALTER TABLE system_note_metadata ADD CONSTRAINT check_9135b6f0b6 CHECK ((namespace_id IS NOT NULL)) NOT VALID; ALTER TABLE slack_api_scopes - ADD CONSTRAINT check_930d89be0d CHECK ((organization_id IS NOT NULL)) NOT VALID; + ADD CONSTRAINT check_930d89be0d CHECK ((organization_id IS NOT NULL)) NOT VALID; ALTER TABLE related_epic_links ADD CONSTRAINT check_a6d9d7c276 CHECK ((issue_link_id IS NOT NULL)) NOT VALID; -- GitLab From 93651513c8bafbd516ff78a0eb69b9e4a5fb4a9e Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Wed, 17 Dec 2025 04:54:12 -0800 Subject: [PATCH 22/23] Update milestones --- .../backfill_pool_repositories_organization_id.yml | 2 +- ...51120181040_add_sharding_key_trigger_to_pool_repositories.rb | 2 +- ..._concurrent_index_to_pool_repositories_on_organization_id.rb | 2 +- ...20181151_queue_backfill_pool_repositories_organization_id.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml b/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml index 00c955baa23c86..668f1935d8c8a7 100644 --- a/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml +++ b/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml @@ -3,6 +3,6 @@ migration_job_name: BackfillPoolRepositoriesOrganizationId description: Backfills organization_id on pool_repositories feature_category: source_code_management introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/208322 -milestone: '18.7' +milestone: '18.8' queued_migration_version: 20251120181151 finalized_by: # version of the migration that finalized this BBM diff --git a/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb b/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb index e0c08c7c7a5f22..acf0dcd4c3dc11 100644 --- a/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb +++ b/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb @@ -3,7 +3,7 @@ class AddShardingKeyTriggerToPoolRepositories < Gitlab::Database::Migration[2.3] include Gitlab::Database::SchemaHelpers - milestone '18.7' + milestone '18.8' TABLE_NAME = 'pool_repositories' TRIGGER_FUNCTION_NAME = 'pool_repositories_sharding_key' diff --git a/db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb b/db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb index 2afe346c037dc9..917be380130f7c 100644 --- a/db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb +++ b/db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb @@ -2,7 +2,7 @@ class AddConcurrentIndexToPoolRepositoriesOnOrganizationId < Gitlab::Database::Migration[2.3] disable_ddl_transaction! - milestone '18.7' + milestone '18.8' INDEX_NAME = 'index_pool_repositories_on_organization_id' diff --git a/db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb b/db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb index b7186fe53af01c..0507509657c38c 100644 --- a/db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb +++ b/db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class QueueBackfillPoolRepositoriesOrganizationId < Gitlab::Database::Migration[2.3] - milestone '18.7' + milestone '18.8' restrict_gitlab_migration gitlab_schema: :gitlab_main_org -- GitLab From 1a477d213684f8fe7e6d0883cf9b2a5f0642e28d Mon Sep 17 00:00:00 2001 From: Kerri Miller Date: Wed, 17 Dec 2025 07:12:13 -0600 Subject: [PATCH 23/23] Update timestamps --- .../backfill_pool_repositories_organization_id.yml | 2 +- ...1217130425_add_sharding_key_trigger_to_pool_repositories.rb} | 0 ...concurrent_index_to_pool_repositories_on_organization_id.rb} | 0 ...n_key_constraint_to_pool_repositories_on_organization_id.rb} | 0 ...7130435_queue_backfill_pool_repositories_organization_id.rb} | 0 db/schema_migrations/20251120181040 | 1 - db/schema_migrations/20251120181044 | 1 - db/schema_migrations/20251120181048 | 1 - db/schema_migrations/20251120181151 | 1 - db/schema_migrations/20251217130425 | 1 + db/schema_migrations/20251217130430 | 1 + db/schema_migrations/20251217130432 | 1 + db/schema_migrations/20251217130435 | 1 + 13 files changed, 5 insertions(+), 5 deletions(-) rename db/migrate/{20251120181040_add_sharding_key_trigger_to_pool_repositories.rb => 20251217130425_add_sharding_key_trigger_to_pool_repositories.rb} (100%) rename db/post_migrate/{20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb => 20251217130430_add_concurrent_index_to_pool_repositories_on_organization_id.rb} (100%) rename db/post_migrate/{20251120181048_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb => 20251217130432_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb} (100%) rename db/post_migrate/{20251120181151_queue_backfill_pool_repositories_organization_id.rb => 20251217130435_queue_backfill_pool_repositories_organization_id.rb} (100%) delete mode 100644 db/schema_migrations/20251120181040 delete mode 100644 db/schema_migrations/20251120181044 delete mode 100644 db/schema_migrations/20251120181048 delete mode 100644 db/schema_migrations/20251120181151 create mode 100644 db/schema_migrations/20251217130425 create mode 100644 db/schema_migrations/20251217130430 create mode 100644 db/schema_migrations/20251217130432 create mode 100644 db/schema_migrations/20251217130435 diff --git a/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml b/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml index 668f1935d8c8a7..9dabb9330fb499 100644 --- a/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml +++ b/db/docs/batched_background_migrations/backfill_pool_repositories_organization_id.yml @@ -4,5 +4,5 @@ description: Backfills organization_id on pool_repositories feature_category: source_code_management introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/208322 milestone: '18.8' -queued_migration_version: 20251120181151 +queued_migration_version: 20251217130435 finalized_by: # version of the migration that finalized this BBM diff --git a/db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb b/db/migrate/20251217130425_add_sharding_key_trigger_to_pool_repositories.rb similarity index 100% rename from db/migrate/20251120181040_add_sharding_key_trigger_to_pool_repositories.rb rename to db/migrate/20251217130425_add_sharding_key_trigger_to_pool_repositories.rb diff --git a/db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb b/db/post_migrate/20251217130430_add_concurrent_index_to_pool_repositories_on_organization_id.rb similarity index 100% rename from db/post_migrate/20251120181044_add_concurrent_index_to_pool_repositories_on_organization_id.rb rename to db/post_migrate/20251217130430_add_concurrent_index_to_pool_repositories_on_organization_id.rb diff --git a/db/post_migrate/20251120181048_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb b/db/post_migrate/20251217130432_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb similarity index 100% rename from db/post_migrate/20251120181048_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb rename to db/post_migrate/20251217130432_add_not_valid_foreign_key_constraint_to_pool_repositories_on_organization_id.rb diff --git a/db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb b/db/post_migrate/20251217130435_queue_backfill_pool_repositories_organization_id.rb similarity index 100% rename from db/post_migrate/20251120181151_queue_backfill_pool_repositories_organization_id.rb rename to db/post_migrate/20251217130435_queue_backfill_pool_repositories_organization_id.rb diff --git a/db/schema_migrations/20251120181040 b/db/schema_migrations/20251120181040 deleted file mode 100644 index 6f9e1c5a803843..00000000000000 --- a/db/schema_migrations/20251120181040 +++ /dev/null @@ -1 +0,0 @@ -d3f0fc55f6b2b23cbd85b872f8e7ebf5073ceaf00a83e92f2f366477d0d7d1a5 \ No newline at end of file diff --git a/db/schema_migrations/20251120181044 b/db/schema_migrations/20251120181044 deleted file mode 100644 index c19fd07d233cd3..00000000000000 --- a/db/schema_migrations/20251120181044 +++ /dev/null @@ -1 +0,0 @@ -123c79cfd3e186b8b0c4de006e8fb97dd777e5febb4137ac7222002e96e68560 \ No newline at end of file diff --git a/db/schema_migrations/20251120181048 b/db/schema_migrations/20251120181048 deleted file mode 100644 index 0f5fa919bd7ff4..00000000000000 --- a/db/schema_migrations/20251120181048 +++ /dev/null @@ -1 +0,0 @@ -1a1346e82f97abc066415b419847ea19ffc44f7bf6b073ff0dc2f918cbe4001e \ No newline at end of file diff --git a/db/schema_migrations/20251120181151 b/db/schema_migrations/20251120181151 deleted file mode 100644 index 0f84b3f86eeb35..00000000000000 --- a/db/schema_migrations/20251120181151 +++ /dev/null @@ -1 +0,0 @@ -bb297d681db8f7c5310e17d7634aeba28b6a36b64de51ce30237d50caa53857b \ No newline at end of file diff --git a/db/schema_migrations/20251217130425 b/db/schema_migrations/20251217130425 new file mode 100644 index 00000000000000..2319a2d797f701 --- /dev/null +++ b/db/schema_migrations/20251217130425 @@ -0,0 +1 @@ +9e6922df75c95742c85248c2ad224950c95594f342ac5f25a0233bf531ff92d5 \ No newline at end of file diff --git a/db/schema_migrations/20251217130430 b/db/schema_migrations/20251217130430 new file mode 100644 index 00000000000000..c5690919b4b859 --- /dev/null +++ b/db/schema_migrations/20251217130430 @@ -0,0 +1 @@ +8ecdda8961617a9b25040679ddc990497b70158cf70c57ff435d58a1f9c1f172 \ No newline at end of file diff --git a/db/schema_migrations/20251217130432 b/db/schema_migrations/20251217130432 new file mode 100644 index 00000000000000..890244eaa20d7c --- /dev/null +++ b/db/schema_migrations/20251217130432 @@ -0,0 +1 @@ +2400e2526b7069ad5fe248a8a952af35cc33d15b518fbaa2ac7cce9b0c6a17c7 \ No newline at end of file diff --git a/db/schema_migrations/20251217130435 b/db/schema_migrations/20251217130435 new file mode 100644 index 00000000000000..8e451dcbe53e33 --- /dev/null +++ b/db/schema_migrations/20251217130435 @@ -0,0 +1 @@ +3f6cc8fa80bfbbdc64a5ba7e7f86a7fda9ca92b9aa2a1628183688754c467d9d \ No newline at end of file -- GitLab