Skip to content

Establish BBM dependencies from migrations

Prabakaran Murugesan requested to merge 424887-establish-bbm-dependencies into master

What does this MR do and why?

Uses the unique identifier 'batched_background_migration.queued_migration_version' introduced by #424881 (closed) to establish dependencies between migrations and already enqueued batched background migrations.

More info can be found in: &11432 and #416689 (comment 1532615791).

Changes done in this MR:

  1. Existing migration generators are updated to introduce DEPENDENT_BATCHED_BACKGROUND_MIGRATIONS constant to hold the queued migration versions of the dependent BBMs.
  2. RuboCop::Cop::Migration::UnfinishedDependencies cop has been introduced to check if there are any dependent BBM which are yet to be finalized or finalized by migrations after the current migration.
    • Uses finalized_by attr of BBM dictionary file to achieve this.

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. Create a migration, which depends on the completion of our my_batched_migration BBM.

    bundle exec rails g post_deployment_migration dependents_on_my_batched_migration 
    • Uncomment DEPENDENT_BATCHED_BACKGROUND_MIGRATIONS constant and add queued_migration_version from MyBatchedMigration's dictionary file (db/docs/batched_background_migrations/my_batched_migration.yml)
  3. Since my_batched_migration is not yet finalized, we should be seeing a cop offense.

    bundle exec rubocop db/post_migrate/20231009135858_dependents_on_my_batched_migration.rb
    
    Inspecting 1 file
    C
    
    Offenses:
    
    db/post_migrate/20231009135858_dependents_on_my_batched_migration.rb:24:3: C: Migration/UnfinishedDependencies: Dependent migration with queued version 20231009135709 is not yet finalized. Consider finalizing the dependent migration and update it's finalized_by atr in the dictionary.
      DEPENDENT_BATCHED_BACKGROUND_MIGRATIONS = [20231009135709]
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  4. Add a finalized_by version to my_batched_migration.yml dictionary to indicate that the BBM has been finalized.

    • Having a version greater than dependents_on_my_batched_migration migration (from step (2)) will throw another rubocop offense.
    • Having a version less than dependents_on_my_batched_migration migration will not throw any offense.

MR acceptance checklist

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

Closes #424887 (closed) and #424884 (closed)

Edited by Prabakaran Murugesan

Merge request reports

Loading