diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-06-01 10:57:42 +0000 |
---|---|---|
committer | Timothy Andrew <mail@timothyandrew.net> | 2017-06-08 11:45:51 +0000 |
commit | f9e45bac3213c3d92a9efd6f7a17e5c2c8e4cbe7 (patch) | |
tree | 1a3c062dbd3fa97b393943d383ad27b33b616548 | |
parent | c15e018cc61d34bcad08eafe06a18216d8df2010 (diff) | |
download | gitlab-ce-f9e45bac3213c3d92a9efd6f7a17e5c2c8e4cbe7.tar.gz |
Merge branch 'zj-drop-fk-if-exists' into 'master'
Only remove FK if it exists
See merge request !11828
-rw-r--r-- | changelogs/unreleased/zj-drop-fk-if-exists.yml | 4 | ||||
-rw-r--r-- | db/migrate/20170425112628_remove_foreigh_key_ci_trigger_schedules.rb | 12 |
2 files changed, 15 insertions, 1 deletions
diff --git a/changelogs/unreleased/zj-drop-fk-if-exists.yml b/changelogs/unreleased/zj-drop-fk-if-exists.yml new file mode 100644 index 00000000000..237ba936de9 --- /dev/null +++ b/changelogs/unreleased/zj-drop-fk-if-exists.yml @@ -0,0 +1,4 @@ +--- +title: Remove foreigh key on ci_trigger_schedules only if it exists +merge_request: +author: 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 |