Skip to content

Improve batched background migration generator

What does this MR do and why?

This MR improves our batched background migration generator to be more user-friendly and support EE-only migrations

Before

bin/rails g batched_background_migration
Usage:
  rails generate batched_background_migration:batched_background_migration NAME [options]

Options:
  [--skip-namespace], [--no-skip-namespace]              # Skip namespace (affects only isolated engines)
  [--skip-collision-check], [--no-skip-collision-check]  # Skip collision check
  [--table-name=TABLE_NAME]                              # Indicates when to generate table name
  [--column-name=COLUMN_NAME]                            # Indicates when to generate column name
  [--feature-category=FEATURE_CATEGORY]                  # Indicates when to generate feature category

Runtime options:
  -f, [--force]                    # Overwrite files that already exist
  -p, [--pretend], [--no-pretend]  # Run but do not make any changes
  -q, [--quiet], [--no-quiet]      # Suppress status output
  -s, [--skip], [--no-skip]        # Skip files that already exist

Description:
    Generates files required for batched background migration.

Example:
    rails g batched_background_migration my_batched_migration --table_name=users --column_name=id --feature_category=gitaly

    This will create:
        db/post_migrate/20230213215230_queue_my_batched_migration.rb
        spec/migrations/20230213215230_queue_my_batched_migration_spec.rb
        lib/gitlab/background_migration/my_batched_migration.rb
        spec/lib/gitlab/background_migration/my_batched_migration_spec.rb
        db/docs/batched_background_migrations/my_batched_migration.yml

After

$ bin/rails g batched_background_migration
Usage:
  rails generate batched_background_migration:batched_background_migration NAME [options]

Options:
  [--skip-namespace], [--no-skip-namespace]              # Skip namespace (affects only isolated engines)
  [--skip-collision-check], [--no-skip-collision-check]  # Skip collision check
  --table-name=TABLE_NAME                                # Table from which records we will be batching
  --column-name=COLUMN_NAME                              # Column to use for batching
                                                         # Default: id
  --feature-category=FEATURE_CATEGORY                    # Feature category to which this batched background migration belongs to
  [--ee-only], [--no-ee-only]                            # Generate files for EE-only batched background migration

Runtime options:
  -f, [--force]                    # Overwrite files that already exist
  -p, [--pretend], [--no-pretend]  # Run but do not make any changes
  -q, [--quiet], [--no-quiet]      # Suppress status output
  -s, [--skip], [--no-skip]        # Skip files that already exist

Description:
    Generates files required for batched background migration.

Example:
    rails g batched_background_migration my_batched_migration --table_name=users --column_name=id --feature_category=gitaly

    This will create:
        db/post_migrate/20230213215230_queue_my_batched_migration.rb
        spec/migrations/20230213215230_queue_my_batched_migration_spec.rb
        lib/gitlab/background_migration/my_batched_migration.rb
        spec/lib/gitlab/background_migration/my_batched_migration_spec.rb
        db/docs/batched_background_migrations/my_batched_migration.yml

Generating an EE-only batched background migration

bin/rails g batched_background_migration mysupereeonlymigration --ee-only --table_name=users --column_name=id --feature_category=gitaly
      create  db/post_migrate/20230613215917_queue_mysupereeonlymigration.rb
      create  spec/migrations/20230613215917_queue_mysupereeonlymigration_spec.rb
      create  ee/lib/ee/gitlab/background_migration/mysupereeonlymigration.rb
      create  lib/gitlab/background_migration/mysupereeonlymigration.rb
      create  ee/spec/lib/ee/gitlab/background_migration/mysupereeonlymigration_spec.rb
      create  db/docs/batched_background_migrations/mysupereeonlymigration.yml

Further work

I am not sure why but the file under spec/migrations/<timestamp>_queue_<migration_name>_spec.rb doesn't get removed when you call bin/rails d batched_background_migration

MR acceptance checklist

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

Edited by Michał Zając

Merge request reports

Loading