Project

General

Profile

Refactor #14094

Replace DB migration foreign_keys calls with foreign_key_exists?

Added by Dominic Cleal about 6 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
DB migrations
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

In Rail 4.2 and higher, where native foreign key support replaces Foreigner, the "foreign_keys" call inside a DB migration should be avoided as it will throw an exception on databases (SQLite) that don't support FKs.

https://github.com/rails/rails/blob/6298ac705da92cc793cbf40dd91484d34e01d255/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L671

In Foreigner, it returned [] on SQLite. In #13244 (Rails 4.2) I'll add a compatibility layer with a deprecation warning, but our migrations that use this to check whether a key exists should just use the foreign_key_exists? method for better compatibility.


Related issues

Blocks Foreman - Feature #13244: Upgrade Ruby on Rails to 4.2Closed2016-01-15

Associated revisions

Revision d273d9cf (diff)
Added by Dominic Cleal about 6 years ago

fixes #14094 - replace foreign_keys calls with foreign_key_exists?

foreign_keys throws an exception under SQLite in Rails 4.2, so prefer
the _exists? call to check for presence of a key as it returns false on
DBs without FK support.

History

#1 Updated by Dominic Cleal about 6 years ago

#2 Updated by The Foreman Bot about 6 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/3290 added

#3 Updated by Dominic Cleal about 6 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#4 Updated by Dominic Cleal about 6 years ago

  • Legacy Backlogs Release (now unused) set to 136

Also available in: Atom PDF