Establish BBM dependencies from migrations
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:
- Existing migration generators are updated to introduce
DEPENDENT_BATCHED_BACKGROUND_MIGRATIONS
constant to hold the queued migration versions of the dependent BBMs. -
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.
- Uses
How to set up and validate locally
-
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
-
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 addqueued_migration_version
from MyBatchedMigration's dictionary file (db/docs/batched_background_migrations/my_batched_migration.yml)
- Uncomment
-
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] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
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.
- Having a version greater than
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Closes #424887 (closed) and #424884 (closed)