Commit e414ca95 authored by Furkan Ayhan's avatar Furkan Ayhan

Merge branch 'remove-projects_ci_runner_projects_project_id-fk' into 'master'

Swap FK ci_runner_projects.project_id to projects for LFK

See merge request gitlab-org/gitlab!79022
parents 1a76d420 92ce5750
# frozen_string_literal: true
class RemoveProjectsCiRunnerProjectsProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return unless foreign_key_exists?(:ci_runner_projects, :projects, name: "fk_4478a6f1e4")
with_lock_retries do
execute('LOCK projects, ci_runner_projects IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_runner_projects, :projects, name: "fk_4478a6f1e4")
end
end
def down
add_concurrent_foreign_key(:ci_runner_projects, :projects, name: "fk_4478a6f1e4", column: :project_id, target_column: :id, on_delete: :cascade)
end
end
4eb33deb4c2d5ff587f8af57b8296e46911f24a6ed0b2f7ff1f36243f1a9013d
\ No newline at end of file
......@@ -29369,9 +29369,6 @@ ALTER TABLE ONLY remote_mirrors
ALTER TABLE ONLY incident_management_timeline_events
ADD CONSTRAINT fk_4432fc4d78 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_runner_projects
ADD CONSTRAINT fk_4478a6f1e4 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY todos
ADD CONSTRAINT fk_45054f9c45 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
......@@ -31,6 +31,10 @@ ci_variables:
- table: projects
column: project_id
on_delete: async_delete
ci_runner_projects:
- table: projects
column: project_id
on_delete: async_delete
ci_job_token_project_scope_links:
- table: users
column: added_by_id
......
......@@ -27,7 +27,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_project_monthly_usages.project_id
ci_resource_groups.project_id
ci_runner_namespaces.namespace_id
ci_runner_projects.project_id
ci_running_builds.project_id
ci_sources_projects.source_project_id
ci_stages.project_id
......
......@@ -6,4 +6,11 @@ RSpec.describe Ci::RunnerProject do
it_behaves_like 'includes Limitable concern' do
subject { build(:ci_runner_project, project: create(:project), runner: create(:ci_runner, :project)) }
end
context 'loose foreign key on ci_runner_projects.project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_runner_project, project: parent) }
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment