# frozen_string_literal: true

# See https://docs.gitlab.com/ee/development/database/batched_background_migrations.html
# for more information on when/how to queue batched background migrations

# Update below commented lines with appropriate values.

class QueueMyBatchedMigration < Gitlab::Database::Migration[2.2]
  milestone '16.6'

  # Select the applicable gitlab schema for your batched background migration
  restrict_gitlab_migration # gitlab_schema: :gitlab_main / :gitlab_ci / :gitlab_main_clusterwide / ...

  MIGRATION = "MyBatchedMigration"
  # DELAY_INTERVAL = 2.minutes
  # BATCH_SIZE = 1000
  # SUB_BATCH_SIZE = 100

  def up
    # If you are requeueing an already executed migration, you need to delete the prior batched migration record
    # for the new enqueue to be executed, else, you can delete this line.
    # delete_batched_background_migration(MIGRATION, :projects, :id, [])

    queue_batched_background_migration(
      MIGRATION,
      :projects,
      :id,
      job_interval: DELAY_INTERVAL,
      batch_size: BATCH_SIZE,
      sub_batch_size: SUB_BATCH_SIZE
    )
  end

  def down
    delete_batched_background_migration(MIGRATION, :projects, :id, [])
  end
end
