diff options
-rw-r--r-- | lib/gitlab/database/migration_helpers.rb | 18 | ||||
-rw-r--r-- | spec/lib/gitlab/database/migration_helpers_spec.rb | 10 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 298b1a1f4e6..73d2bc2a66c 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -278,6 +278,22 @@ module Gitlab raise 'rename_column_concurrently can not be run inside a transaction' end +<<<<<<< HEAD +======= + old_col = column_for(table, old) + new_type = type || old_col.type + + add_column(table, new, new_type, + limit: old_col.limit, + precision: old_col.precision, + scale: old_col.scale) + + # We set the default value _after_ adding the column so we don't end up + # updating any existing data with the default value. This isn't + # necessary since we copy over old values further down. + change_column_default(table, new, old_col.default) if old_col.default + +>>>>>>> c53d06c4d8... Merge branch 'dm-rename-column-concurrently-with-null' into 'master'
trigger_name = rename_trigger_name(table, old, new) quoted_table = quote_table_name(table) quoted_old = quote_column_name(old) @@ -303,6 +319,8 @@ module Gitlab update_column_in_batches(table, new, Arel::Table.new(table)[old]) + change_column_null(table, new, false) unless old_col.null + copy_indexes(table, old, new) copy_foreign_keys(table, old, new) end diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index 737fac14f92..942635d3dae 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -382,13 +382,18 @@ describe Gitlab::Database::MigrationHelpers, lib: true do expect(model).to receive(:add_column). with(:users, :new, :integer, limit: old_column.limit, +<<<<<<< HEAD default: old_column.default, null: old_column.null, +======= +>>>>>>> c53d06c4d8... Merge branch 'dm-rename-column-concurrently-with-null' into 'master'
precision: old_column.precision, scale: old_column.scale) expect(model).to receive(:update_column_in_batches) + expect(model).to receive(:change_column_null).with(:users, :new, false) + expect(model).to receive(:copy_indexes).with(:users, :old, :new) expect(model).to receive(:copy_foreign_keys).with(:users, :old, :new) @@ -406,13 +411,18 @@ describe Gitlab::Database::MigrationHelpers, lib: true do expect(model).to receive(:add_column). with(:users, :new, :integer, limit: old_column.limit, +<<<<<<< HEAD default: old_column.default, null: old_column.null, +======= +>>>>>>> c53d06c4d8... Merge branch 'dm-rename-column-concurrently-with-null' into 'master'
precision: old_column.precision, scale: old_column.scale) expect(model).to receive(:update_column_in_batches) + expect(model).to receive(:change_column_null).with(:users, :new, false) + expect(model).to receive(:copy_indexes).with(:users, :old, :new) expect(model).to receive(:copy_foreign_keys).with(:users, :old, :new) |