Commit 474fcc18 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

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

Swap FK ci_stages.project_id to projects for LFK

See merge request gitlab-org/gitlab!78945
parents 3e386174 dbc0fb73
# frozen_string_literal: true
class RemoveProjectsCiStagesProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return if Gitlab.com? # unsafe migration, skip on GitLab.com due to https://gitlab.com/groups/gitlab-org/-/epics/7249#note_819625526
return unless foreign_key_exists?(:ci_stages, :projects, name: "fk_2360681d1d")
with_lock_retries do
execute('LOCK projects, ci_stages IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_stages, :projects, name: "fk_2360681d1d")
end
end
def down
add_concurrent_foreign_key(:ci_stages, :projects, name: "fk_2360681d1d", column: :project_id, target_column: :id, on_delete: :cascade)
end
end
c56983a489b56eb6b4a5cd5ae6947a322fd58b8e96bcdee1e38634d99727c432
\ No newline at end of file
......@@ -29261,9 +29261,6 @@ ALTER TABLE ONLY users_star_projects
ALTER TABLE ONLY alert_management_alerts
ADD CONSTRAINT fk_2358b75436 FOREIGN KEY (issue_id) REFERENCES issues(id) ON DELETE SET NULL;
ALTER TABLE ONLY ci_stages
ADD CONSTRAINT fk_2360681d1d FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY import_failures
ADD CONSTRAINT fk_24b824da43 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
......@@ -191,6 +191,10 @@ ci_sources_pipelines:
- table: projects
column: project_id
on_delete: async_delete
ci_stages:
- table: projects
column: project_id
on_delete: async_delete
ci_triggers:
- table: users
column: owner_id
......
......@@ -362,4 +362,11 @@ RSpec.describe Ci::Stage, :models do
end
it_behaves_like 'manual playable stage', :ci_stage_entity
context 'loose foreign key on ci_stages.project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_stage_entity, 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