diff options
author | Rémy Coutable <remy@rymai.me> | 2016-09-14 15:04:25 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-09-14 15:04:25 +0000 |
commit | 1c05302b3c3b1cff435d3c8617e219ccc8373606 (patch) | |
tree | ce2c013f549fd0b9ab73719a59b66b48b03c28f3 | |
parent | 11a26ab145856e9a9f0d2ccbeda99a0a969436eb (diff) | |
parent | fd4ad6546278aef904f02dffe106b41872a9068c (diff) | |
download | gitlab-ce-1c05302b3c3b1cff435d3c8617e219ccc8373606.tar.gz |
Merge branch 'fix-remove-merge-request-diff-unique-index' into 'master'
This MR fixes the migration that removes the unique index/constraint from `merge_request_diffs.merge_request_id`
See merge request !6346
-rw-r--r-- | db/migrate/20160725104020_merge_request_diff_remove_uniq.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/db/migrate/20160725104020_merge_request_diff_remove_uniq.rb b/db/migrate/20160725104020_merge_request_diff_remove_uniq.rb index c8cbd2718ff..75a3eb15124 100644 --- a/db/migrate/20160725104020_merge_request_diff_remove_uniq.rb +++ b/db/migrate/20160725104020_merge_request_diff_remove_uniq.rb @@ -8,14 +8,28 @@ class MergeRequestDiffRemoveUniq < ActiveRecord::Migration DOWNTIME = false def up - if index_exists?(:merge_request_diffs, :merge_request_id) - remove_index :merge_request_diffs, :merge_request_id + constraint_name = 'merge_request_diffs_merge_request_id_key' + + transaction do + if index_exists?(:merge_request_diffs, :merge_request_id) + remove_index(:merge_request_diffs, :merge_request_id) + end + + # In some bizarre cases PostgreSQL might have a separate unique constraint + # that we'll need to drop. + if constraint_exists?(constraint_name) && Gitlab::Database.postgresql? + execute("ALTER TABLE merge_request_diffs DROP CONSTRAINT IF EXISTS #{constraint_name};") + end end end def down unless index_exists?(:merge_request_diffs, :merge_request_id) - add_concurrent_index :merge_request_diffs, :merge_request_id, unique: true + add_concurrent_index(:merge_request_diffs, :merge_request_id, unique: true) end end + + def constraint_exists?(name) + indexes(:merge_request_diffs).map(&:name).include?(name) + end end |