Commit dfdb363a authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'jprovazn-project_fk' into 'master'

Nullify project_namespace_id reference

See merge request gitlab-org/gitlab!78046
parents 2a8c0142 9699e82f
# frozen_string_literal: true
class RemoveCascadeDeleteFromProjectNamespaceForeignKey < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
TARGET_COLUMN = :project_namespace_id
def up
with_lock_retries do
remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN)
end
add_concurrent_foreign_key(:projects, :namespaces, column: TARGET_COLUMN, on_delete: :nullify)
end
def down
with_lock_retries do
remove_foreign_key_if_exists(:projects, column: TARGET_COLUMN)
end
add_concurrent_foreign_key(:projects, :namespaces, column: TARGET_COLUMN, on_delete: :cascade)
end
end
e78e11a47017c67130fe88fa538578553b7015c18cf222b5e7fb7f503254dc6d
\ No newline at end of file
......@@ -29346,7 +29346,7 @@ ALTER TABLE ONLY protected_branch_push_access_levels
ADD CONSTRAINT fk_7111b68cdb FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY projects
ADD CONSTRAINT fk_71625606ac FOREIGN KEY (project_namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ADD CONSTRAINT fk_71625606ac FOREIGN KEY (project_namespace_id) REFERENCES namespaces(id) ON DELETE SET NULL;
ALTER TABLE ONLY integrations
ADD CONSTRAINT fk_71cce407f9 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
......@@ -17,11 +17,11 @@ RSpec.describe Namespaces::ProjectNamespace, type: :model do
let_it_be(:project) { create(:project) }
let_it_be(:project_namespace) { project.project_namespace }
it 'also deletes the associated project' do
it 'keeps the associated project' do
project_namespace.delete
expect { project_namespace.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect { project.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(project.reload.project_namespace).to be_nil
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