diff --git a/db/migrate/20221202202351_remove_index_i_ci_job_token_project_scope_links_on_source_and_target_project.rb b/db/migrate/20221202202351_remove_index_i_ci_job_token_project_scope_links_on_source_and_target_project.rb new file mode 100644 index 0000000000000000000000000000000000000000..81a636739b48f2d64bd649d721f69c47deca1a40 --- /dev/null +++ b/db/migrate/20221202202351_remove_index_i_ci_job_token_project_scope_links_on_source_and_target_project.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true +class RemoveIndexICiJobTokenProjectScopeLinksOnSourceAndTargetProject < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + TABLE_NAME = 'ci_job_token_project_scope_links' + OLD_INDEX_NAME = 'i_ci_job_token_project_scope_links_on_source_and_target_project' + NEW_INDEX_NAME = 'ci_job_token_scope_links_source_and_target_project_direction' + NEW_INDEX_COL = %w[source_project_id target_project_id direction] + + def up + add_concurrent_index( + TABLE_NAME, + NEW_INDEX_COL, + name: NEW_INDEX_NAME, + unique: true + ) + remove_concurrent_index_by_name(TABLE_NAME, OLD_INDEX_NAME) + end + + def down + # noop: as we can have duplicate records once the unique index is removed + end +end diff --git a/db/schema_migrations/20221202202351 b/db/schema_migrations/20221202202351 new file mode 100644 index 0000000000000000000000000000000000000000..942bc0577d6065a113a853a20622739800b0b632 --- /dev/null +++ b/db/schema_migrations/20221202202351 @@ -0,0 +1 @@ +8e9641a603bd9540d0004fb76b407a5cb4392c8cc41c084cd746f354b9a8d417 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 8a18e64be25eeac0242d63ef469bea4d1c32fa71..0b2d5c0cd872b47a9fc342a0e1a8e2be11c8ca66 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -28001,6 +28001,8 @@ CREATE INDEX ca_aggregations_last_incremental_run_at ON analytics_cycle_analytic CREATE INDEX ci_builds_gitlab_monitor_metrics ON ci_builds USING btree (status, created_at, project_id) WHERE ((type)::text = 'Ci::Build'::text); +CREATE UNIQUE INDEX ci_job_token_scope_links_source_and_target_project_direction ON ci_job_token_project_scope_links USING btree (source_project_id, target_project_id, direction); + CREATE INDEX ci_pipeline_artifacts_on_expire_at_for_removal ON ci_pipeline_artifacts USING btree (expire_at) WHERE ((locked = 0) AND (expire_at IS NOT NULL)); CREATE INDEX code_owner_approval_required ON protected_branches USING btree (project_id, code_owner_approval_required) WHERE (code_owner_approval_required = true); @@ -28031,8 +28033,6 @@ CREATE INDEX finding_links_on_vulnerability_occurrence_id ON vulnerability_findi CREATE INDEX i_batched_background_migration_job_transition_logs_on_job_id ON ONLY batched_background_migration_job_transition_logs USING btree (batched_background_migration_job_id); -CREATE UNIQUE INDEX i_ci_job_token_project_scope_links_on_source_and_target_project ON ci_job_token_project_scope_links USING btree (source_project_id, target_project_id); - CREATE INDEX i_compliance_frameworks_on_id_and_created_at ON compliance_management_frameworks USING btree (id, created_at, pipeline_configuration_full_path); CREATE UNIQUE INDEX i_pm_licenses_on_spdx_identifier ON pm_licenses USING btree (spdx_identifier);