Commit df5f07ac authored by Adam Hegyi's avatar Adam Hegyi

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

Swap FK ci_job_token_project_scope_links.source_project_id to projects for LFK

See merge request gitlab-org/gitlab!79069
parents a44c5f5e cd3dc6e4
# frozen_string_literal: true
class RemoveProjectsCiJobTokenProjectScopeLinksSourceProjectIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
return unless foreign_key_exists?(:ci_job_token_project_scope_links, :projects, name: "fk_rails_4b2ee3290b")
with_lock_retries do
execute('LOCK projects, ci_job_token_project_scope_links IN ACCESS EXCLUSIVE MODE') if transaction_open?
remove_foreign_key_if_exists(:ci_job_token_project_scope_links, :projects, name: "fk_rails_4b2ee3290b")
end
end
def down
add_concurrent_foreign_key(:ci_job_token_project_scope_links, :projects, name: "fk_rails_4b2ee3290b", column: :source_project_id, target_column: :id, on_delete: :cascade)
end
end
785c2404175faef7d3d6f81ae8652ca0ced0f4b01def8d6364a4450f0db49ecf
\ No newline at end of file
...@@ -30452,9 +30452,6 @@ ALTER TABLE ONLY user_custom_attributes ...@@ -30452,9 +30452,6 @@ ALTER TABLE ONLY user_custom_attributes
ALTER TABLE ONLY upcoming_reconciliations ALTER TABLE ONLY upcoming_reconciliations
ADD CONSTRAINT fk_rails_497b4938ac FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_497b4938ac FOREIGN KEY (namespace_id) REFERENCES namespaces(id) ON DELETE CASCADE;
ALTER TABLE ONLY ci_job_token_project_scope_links
ADD CONSTRAINT fk_rails_4b2ee3290b FOREIGN KEY (source_project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY group_deletion_schedules ALTER TABLE ONLY group_deletion_schedules
ADD CONSTRAINT fk_rails_4b8c694a6c FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE; ADD CONSTRAINT fk_rails_4b8c694a6c FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
...@@ -35,6 +35,9 @@ ci_job_token_project_scope_links: ...@@ -35,6 +35,9 @@ ci_job_token_project_scope_links:
- table: users - table: users
column: added_by_id column: added_by_id
on_delete: async_nullify on_delete: async_nullify
- table: projects
column: source_project_id
on_delete: async_delete
ci_daily_build_group_report_results: ci_daily_build_group_report_results:
- table: namespaces - table: namespaces
column: group_id column: group_id
......
...@@ -19,7 +19,6 @@ RSpec.describe 'cross-database foreign keys' do ...@@ -19,7 +19,6 @@ RSpec.describe 'cross-database foreign keys' do
ci_freeze_periods.project_id ci_freeze_periods.project_id
ci_job_artifacts.project_id ci_job_artifacts.project_id
ci_job_token_project_scope_links.added_by_id ci_job_token_project_scope_links.added_by_id
ci_job_token_project_scope_links.source_project_id
ci_job_token_project_scope_links.target_project_id ci_job_token_project_scope_links.target_project_id
ci_pending_builds.namespace_id ci_pending_builds.namespace_id
ci_pending_builds.project_id ci_pending_builds.project_id
......
...@@ -88,4 +88,11 @@ RSpec.describe Ci::JobToken::ProjectScopeLink do ...@@ -88,4 +88,11 @@ RSpec.describe Ci::JobToken::ProjectScopeLink do
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
end end
context 'loose foreign key on ci_job_token_project_scope_links.source_project_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:project) }
let!(:model) { create(:ci_job_token_project_scope_link, source_project: parent) }
end
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