From 9629bb962cd3666ac58cfbaba9d79df011221f41 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Mon, 3 Oct 2016 18:43:39 -0300 Subject: Add column type to labels and do the batch update in the same migration --- db/migrate/20160919144305_add_type_to_labels.rb | 7 ++++++- .../20160920191518_set_project_label_type_on_labels.rb | 17 ----------------- 2 files changed, 6 insertions(+), 18 deletions(-) delete mode 100644 db/migrate/20160920191518_set_project_label_type_on_labels.rb diff --git a/db/migrate/20160919144305_add_type_to_labels.rb b/db/migrate/20160919144305_add_type_to_labels.rb index 43aac7846d3..66172bda6ff 100644 --- a/db/migrate/20160919144305_add_type_to_labels.rb +++ b/db/migrate/20160919144305_add_type_to_labels.rb @@ -1,9 +1,14 @@ class AddTypeToLabels < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers - DOWNTIME = false + DOWNTIME = true + DOWNTIME_REASON = 'Labels will not work as expected until this migration is complete.' def change 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 diff --git a/db/migrate/20160920191518_set_project_label_type_on_labels.rb b/db/migrate/20160920191518_set_project_label_type_on_labels.rb deleted file mode 100644 index af47d0320e2..00000000000 --- a/db/migrate/20160920191518_set_project_label_type_on_labels.rb +++ /dev/null @@ -1,17 +0,0 @@ -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 -- cgit v1.2.1