Commit 71190031 authored by Marius Bobin's avatar Marius Bobin

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

Swap FK ci_triggers.owner_id to users for LFK

See merge request gitlab-org/gitlab!78563
parents 1673727e 3540dcc5
# frozen_string_literal: true
class RemoveUsersCiTriggersOwnerIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
with_lock_retries do
execute('LOCK users, ci_triggers IN ACCESS EXCLUSIVE MODE')
remove_foreign_key_if_exists(:ci_triggers, :users, name: "fk_e8e10d1964")
end
end
def down
add_concurrent_foreign_key(:ci_triggers, :users, name: "fk_e8e10d1964", column: :owner_id, target_column: :id, on_delete: :cascade)
end
end
85227d2aa0e984f12362484b23554a4feb1304d055d54da40e20812f2d8c5b9e
\ No newline at end of file
......@@ -29930,9 +29930,6 @@ ALTER TABLE ONLY application_settings
ALTER TABLE ONLY vulnerability_statistics
ADD CONSTRAINT fk_e8b13c928f FOREIGN KEY (latest_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE SET NULL;
ALTER TABLE ONLY ci_triggers
ADD CONSTRAINT fk_e8e10d1964 FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY integrations
ADD CONSTRAINT fk_e8fe908a34 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
......@@ -162,3 +162,7 @@ ci_sources_pipelines:
- table: projects
column: source_project_id
on_delete: async_delete
ci_triggers:
- table: users
column: owner_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.owner_id
ci_triggers.project_id
ci_unit_tests.project_id
ci_variables.project_id
......
......@@ -61,4 +61,11 @@ RSpec.describe Ci::Trigger do
it_behaves_like 'includes Limitable concern' do
subject { build(:ci_trigger, owner: project.owner, project: project) }
end
context 'loose foreign key on ci_triggers.owner_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:user) }
let!(:model) { create(:ci_trigger, owner: 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