diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-06-01 13:57:42 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-06-01 13:57:42 +0300 |
commit | 358662a9f7474b41755ec0128efaaa8bef3cb249 (patch) | |
tree | d5eeed464c0e4e42a978edceab561b48ba03cd24 /db/migrate | |
parent | b410322990f6f5b656aaac00c4a4a3b810944eac (diff) | |
parent | c4067ed6eda1757e3757f22ad8587eeaa04d4be5 (diff) |
Merge branch 'zj-drop-fk-if-exists' into 'master'
Only remove FK if it exists
See merge request !11828
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/20170425112628_remove_foreigh_key_ci_trigger_schedules.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/db/migrate/20170425112628_remove_foreigh_key_ci_trigger_schedules.rb b/db/migrate/20170425112628_remove_foreigh_key_ci_trigger_schedules.rb index 6116ca59ee4..1587eee06ae 100644 --- a/db/migrate/20170425112628_remove_foreigh_key_ci_trigger_schedules.rb +++ b/db/migrate/20170425112628_remove_foreigh_key_ci_trigger_schedules.rb @@ -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 |