summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-05-15 07:50:44 +0000
committerRémy Coutable <remy@rymai.me>2017-05-15 07:50:44 +0000
commitae8511df1312d85745baddec0b54401b36d46126 (patch)
treed0842a622e761e3273b09b81add2a0a883afac9c
parentba5009def3199f95729f7d90c5349103731cb059 (diff)
parent3fc20c01170ebb6648ff9dbe76b0d52d0c13d68d (diff)
downloadgitlab-ce-ae8511df1312d85745baddec0b54401b36d46126.tar.gz
Merge branch 'rename-column-concurrently-defaults' into 'master'
Fix adding defaults for concurrent column renames See merge request !11335
-rw-r--r--lib/gitlab/database/migration_helpers.rb6
-rw-r--r--spec/lib/gitlab/database/migration_helpers_spec.rb8
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index f04a907004c..f3476dadec8 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -283,11 +283,15 @@ module Gitlab
add_column(table, new, new_type,
limit: old_col.limit,
- default: old_col.default,
null: old_col.null,
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
+
trigger_name = rename_trigger_name(table, old, new)
quoted_table = quote_table_name(table)
quoted_old = quote_column_name(old)
diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb
index 737fac14f92..d6535f97665 100644
--- a/spec/lib/gitlab/database/migration_helpers_spec.rb
+++ b/spec/lib/gitlab/database/migration_helpers_spec.rb
@@ -382,11 +382,13 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
expect(model).to receive(:add_column).
with(:users, :new, :integer,
limit: old_column.limit,
- default: old_column.default,
null: old_column.null,
precision: old_column.precision,
scale: old_column.scale)
+ expect(model).to receive(:change_column_default).
+ with(:users, :new, old_column.default)
+
expect(model).to receive(:update_column_in_batches)
expect(model).to receive(:copy_indexes).with(:users, :old, :new)
@@ -406,11 +408,13 @@ describe Gitlab::Database::MigrationHelpers, lib: true do
expect(model).to receive(:add_column).
with(:users, :new, :integer,
limit: old_column.limit,
- default: old_column.default,
null: old_column.null,
precision: old_column.precision,
scale: old_column.scale)
+ expect(model).to receive(:change_column_default).
+ with(:users, :new, old_column.default)
+
expect(model).to receive(:update_column_in_batches)
expect(model).to receive(:copy_indexes).with(:users, :old, :new)