Commit 358662a9 authored by Yorick Peterse's avatar Yorick Peterse

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

Only remove FK if it exists

See merge request !11828
parents b4103229 c4067ed6
---
title: Remove foreigh key on ci_trigger_schedules only if it exists
merge_request:
author:
...@@ -4,10 +4,20 @@ class RemoveForeighKeyCiTriggerSchedules < ActiveRecord::Migration ...@@ -4,10 +4,20 @@ class RemoveForeighKeyCiTriggerSchedules < ActiveRecord::Migration
DOWNTIME = false DOWNTIME = false
def up def up
if fk_on_trigger_schedules?
remove_foreign_key :ci_trigger_schedules, column: :trigger_id remove_foreign_key :ci_trigger_schedules, column: :trigger_id
end end
end
def down def down
# no op, the foreign key should not have been here # no op, the foreign key should not have been here
end 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 end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment