From 34c02117ed94dbb83d583852ec0ec30f67f55f88 Mon Sep 17 00:00:00 2001 From: Olaoluwa Oluro Date: Thu, 27 Feb 2025 13:38:23 +0000 Subject: [PATCH] Add `organization_id` field to `fork_networks` This adds `organization_id` column to the `fork_networks` table to support sharding on Cells 1.0. It also provides an index to the newly added organization_id column. Changelog: added --- config/gitlab_loose_foreign_keys.yml | 4 ++++ ...537_add_organization_id_to_fork_networks.rb | 11 +++++++++++ ...dex_for_organization_id_on_fork_networks.rb | 18 ++++++++++++++++++ db/schema_migrations/20250227095537 | 1 + db/schema_migrations/20250227102407 | 1 + db/structure.sql | 5 ++++- spec/lib/gitlab/database/sharding_key_spec.rb | 3 ++- 7 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20250227095537_add_organization_id_to_fork_networks.rb create mode 100644 db/post_migrate/20250227102407_add_index_for_organization_id_on_fork_networks.rb create mode 100644 db/schema_migrations/20250227095537 create mode 100644 db/schema_migrations/20250227102407 diff --git a/config/gitlab_loose_foreign_keys.yml b/config/gitlab_loose_foreign_keys.yml index 228a372725182d..98257f8e33ad75 100644 --- a/config/gitlab_loose_foreign_keys.yml +++ b/config/gitlab_loose_foreign_keys.yml @@ -320,6 +320,10 @@ external_pull_requests: - table: projects column: project_id on_delete: async_delete +fork_networks: + - table: organizations + column: organization_id + on_delete: async_delete group_security_exclusions: - table: namespaces column: group_id diff --git a/db/migrate/20250227095537_add_organization_id_to_fork_networks.rb b/db/migrate/20250227095537_add_organization_id_to_fork_networks.rb new file mode 100644 index 00000000000000..bd62094bd6203d --- /dev/null +++ b/db/migrate/20250227095537_add_organization_id_to_fork_networks.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class AddOrganizationIdToForkNetworks < Gitlab::Database::Migration[2.2] + milestone '17.10' + + enable_lock_retries! + + def change + add_column :fork_networks, :organization_id, :bigint, null: true + end +end diff --git a/db/post_migrate/20250227102407_add_index_for_organization_id_on_fork_networks.rb b/db/post_migrate/20250227102407_add_index_for_organization_id_on_fork_networks.rb new file mode 100644 index 00000000000000..a35188353dc55d --- /dev/null +++ b/db/post_migrate/20250227102407_add_index_for_organization_id_on_fork_networks.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class AddIndexForOrganizationIdOnForkNetworks < Gitlab::Database::Migration[2.2] + milestone '17.10' + + disable_ddl_transaction! + + TABLE_NAME = :fork_networks + INDEX_NAME = 'index_fork_networks_on_organization_id' + + def up + add_concurrent_index TABLE_NAME, :organization_id, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name TABLE_NAME, INDEX_NAME + end +end diff --git a/db/schema_migrations/20250227095537 b/db/schema_migrations/20250227095537 new file mode 100644 index 00000000000000..eb980cf09c92f2 --- /dev/null +++ b/db/schema_migrations/20250227095537 @@ -0,0 +1 @@ +d211433f7c46ddcf0a85d912b4dbab58af583174415e0a16705087b4d55732f0 \ No newline at end of file diff --git a/db/schema_migrations/20250227102407 b/db/schema_migrations/20250227102407 new file mode 100644 index 00000000000000..b459f9fb467be9 --- /dev/null +++ b/db/schema_migrations/20250227102407 @@ -0,0 +1 @@ +87839950df3e95155710d1572c04ff199557d3feffb6ff9d172521ad9fd7572d \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 5b6ce385a00275..9b54d78dc23b50 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -13761,7 +13761,8 @@ ALTER SEQUENCE fork_network_members_id_seq OWNED BY fork_network_members.id; CREATE TABLE fork_networks ( id bigint NOT NULL, root_project_id bigint, - deleted_root_project_name character varying + deleted_root_project_name character varying, + organization_id bigint ); CREATE SEQUENCE fork_networks_id_seq @@ -33002,6 +33003,8 @@ CREATE INDEX index_fork_network_members_on_forked_from_project_id ON fork_networ CREATE UNIQUE INDEX index_fork_network_members_on_project_id ON fork_network_members USING btree (project_id); +CREATE INDEX index_fork_networks_on_organization_id ON fork_networks USING btree (organization_id); + CREATE UNIQUE INDEX index_fork_networks_on_root_project_id ON fork_networks USING btree (root_project_id); CREATE INDEX index_geo_event_log_on_cache_invalidation_event_id ON geo_event_log USING btree (cache_invalidation_event_id) WHERE (cache_invalidation_event_id IS NOT NULL); diff --git a/spec/lib/gitlab/database/sharding_key_spec.rb b/spec/lib/gitlab/database/sharding_key_spec.rb index d656d92a7aa0bf..bc240a06c4091b 100644 --- a/spec/lib/gitlab/database/sharding_key_spec.rb +++ b/spec/lib/gitlab/database/sharding_key_spec.rb @@ -204,7 +204,8 @@ "oauth_device_grants" => "https://gitlab.com/gitlab-org/gitlab/-/issues/496717", "uploads" => "https://gitlab.com/gitlab-org/gitlab/-/issues/398199", "bulk_import_trackers" => "https://gitlab.com/gitlab-org/gitlab/-/issues/517823", - "ai_duo_chat_events" => "https://gitlab.com/gitlab-org/gitlab/-/issues/516140" + "ai_duo_chat_events" => "https://gitlab.com/gitlab-org/gitlab/-/issues/516140", + "fork_networks" => "https://gitlab.com/gitlab-org/gitlab/-/issues/522958" } has_lfk = ->(lfks) { lfks.any? { |k| k.options[:column] == 'organization_id' && k.to_table == 'organizations' } } -- GitLab