Merge branch 'zj-drop-fk-if-exists' into 'master'
Only remove FK if it exists See merge request !11828
This commit is contained in:
commit
358662a9f7
2 changed files with 15 additions and 1 deletions
4
changelogs/unreleased/zj-drop-fk-if-exists.yml
Normal file
4
changelogs/unreleased/zj-drop-fk-if-exists.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: Remove foreigh key on ci_trigger_schedules only if it exists
|
||||
merge_request:
|
||||
author:
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue