diff --git a/db/post_migrate/20230119085509_add_index_to_ci_running_build.rb b/db/post_migrate/20230119085509_add_index_to_ci_running_build.rb new file mode 100644 index 0000000000000000000000000000000000000000..f340b78801fb371cd36f351ab0b3d2c9d733d6f5 --- /dev/null +++ b/db/post_migrate/20230119085509_add_index_to_ci_running_build.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexToCiRunningBuild < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + INDEX_NAME = :index_ci_running_builds_on_partition_id_build_id + TABLE_NAME = :ci_running_builds + COLUMNS = [:partition_id, :build_id] + + def up + add_concurrent_index(TABLE_NAME, COLUMNS, unique: true, name: INDEX_NAME) + end + + def down + remove_concurrent_index_by_name(TABLE_NAME, INDEX_NAME) + end +end diff --git a/db/post_migrate/20230119085552_add_foreign_key_to_ci_running_build.rb b/db/post_migrate/20230119085552_add_foreign_key_to_ci_running_build.rb new file mode 100644 index 0000000000000000000000000000000000000000..94dfdc5b967ea21a8006964ab193815c9429f37f --- /dev/null +++ b/db/post_migrate/20230119085552_add_foreign_key_to_ci_running_build.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class AddForeignKeyToCiRunningBuild < Gitlab::Database::Migration[2.1] + disable_ddl_transaction! + + SOURCE_TABLE_NAME = :ci_running_builds + TARGET_TABLE_NAME = :ci_builds + COLUMN = :build_id + TARGET_COLUMN = :id + FK_NAME = :fk_rails_da45cfa165_p + PARTITION_COLUMN = :partition_id + + def up + add_concurrent_foreign_key( + SOURCE_TABLE_NAME, + TARGET_TABLE_NAME, + column: [PARTITION_COLUMN, COLUMN], + target_column: [PARTITION_COLUMN, TARGET_COLUMN], + validate: true, + reverse_lock_order: true, + name: FK_NAME, + on_update: :cascade + ) + end + + def down + with_lock_retries do + remove_foreign_key_if_exists(SOURCE_TABLE_NAME, name: FK_NAME) + end + end +end diff --git a/db/schema_migrations/20230119085509 b/db/schema_migrations/20230119085509 new file mode 100644 index 0000000000000000000000000000000000000000..1eb8297a4b36883011d189e10dc2c65f646a5714 --- /dev/null +++ b/db/schema_migrations/20230119085509 @@ -0,0 +1 @@ +6206e50e14c129aeb1d44fbd82add001e73b338bbe80bdade852ff7ec0bc0f86 \ No newline at end of file diff --git a/db/schema_migrations/20230119085552 b/db/schema_migrations/20230119085552 new file mode 100644 index 0000000000000000000000000000000000000000..d548c864d2f7b84f3885ea2428a51bb1772149b5 --- /dev/null +++ b/db/schema_migrations/20230119085552 @@ -0,0 +1 @@ +4bc2f855e1448c3c1b3d6d2b853dc61b049048fa0fee663fe798d86ea88b09a0 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 5f33b103d72f968c7f36b45768165eb4b496b6b8..8b05ce220eca0092d5e375f6dc3d0c61731c03c1 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -29129,6 +29129,8 @@ CREATE INDEX index_ci_runners_on_version ON ci_runners USING btree (version); CREATE UNIQUE INDEX index_ci_running_builds_on_build_id ON ci_running_builds USING btree (build_id); +CREATE UNIQUE INDEX index_ci_running_builds_on_partition_id_build_id ON ci_running_builds USING btree (partition_id, build_id); + CREATE INDEX index_ci_running_builds_on_project_id ON ci_running_builds USING btree (project_id); CREATE INDEX index_ci_running_builds_on_runner_id ON ci_running_builds USING btree (runner_id); @@ -35676,6 +35678,9 @@ ALTER TABLE ONLY merge_request_reviewers ALTER TABLE ONLY ci_running_builds ADD CONSTRAINT fk_rails_da45cfa165 FOREIGN KEY (build_id) REFERENCES ci_builds(id) ON DELETE CASCADE; +ALTER TABLE ONLY ci_running_builds + ADD CONSTRAINT fk_rails_da45cfa165_p FOREIGN KEY (partition_id, build_id) REFERENCES ci_builds(partition_id, id) ON UPDATE CASCADE ON DELETE CASCADE; + ALTER TABLE ONLY jira_imports ADD CONSTRAINT fk_rails_da617096ce FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;