Commit 647ddc65 authored by Fabio Pitino's avatar Fabio Pitino

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

Swap FK ci_triggers.project_id to projects for LFK

See merge request gitlab-org/gitlab!79021
parents a467ac15 6f1546ce
# frozen_string_literal: true
class RemoveProjectsCiTriggersProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return unless foreign_key_exists?(:ci_triggers, :projects, name: "fk_e3e63f966e")
with_lock_retries do
execute('LOCK projects, ci_triggers IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_triggers, :projects, name: "fk_e3e63f966e")
end
end
def down
add_concurrent_foreign_key(:ci_triggers, :projects, name: "fk_e3e63f966e", column: :project_id, target_column: :id, on_delete: :cascade)
end
end
5ec73b28adb027a4462ec9b268ef9c505e281f1afedce3c592d431cd90808dac
\ No newline at end of file
......@@ -29906,9 +29906,6 @@ ALTER TABLE ONLY ci_builds_metadata
ALTER TABLE ONLY gitlab_subscriptions
ADD CONSTRAINT fk_e2595d00a1 FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_triggers
ADD CONSTRAINT fk_e3e63f966e FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY merge_requests
ADD CONSTRAINT fk_e719a85f8a FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL;
......@@ -170,3 +170,6 @@ ci_triggers:
- table: users
column: owner_id
on_delete: async_delete
- table: projects
column: project_id
on_delete: async_delete
......@@ -38,7 +38,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_stages.project_id
ci_subscriptions_projects.downstream_project_id
ci_subscriptions_projects.upstream_project_id
ci_triggers.project_id
ci_unit_tests.project_id
ci_variables.project_id
dast_site_profiles_pipelines.ci_pipeline_id
......
......@@ -68,4 +68,11 @@ RSpec.describe Ci::Trigger do
let!(:model) { create(:ci_trigger, owner: parent) }
end
end
context 'loose foreign key on ci_triggers.project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_trigger, 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