Merge branch 'zj-drop-fk-if-exists' into 'master'

Only remove FK if it exists

See merge request !11828
This commit is contained in:
Yorick Peterse 2017-06-01 10:57:42 +00:00
commit 358662a9f7
2 changed files with 15 additions and 1 deletions

View file

@ -0,0 +1,4 @@
---
title: Remove foreigh key on ci_trigger_schedules only if it exists
merge_request:
author:

View file

@ -4,10 +4,20 @@ class RemoveForeighKeyCiTriggerSchedules < ActiveRecord::Migration
DOWNTIME = false
def up
remove_foreign_key :ci_trigger_schedules, column: :trigger_id
if fk_on_trigger_schedules?
remove_foreign_key :ci_trigger_schedules, column: :trigger_id
end
end
def down
# no op, the foreign key should not have been here
end
private
# Not made more generic and lifted to the helpers as Rails 5 will provide
# such an API
def fk_on_trigger_schedules?
connection.foreign_keys(:ci_trigger_schedules).include?("ci_triggers")
end
end