summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-08-24 04:20:30 +0000
committerStan Hu <stanhu@gmail.com>2019-08-24 04:20:30 +0000
commit892e4c0da818006159cc26bc79f1fa48b76c9b3f (patch)
tree0dfdd80e560413c38223bd3e8847e3da8a28d16a
parent523c619fe41191e32c852dae972958302364c3ca (diff)
parent599cc49973d540b59316dcdd8de157a9ca24b814 (diff)
downloadgitlab-ce-892e4c0da818006159cc26bc79f1fa48b76c9b3f.tar.gz
Merge branch 'fix-migration' into 'master'
Delete rename trigger before creating to prevent error See merge request gitlab-org/gitlab-ce!32147
-rw-r--r--lib/gitlab/database/migration_helpers.rb5
-rw-r--r--spec/lib/gitlab/database/migration_helpers_spec.rb8
2 files changed, 13 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}
diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb
index 2731fc8573f..fe44b09aa24 100644
--- a/spec/lib/gitlab/database/migration_helpers_spec.rb
+++ b/spec/lib/gitlab/database/migration_helpers_spec.rb
@@ -619,10 +619,18 @@ describe Gitlab::Database::MigrationHelpers do
.with(/CREATE OR REPLACE FUNCTION foo()/m)
expect(model).to receive(:execute)
+ .with(/DROP TRIGGER IF EXISTS foo/m)
+
+ expect(model).to receive(:execute)
.with(/CREATE TRIGGER foo/m)
model.install_rename_triggers_for_postgresql('foo', :users, :old, :new)
end
+
+ it 'does not fail if trigger already exists' do
+ model.install_rename_triggers_for_postgresql('foo', :users, :old, :new)
+ model.install_rename_triggers_for_postgresql('foo', :users, :old, :new)
+ end
end
describe '#remove_rename_triggers_for_postgresql' do