Swap FK vulnerability_statistics to ci_pipelines for LFK

Swaps FK for vulnerability_statistics.latest_pipeline_id to ci_pipelines

Changelog: changed
parent 55a4cc5a
# frozen_string_literal: true
class RemoveCiPipelinesVulnerabilityStatisticsLatestPipelineIdFk < Gitlab::Database::Migration[1.0]
disable_ddl_transaction!
def up
with_lock_retries do
execute('LOCK ci_pipelines, vulnerability_statistics IN ACCESS EXCLUSIVE MODE')
remove_foreign_key_if_exists(:vulnerability_statistics, :ci_pipelines, name: "fk_e8b13c928f")
end
end
def down
add_concurrent_foreign_key(:vulnerability_statistics, :ci_pipelines, name: "fk_e8b13c928f", column: :latest_pipeline_id, target_column: :id, on_delete: :nullify)
end
end
62b35cc5bd0abc5b7bcf4347346de832bbbed723fee7860ec649185d4d5fb53c
\ No newline at end of file
...@@ -29926,9 +29926,6 @@ ALTER TABLE ONLY sprints ...@@ -29926,9 +29926,6 @@ ALTER TABLE ONLY sprints
ALTER TABLE ONLY application_settings ALTER TABLE ONLY application_settings
ADD CONSTRAINT fk_e8a145f3a7 FOREIGN KEY (instance_administrators_group_id) REFERENCES namespaces(id) ON DELETE SET NULL; ADD CONSTRAINT fk_e8a145f3a7 FOREIGN KEY (instance_administrators_group_id) REFERENCES namespaces(id) ON DELETE SET NULL;
ALTER TABLE ONLY vulnerability_statistics
ADD CONSTRAINT fk_e8b13c928f FOREIGN KEY (latest_pipeline_id) REFERENCES ci_pipelines(id) ON DELETE SET NULL;
ALTER TABLE ONLY integrations ALTER TABLE ONLY integrations
ADD CONSTRAINT fk_e8fe908a34 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE; ADD CONSTRAINT fk_e8fe908a34 FOREIGN KEY (group_id) REFERENCES namespaces(id) ON DELETE CASCADE;
...@@ -118,4 +118,11 @@ RSpec.describe Vulnerabilities::Statistic do ...@@ -118,4 +118,11 @@ RSpec.describe Vulnerabilities::Statistic do
end end
end end
end end
context 'loose foreign key on vulnerability_statistics.latest_pipeline_id' do
it_behaves_like 'cleanup by a loose foreign key' do
let!(:parent) { create(:ci_pipeline) }
let!(:model) { create(:vulnerability_statistic, pipeline: parent) }
end
end
end end
...@@ -44,7 +44,6 @@ RSpec.describe 'cross-database foreign keys' do ...@@ -44,7 +44,6 @@ RSpec.describe 'cross-database foreign keys' do
dast_site_profiles_pipelines.ci_pipeline_id dast_site_profiles_pipelines.ci_pipeline_id
external_pull_requests.project_id external_pull_requests.project_id
vulnerability_feedback.pipeline_id vulnerability_feedback.pipeline_id
vulnerability_statistics.latest_pipeline_id
).freeze ).freeze
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