Commit 52d11faf authored by Patrick Bair's avatar Patrick Bair

Merge branch 'sk/340846-fix-project-delete-error' into 'master'

Add ON DELETE constraint to security_policy_management_project_id

See merge request gitlab-org/gitlab!71391
parents bea71761 402154b0
# 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
......@@ -28643,9 +28643,6 @@ ALTER TABLE ONLY epic_issues
ALTER TABLE ONLY ci_refs
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
ADD CONSTRAINT fk_rails_430336af2d FOREIGN KEY (resource_group_id) REFERENCES ci_resource_groups(id) ON DELETE CASCADE;
......@@ -29825,6 +29822,9 @@ ALTER TABLE ONLY resource_label_events
ALTER TABLE ONLY ci_builds_metadata
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
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
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
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