Commit 0e7cb428 authored by Patrick Bair's avatar Patrick Bair

Merge branch '348273-remove-artifacts-archive-id-foreign-key' into 'master'

Remove foreign key constraint on `project_pages_metadata.ci_job_artifacts` to use loose foreign key

See merge request gitlab-org/gitlab!76996
parents 80185995 d2c9fe10
# frozen_string_literal: true
class RemoveArtifactsArchiveIdForeignKeyFromProjectPagesMetadata < Gitlab::Database::Migration[1.0]
CONSTRAINT_NAME = 'fk_69366a119e'
disable_ddl_transaction!
def up
with_lock_retries do
execute('lock table ci_job_artifacts, project_pages_metadata in access exclusive mode')
remove_foreign_key :project_pages_metadata, to_table: :ci_job_artifacts, column: :artifacts_archive_id, on_delete: :nullify, name: CONSTRAINT_NAME
end
end
def down
add_concurrent_foreign_key :project_pages_metadata, :ci_job_artifacts, column: :artifacts_archive_id, on_delete: :nullify, name: CONSTRAINT_NAME
end
end
fe5cbf928d45d506132078678cf70264f01190cfe581628a5038d77f68a52961
\ No newline at end of file
......@@ -29263,9 +29263,6 @@ ALTER TABLE ONLY merge_requests
ALTER TABLE ONLY ci_builds
ADD CONSTRAINT fk_6661f4f0e8 FOREIGN KEY (resource_group_id) REFERENCES ci_resource_groups(id) ON DELETE SET NULL;
ALTER TABLE ONLY project_pages_metadata
ADD CONSTRAINT fk_69366a119e FOREIGN KEY (artifacts_archive_id) REFERENCES ci_job_artifacts(id) ON DELETE SET NULL;
ALTER TABLE ONLY application_settings
ADD CONSTRAINT fk_693b8795e4 FOREIGN KEY (push_rule_id) REFERENCES push_rules(id) ON DELETE SET NULL;
......@@ -18,4 +18,15 @@ RSpec.describe ProjectPagesMetadatum do
expect(described_class.only_on_legacy_storage).to eq([legacy_storage_project.pages_metadatum])
end
end
it_behaves_like 'cleanup by a loose foreign key' do
let!(:model) do
artifacts_archive = create(:ci_job_artifact, :legacy_archive)
metadatum = artifacts_archive.project.pages_metadatum
metadatum.artifacts_archive = artifacts_archive
metadatum
end
let!(:parent) { model.artifacts_archive }
end
end
......@@ -55,7 +55,8 @@ RSpec.shared_examples 'cleanup by a loose foreign key' do
end
def find_model
model.class.find_by(id: model.id)
primary_key = model.class.primary_key.to_sym
model.class.find_by(primary_key => model.public_send(primary_key))
end
it 'deletes the model' do
......
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