Skip to content

Avoid name collision between migrations

What does this MR do and why?

Adds a pre-push hook to check name clashing between db migrations and Elasticsearch migrations.

How to set up and validate locally

Method 1

  1. Pick a migration in db/migrate, like db/migrate/20220421114418_make_fingerprint_nullable_for_group_deploy_key.rb
  2. Change the class name to some class that it's already present in ee/elastic/migrate, like AddUpvotesMappingsToMergeRequests.
  3. run ./scripts/validate_name_collisions_between_migrations
  4. Should get the following output:
Error: Naming collisions were found between migrations

AddUpvotesMappingsToMergeRequests: /Users/leonardodarosa/gdk/gitlab/db/migrate/20220421114418_make_fingerprint_nullable_for_group_deploy_key.rb, /Users/leonardodarosa/gdk/gitlab/ee/elastic/migrate/20210722112500_add_upvotes_mappings_to_merge_requests.rb

Method 2

  1. Pick a migration in db/migrate, like db/migrate/20220421114418_make_fingerprint_nullable_for_group_deploy_key.rb
  2. Change the class name to some class that it's already present in ee/elastic/migrate, like AddUpvotesMappingsToMergeRequests.
  3. Commit
  4. Push
Lefthook v1.4.7
RUNNING HOOK: pre-commit
...
RUNNING HOOK: pre-push
...
EXECUTE > db-migration-name-collisions
Error: Naming collisions were found between migrations
AddUpvotesMappingsToMergeRequests: /Users/leonardodarosa/gdk/gitlab/db/migrate/20220421114418_make_fingerprint_nullable_for_group_deploy_key.rb, /Users/leonardodarosa/gdk/gitlab/ee/elastic/migrate/20210722112500_add_upvotes_mappings_to_merge_requests.rb

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #419193 (closed)

Edited by Peter Leitzen

Merge request reports

Loading