Add column type to labels and do the batch update in the same migration

parent 7e11ca86
class AddTypeToLabels < ActiveRecord::Migration class AddTypeToLabels < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
DOWNTIME = false DOWNTIME = true
DOWNTIME_REASON = 'Labels will not work as expected until this migration is complete.'
def change def change
add_column :labels, :type, :string add_column :labels, :type, :string
update_column_in_batches(:labels, :type, 'ProjectLabel') do |table, query|
query.where(table[:project_id].not_eq(nil))
end
end end
end end
class SetProjectLabelTypeOnLabels < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def up
update_column_in_batches(:labels, :type, 'ProjectLabel') do |table, query|
query.where(table[:project_id].not_eq(nil))
end
end
def down
update_column_in_batches(:labels, :type, nil) do |table, query|
query.where(table[:project_id].not_eq(nil))
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment