Commit 1716da95 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre Committed by Adam Hegyi

Swap FK ci_pipelines to projects for LFK

Swaps FK for ci_pipelines.project_id to projects

Changelog: changed
parent e14b7cce
# frozen_string_literal: true
class RemoveProjectsCiPipelinesProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return unless foreign_key_exists?(:ci_pipelines, :projects, name: "fk_86635dbd80")
with_lock_retries do
execute('LOCK projects, ci_pipelines IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_pipelines, :projects, name: "fk_86635dbd80")
end
end
def down
add_concurrent_foreign_key(:ci_pipelines, :projects, name: "fk_86635dbd80", column: :project_id, target_column: :id, on_delete: :cascade)
end
end
853209f3babe2856481591790d9bb67145c4c0c919ed4d8365bb8d498e4f6b8e
\ No newline at end of file
......@@ -29544,9 +29544,6 @@ ALTER TABLE ONLY merge_request_diffs
ALTER TABLE ONLY requirements
ADD CONSTRAINT fk_85044baef0 FOREIGN KEY (issue_id) REFERENCES issues(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_pipelines
ADD CONSTRAINT fk_86635dbd80 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY geo_event_log
ADD CONSTRAINT fk_86c84214ec FOREIGN KEY (repository_renamed_event_id) REFERENCES geo_repository_renamed_events(id) ON DELETE CASCADE;
......@@ -112,6 +112,9 @@ ci_pipelines:
- table: users
column: user_id
on_delete: async_nullify
- table: projects
column: project_id
on_delete: async_delete
ci_project_mirrors:
- table: projects
column: project_id
......
......@@ -19,7 +19,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_pending_builds.namespace_id
ci_pending_builds.project_id
ci_pipeline_schedules.owner_id
ci_pipelines.project_id
ci_resource_groups.project_id
ci_runner_namespaces.namespace_id
ci_running_builds.project_id
......
......@@ -4731,4 +4731,11 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
let!(:model) { create(:ci_pipeline, merge_request: parent) }
end
end
context 'loose foreign key on ci_pipelines.project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_pipeline, 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