summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorReuben Pereira <rpereira@gitlab.com>2019-08-24 04:20:29 +0000
committerStan Hu <stanhu@gmail.com>2019-08-24 04:20:29 +0000
commit599cc49973d540b59316dcdd8de157a9ca24b814 (patch)
tree0dfdd80e560413c38223bd3e8847e3da8a28d16a /lib
parent523c619fe41191e32c852dae972958302364c3ca (diff)
downloadgitlab-ce-599cc49973d540b59316dcdd8de157a9ca24b814.tar.gz
Drop existing trigger before creating new one
- When renaming a column concurrently, drop any existing trigger before attempting to create a new one. When running migration specs multiple times (as it happens during local development), the down method of previous migrations are called. If any of the called methods contains a call to rename_column_concurrently, a trigger will be created and not removed. So, the next time a migration spec is run, if the same down method is executed again, it will cause an error when attempting to create the trigger (since it already exists). Dropping the trigger if it already exists will prevent this problem.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/database/migration_helpers.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index 9bba4f6ce1e..8bc45f6e78c 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -747,6 +747,11 @@ module Gitlab
EOF
execute <<-EOF.strip_heredoc
+ DROP TRIGGER IF EXISTS #{trigger}
+ ON #{table}
+ EOF
+
+ execute <<-EOF.strip_heredoc
CREATE TRIGGER #{trigger}
BEFORE INSERT OR UPDATE
ON #{table}