Commit 402154b0 authored by Sashi Kumar Kumaresan's avatar Sashi Kumar Kumaresan Committed by Patrick Bair

Add ON DELETE constraint to security_policy_management_project_id

This change adds ON DELETE CASCADE fk constraint
to security_orchestration_policy_configurations table for
security_policy_management_project_id column. This allows
the deletion of security_policy_management_project without
ForeignKeyViolation error.

Changelog: fixed
parent ae63ee79
# frozen_string_literal: true
class AddSecurityPolicyConfigurationsManagementProjectIdForeignKey < Gitlab::Database::Migration[1.0]
CONSTRAINT_NAME = 'fk_security_policy_configurations_management_project_id'
OLD_CONSTRAINT_NAME = 'fk_rails_42ed6c25ec'
disable_ddl_transaction!
def up
add_concurrent_foreign_key(:security_orchestration_policy_configurations, :projects, column: :security_policy_management_project_id, on_delete: :cascade, name: CONSTRAINT_NAME)
remove_foreign_key_if_exists(:security_orchestration_policy_configurations, column: :security_policy_management_project_id, on_delete: :restrict, name: OLD_CONSTRAINT_NAME)
end
def down
add_concurrent_foreign_key(:security_orchestration_policy_configurations, :projects, column: :security_policy_management_project_id, on_delete: :restrict, name: OLD_CONSTRAINT_NAME)
remove_foreign_key_if_exists(:security_orchestration_policy_configurations, column: :security_policy_management_project_id, on_delete: :cascade, name: CONSTRAINT_NAME)
end
end
0de2844fdec43eca860648bdb1a5b184bcc0f79b51086b16d8ef398f32cfd5de
\ No newline at end of file
...@@ -28639,9 +28639,6 @@ ALTER TABLE ONLY epic_issues ...@@ -28639,9 +28639,6 @@ ALTER TABLE ONLY epic_issues
ALTER TABLE ONLY ci_refs ALTER TABLE ONLY ci_refs
ADD CONSTRAINT fk_rails_4249db8cc3 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_4249db8cc3 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY security_orchestration_policy_configurations
ADD CONSTRAINT fk_rails_42ed6c25ec FOREIGN KEY (security_policy_management_project_id) REFERENCES projects(id) ON DELETE RESTRICT;
ALTER TABLE ONLY ci_resources ALTER TABLE ONLY ci_resources
ADD CONSTRAINT fk_rails_430336af2d FOREIGN KEY (resource_group_id) REFERENCES ci_resource_groups(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_430336af2d FOREIGN KEY (resource_group_id) REFERENCES ci_resource_groups(id) ON DELETE CASCADE;
...@@ -29821,6 +29818,9 @@ ALTER TABLE ONLY resource_label_events ...@@ -29821,6 +29818,9 @@ ALTER TABLE ONLY resource_label_events
ALTER TABLE ONLY ci_builds_metadata ALTER TABLE ONLY ci_builds_metadata
ADD CONSTRAINT fk_rails_ffcf702a02 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_ffcf702a02 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY security_orchestration_policy_configurations
ADD CONSTRAINT fk_security_policy_configurations_management_project_id FOREIGN KEY (security_policy_management_project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY integrations ALTER TABLE ONLY integrations
ADD CONSTRAINT fk_services_inherit_from_id FOREIGN KEY (inherit_from_id) REFERENCES integrations(id) ON DELETE CASCADE; ADD CONSTRAINT fk_services_inherit_from_id FOREIGN KEY (inherit_from_id) REFERENCES integrations(id) ON DELETE CASCADE;
...@@ -254,6 +254,18 @@ RSpec.describe Project do ...@@ -254,6 +254,18 @@ RSpec.describe Project do
end end
end end
end end
context 'when deleting security policy project' do
let_it_be(:project) { create(:project) }
let_it_be(:policy_management_project) { create(:project) }
let_it_be(:policy_configuration) { create(:security_orchestration_policy_configuration, security_policy_management_project: policy_management_project, project: project) }
it 'also deletes the associated security_orchestration_policy_configuration' do
policy_management_project.delete
expect(project.reload.security_orchestration_policy_configuration).to be_nil
end
end
end end
context 'scopes' do context 'scopes' do
......
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