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

class BackfillReleaseNameWithTag < ActiveRecord::Migration[5.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    subquery = Arel.sql("select id from projects where visibility_level = #{Gitlab::VisibilityLevel::PUBLIC}")

    update_column_in_batches(:releases, :name, Release.arel_table[:tag]) do |table, query|
      query.where(table[:name].eq(nil)).where(table[:project_id].in(subquery))
    end
  end

  def down
    # noop
  end
end