summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-05-15 22:06:52 +0000
committerkushalpandya <kushal@gitlab.com>2017-05-22 13:55:38 +0530
commit2f097402599dc8c734759e1bef3ec2c4534f594d (patch)
tree0f880d2c744d16d5447fc52e41b855c4f244bf15
parentadd9abadbdfac7e4c03b06b47d3afc296e00ac97 (diff)
downloadgitlab-ce-2f097402599dc8c734759e1bef3ec2c4534f594d.tar.gz
[ci skip] Conflicts while picking !11396 into 9-2-stable
-rw-r--r--lib/gitlab/database/migration_helpers.rb18
-rw-r--r--spec/lib/gitlab/database/migration_helpers_spec.rb10
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)