Refactor #14094
Replace DB migration foreign_keys calls with foreign_key_exists?
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.
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
Associated revisions
History
#1
Updated by Dominic Cleal about 6 years ago
- Blocks Feature #13244: Upgrade Ruby on Rails to 4.2 added
#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
Applied in changeset d273d9cfdec2192cf7f22f1f3a69d51c413b9647.
#4
Updated by Dominic Cleal about 6 years ago
- Legacy Backlogs Release (now unused) set to 136
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.