diff --git a/config/gitlab_loose_foreign_keys.yml b/config/gitlab_loose_foreign_keys.yml index 228a372725182d3937758a0f9333d566faf8e580..98257f8e33ad7587c95f3ffca3eb36c9cefb616e 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 0000000000000000000000000000000000000000..bd62094bd6203d433b26e5e5525c752041c4c992 --- /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 0000000000000000000000000000000000000000..a35188353dc55d35000f9626c85af43f4eee2bed --- /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 0000000000000000000000000000000000000000..eb980cf09c92f2644253ed9e55f99333cdc25001 --- /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 0000000000000000000000000000000000000000..b459f9fb467be90ca5c9c6f12ec4cc23e03665a3 --- /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 5b6ce385a002759f62f4092d3c2305ac680a9323..9b54d78dc23b50265f389b5889cf2258207e82ca 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 d656d92a7aa0bfca8e2424da9d5cd2dc9e1a9c62..bc240a06c4091b74c79118a255de3b8d71b2c1c8 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' } }