Commit ed2adc84 authored by Dylan Griffith's avatar Dylan Griffith Committed by Adam Hegyi

Remove foreign key ci_group_variables.group_id as we have loose fK

In https://gitlab.com/gitlab-org/gitlab/-/merge_requests/77322 we
already added a ["loose foreign key"](
https://docs.gitlab.com/ee/development/database/loose_foreign_keys.html)
to replace this foreign key. Now that this has been running fine in
production we should be OK to remove the foreign key altogether.

This was added in a post-deployment migration as we want to ensure that
they have the correct code running with the loose foreign key in place
before we remove the foreign key to ensure that there isn't any lost
deletes.

Changelog: other
parent 083c1505
# frozen_string_literal: true
class RemoveForeignKeyCiGroupVariablesGroupId < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
CONSTRAINT_NAME = 'fk_33ae4d58d8'
def up
with_lock_retries do
remove_foreign_key_if_exists(:ci_group_variables, :namespaces, name: CONSTRAINT_NAME)
end
end
def down
add_concurrent_foreign_key :ci_group_variables, :namespaces, column: :group_id, on_delete: :cascade, name: CONSTRAINT_NAME
end
end
fa87b087b576d320f94028444a082b920870a2554209808849f9f3f42ead83c4
\ No newline at end of file
......@@ -29179,9 +29179,6 @@ ALTER TABLE ONLY approvals
ALTER TABLE ONLY namespaces
ADD CONSTRAINT fk_319256d87a FOREIGN KEY (file_template_project_id) REFERENCES projects(id) ON DELETE SET NULL;
ALTER TABLE ONLY ci_group_variables
ADD CONSTRAINT fk_33ae4d58d8 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY namespaces
ADD CONSTRAINT fk_3448c97865 FOREIGN KEY (push_rule_id) REFERENCES push_rules(id) ON DELETE SET NULL;
......@@ -42,4 +42,10 @@ RSpec.describe Ci::GroupVariable do
end
end
end
it_behaves_like 'cleanup by a loose foreign key' do
let!(:model) { create(:ci_group_variable) }
let!(:parent) { model.group }
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