summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220426185933_backfill_deployments_finished_at.rb
blob: 860756de29832b542d085e0cfdf8e5e691a95153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

class BackfillDeploymentsFinishedAt < Gitlab::Database::Migration[2.0]
  DEPLOYMENT_STATUS_SUCCESS = 2 # Equivalent to Deployment.statuses[:success]

  restrict_gitlab_migration gitlab_schema: :gitlab_main

  BATCH_SIZE = 100

  def up
    define_batchable_model('deployments')
      .where(finished_at: nil)
      .where(status: DEPLOYMENT_STATUS_SUCCESS)
      .each_batch(of: BATCH_SIZE) { |relation| relation.update_all('finished_at = created_at') }
  end

  def down
    # no-op
  end
end