summaryrefslogtreecommitdiff
path: root/db/migrate/20190104182041_cleanup_legacy_artifact_migration.rb
blob: 11659846a06306606547502f552e98edff021a04 (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
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

class CleanupLegacyArtifactMigration < ActiveRecord::Migration[5.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  class Build < ActiveRecord::Base
    include EachBatch

    self.table_name = 'ci_builds'
    self.inheritance_column = :_type_disabled

    scope :with_legacy_artifacts, -> { where("artifacts_file <> ''") }
  end

  def up
    Gitlab::BackgroundMigration.steal('MigrateLegacyArtifacts')

    CleanupLegacyArtifactMigration::Build
      .with_legacy_artifacts
      .each_batch(of: 100) do |batch|
      range = batch.pluck('MIN(id)', 'MAX(id)').first

      Gitlab::BackgroundMigration::MigrateLegacyArtifacts.new.perform(*range)
    end
  end

  def down
    # no-op
  end
end