Commit 7a142562 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'remove-projects_ci_builds_project_id-fk' into 'master'

Swap FK ci_builds.project_id to projects for LFK

See merge request gitlab-org/gitlab!79275
parents a6066836 511221eb
# frozen_string_literal: true
class RemoveProjectsCiBuildsProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return if Gitlab.com? # unsafe migration, skip on GitLab.com due to https://gitlab.com/groups/gitlab-org/-/epics/7249#note_819625526
return unless foreign_key_exists?(:ci_builds, :projects, name: "fk_befce0568a")
with_lock_retries do
execute('LOCK projects, ci_builds IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_builds, :projects, name: "fk_befce0568a")
end
end
def down
add_concurrent_foreign_key(:ci_builds, :projects, name: "fk_befce0568a", column: :project_id, target_column: :id, on_delete: :cascade)
end
end
fd7940bb6f077c91d7f9928f574443ba4bf33bb90cb702c0a2ecad14398ab1cc
\ No newline at end of file
......@@ -29753,9 +29753,6 @@ ALTER TABLE ONLY ci_sources_pipelines
ALTER TABLE ONLY packages_maven_metadata
ADD CONSTRAINT fk_be88aed360 FOREIGN KEY (package_id) REFERENCES packages_packages(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_builds
ADD CONSTRAINT fk_befce0568a FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY design_management_versions
ADD CONSTRAINT fk_c1440b4896 FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE SET NULL;
......@@ -88,6 +88,9 @@ ci_builds:
- table: users
column: user_id
on_delete: async_nullify
- table: projects
column: project_id
on_delete: async_delete
ci_pipelines:
- table: merge_requests
column: merge_request_id
......
......@@ -12,7 +12,6 @@ RSpec.describe 'cross-database foreign keys' do
let(:allowed_cross_database_foreign_keys) do
%w(
ci_build_report_results.project_id
ci_builds.project_id
ci_daily_build_group_report_results.group_id
ci_daily_build_group_report_results.project_id
ci_freeze_periods.project_id
......
......@@ -987,4 +987,11 @@ RSpec.describe CommitStatus do
commit_status.expire_etag_cache!
end
end
context 'loose foreign key on ci_builds.project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_build, project: parent) }
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