Commit dd963a33 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'afontaine/cascade-delete-freeze-periods' into 'master'

Allow Projects with Freeze Periods to be Deleted

See merge request gitlab-org/gitlab!64338
parents ab6286cb a9a9f0b6
# frozen_string_literal: true
# See https://docs.gitlab.com/ee/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class CascadeDeleteFreezePeriods < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
OLD_PROJECT_FK = 'fk_rails_2e02bbd1a6'
NEW_PROJECT_FK = 'fk_2e02bbd1a6'
disable_ddl_transaction!
def up
add_concurrent_foreign_key :ci_freeze_periods, :projects, column: :project_id, on_delete: :cascade, name: NEW_PROJECT_FK
remove_foreign_key_if_exists :ci_freeze_periods, :projects, column: :project_id, name: OLD_PROJECT_FK
end
def down
add_concurrent_foreign_key :ci_freeze_periods, :projects, column: :project_id, on_delete: nil, name: OLD_PROJECT_FK
remove_foreign_key_if_exists :ci_freeze_periods, :projects, column: :project_id, name: NEW_PROJECT_FK
end
end
3f73aa7d2cff11d00b330d88e76daaa058f82b7012da3c244f246da6e538921c
\ No newline at end of file
......@@ -25627,6 +25627,9 @@ ALTER TABLE ONLY geo_event_log
ALTER TABLE ONLY deployments
ADD CONSTRAINT fk_289bba3222 FOREIGN KEY (cluster_id) REFERENCES clusters(id) ON DELETE SET NULL;
ALTER TABLE ONLY ci_freeze_periods
ADD CONSTRAINT fk_2e02bbd1a6 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY notes
ADD CONSTRAINT fk_2e82291620 FOREIGN KEY (review_id) REFERENCES reviews(id) ON DELETE SET NULL;
......@@ -26575,9 +26578,6 @@ ALTER TABLE ONLY onboarding_progresses
ALTER TABLE ONLY protected_branch_unprotect_access_levels
ADD CONSTRAINT fk_rails_2d2aba21ef FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_freeze_periods
ADD CONSTRAINT fk_rails_2e02bbd1a6 FOREIGN KEY (project_id) REFERENCES projects(id);
ALTER TABLE ONLY issuable_severities
ADD CONSTRAINT fk_rails_2fbb74ad6d FOREIGN KEY (issue_id) REFERENCES issues(id) ON DELETE CASCADE;
# frozen_string_literal: true
require 'spec_helper'
require_migration!('cascade_delete_freeze_periods')
RSpec.describe CascadeDeleteFreezePeriods do
let(:namespace) { table(:namespaces).create!(name: 'deploy_freeze', path: 'deploy_freeze') }
let(:project) { table(:projects).create!(id: 1, namespace_id: namespace.id) }
let(:freeze_periods) { table(:ci_freeze_periods) }
describe "#up" do
it 'allows for a project to be deleted' do
freeze_periods.create!(id: 1, project_id: project.id, freeze_start: '5 * * * *', freeze_end: '6 * * * *', cron_timezone: 'UTC')
migrate!
project.delete
expect(freeze_periods.where(project_id: project.id).count).to be_zero
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