summaryrefslogtreecommitdiff
path: root/db/post_migrate/20220128155251_remove_dangling_running_builds.rb
blob: f86a21ced008b20dc20849b12ccff28dc7e1ee44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

class RemoveDanglingRunningBuilds < Gitlab::Database::Migration[1.0]
  BATCH_SIZE = 100

  disable_ddl_transaction!

  def up
    each_batch_range('ci_running_builds', of: BATCH_SIZE) do |min, max|
      execute <<~SQL
        DELETE FROM ci_running_builds
          USING ci_builds
          WHERE ci_builds.id = ci_running_builds.build_id
            AND ci_builds.status = 'failed'
            AND ci_builds.type = 'Ci::Build'
            AND ci_running_builds.id BETWEEN #{min} AND #{max}
      SQL
    end
  end

  def down
    # no-op
    # This migration deletes data and it can not be reversed
  end
end