Commit 671e495b authored by Thong Kuah's avatar Thong Kuah

Remove ci_pending_builds FK to projects

We already have a ci_pending_builds FK to ci_builds.
ci_builds in turn have a FK to projects. So this FK should
be safe to remove.

With this change when project is deleted, dependent ci_pending_builds
will either be:

- deleted via loose foreign keys
- deleted via FK cascade projects -> ci_builds -> ci_pending_builds

Changelog: other
parent 2d9d5a76
# frozen_string_literal: true
class RemoveProjectsCiPendingBuildsFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
with_lock_retries do
remove_foreign_key_if_exists(:ci_pending_builds, :projects, name: "fk_rails_480669c3b3")
end
end
def down
add_concurrent_foreign_key(:ci_pending_builds, :projects, name: "fk_rails_480669c3b3", column: :project_id, target_column: :id, on_delete: "cascade")
end
end
0cb120b0036b3f472edb57fcb8a52877d399edf8ff1f416ce76497d6aa8265d7
\ No newline at end of file
......@@ -30368,9 +30368,6 @@ ALTER TABLE ONLY vulnerability_feedback
ALTER TABLE ONLY user_custom_attributes
ADD CONSTRAINT fk_rails_47b91868a8 FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_pending_builds
ADD CONSTRAINT fk_rails_480669c3b3 FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY upcoming_reconciliations
ADD CONSTRAINT fk_rails_497b4938ac FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
......@@ -228,4 +228,9 @@ RSpec.describe Ci::PendingBuild do
let!(:parent) { create(:namespace) }
let!(:model) { create(:ci_pending_build, namespace: parent) }
end
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_pending_build, project: parent) }
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