Commit 9699e82f authored by Jan Provaznik's avatar Jan Provaznik

Nullify project_namespace_id reference

Because project namespaces are not backfilled for projects yet
and we may need to rollback created project namespaces) it would
be dangerous to use cascade deletion for projects.

For now we just nullify project_namespace_id reference, when backfilling
is done, we can restore cascade deletion.

Changelog: changed
parent 4cc9082e
# 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
......@@ -29344,7 +29344,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