BigW Consortium Gitlab

20170425112628_remove_foreigh_key_ci_trigger_schedules.rb 549 Bytes
Newer Older
1 2 3 4 5 6
class RemoveForeighKeyCiTriggerSchedules < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  def up
7 8 9
    if fk_on_trigger_schedules?
      remove_foreign_key :ci_trigger_schedules, column: :trigger_id
    end
10 11 12 13 14
  end

  def down
    # no op, the foreign key should not have been here
  end
15 16 17 18 19 20 21 22

  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
23
end