Skip to content

Ensure the presence of required attrs in BBM dict

What does this MR do and why?

We need to make few attrs mandatory to support BBM dependencies framework. Eg: Run a cron to create a new issue after 'finaliz... (#424886) requires introduced_by_url, finalize_after values to be present.

Highlights:

  • Renamed existing BackgroundMigration/MissingDictionaryFile cop to BackgroundMigration/DictionaryFile, to support missing keys offense too.
  • Added the grace period to avoid any failures in the default branch pipelines.
  • Included enforcedSince to not include existing migrations without required keys.

How to set up and validate locally

  1. Enqueue a new batched background migration (my_batched_migration).

    bundle exec rails g batched_background_migration my_batched_migration --table_name=projects --column_name=id --feature_category=database
  2. With default values in the dictionary (empty introduced_by_url and finalize_after keys), it should throw an offense

    bundle exec rubocop --cache false db/post_migrate/20231020150948_queue_my_batched_migration.rb
    
    db/post_migrate/20231020150948_queue_my_batched_migration.rb:8:1: C: BackgroundMigration/DictionaryFile: Mandatory key 'finalize_after' is missing from the dictionary. Please add with an appropriate value.
    class QueueMyBatchedMigration < Gitlab::Database::Migration[2.1] ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  3. Add a value for finalize_after in db/docs/batched_background_migrations/my_batched_migration.yml, should still throw an offense for missing introduced_by_url.

    bundle exec rubocop --cache false db/post_migrate/20231020150948_queue_my_batched_migration.rb
    Inspecting 1 file
    C
    
    Offenses:
    
    db/post_migrate/20231020150948_queue_my_batched_migration.rb:8:1: C: BackgroundMigration/DictionaryFile: Mandatory key 'introduced_by_url' is missing from the dictionary. Please add with an appropriate value.
    class QueueMyBatchedMigration < Gitlab::Database::Migration[2.1] ...
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    1 file inspected, 1 offense detected
  4. Add a value for introduced_by_url too, now it shouldn't throw any offense.

    bundle exec rubocop --cache false db/post_migrate/20231020150948_queue_my_batched_migration.rb
    Inspecting 1 file
    .
    
    1 file inspected, no offenses detected

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 #424883 (closed)

Edited by Prabakaran Murugesan

Merge request reports