Commit ca619a5c authored by Patrick Bair's avatar Patrick Bair

Merge branch 'ab/remove-inconsistent-fk' into 'master'

Remove unexpected FK prior to swapping columns

See merge request gitlab-org/gitlab!71311
parents 3978b5f9 f020d8e8
...@@ -103,6 +103,11 @@ class FinalizeCiBuildsBigintConversion < Gitlab::Database::Migration[1.0] ...@@ -103,6 +103,11 @@ class FinalizeCiBuildsBigintConversion < Gitlab::Database::Migration[1.0]
remove_foreign_key(:ci_resources, TABLE_NAME, column: :build_id, name: 'fk_rails_e169a8e3d5') remove_foreign_key(:ci_resources, TABLE_NAME, column: :build_id, name: 'fk_rails_e169a8e3d5')
end end
# Remove this unexpected FK if it exists - https://gitlab.com/gitlab-org/gitlab/-/issues/341822
if foreign_key_exists?(:ci_sources_pipelines, TABLE_NAME, column: :source_job_id, name: 'fk_3f0c88d7dc')
remove_foreign_key(:ci_sources_pipelines, TABLE_NAME, column: :source_job_id, name: 'fk_3f0c88d7dc')
end
swap_columns swap_columns
end end
......
# frozen_string_literal: true
require 'spec_helper'
require_migration!('finalize_ci_builds_bigint_conversion')
RSpec.describe FinalizeCiBuildsBigintConversion, :migration, schema: 20210907182359 do
context 'with an unexpected FK fk_3f0c88d7dc' do
it 'removes the FK and migrates successfully' do
# Add the unexpected FK
subject.add_foreign_key(:ci_sources_pipelines, :ci_builds, column: :source_job_id, name: 'fk_3f0c88d7dc')
expect { migrate! }.to change { subject.foreign_key_exists?(:ci_sources_pipelines, :ci_builds, column: :source_job_id, name: 'fk_3f0c88d7dc') }.from(true).to(false)
# Additional check: The actually expected FK should still exist
expect(subject.foreign_key_exists?(:ci_sources_pipelines, :ci_builds, column: :source_job_id, name: 'fk_be5624bf37')).to be_truthy
end
end
end
...@@ -63,6 +63,7 @@ ...@@ -63,6 +63,7 @@
- "./spec/lib/api/entities/package_spec.rb" - "./spec/lib/api/entities/package_spec.rb"
- "./spec/lib/gitlab/background_migration/migrate_legacy_artifacts_spec.rb" - "./spec/lib/gitlab/background_migration/migrate_legacy_artifacts_spec.rb"
- "./spec/mailers/emails/pipelines_spec.rb" - "./spec/mailers/emails/pipelines_spec.rb"
- "./spec/migrations/20210907211557_finalize_ci_builds_bigint_conversion_spec.rb"
- "./spec/migrations/cleanup_legacy_artifact_migration_spec.rb" - "./spec/migrations/cleanup_legacy_artifact_migration_spec.rb"
- "./spec/migrations/migrate_protected_attribute_to_pending_builds_spec.rb" - "./spec/migrations/migrate_protected_attribute_to_pending_builds_spec.rb"
- "./spec/migrations/re_schedule_latest_pipeline_id_population_with_all_security_related_artifact_types_spec.rb" - "./spec/migrations/re_schedule_latest_pipeline_id_population_with_all_security_related_artifact_types_spec.rb"
......
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