The Wire · Showcase
SQLITE3 FOREIGN KEYS GET THEIR NAMES BACK
By RepoJournal · Filed · About Rails
SQLite3 migrations just stopped silently destroying the wrong foreign keys.
Rails merged three critical fixes for SQLite3 schema introspection that were causing migrations to behave unpredictably [1]. The core issue: `foreign_keys` wasn't reading constraint names from the schema, so every `ForeignKeyDefinition` came back with `name == nil`. This meant `remove_foreign_key(table, name: "fk")` ignored your target constraint and deleted an arbitrary one instead [1]. The same blind spot broke `if_not_exists:` on both `add_check_constraint` and `add_foreign_key` [2], leaving SQLite3 users without options that MySQL and PostgreSQL had long since fixed. Two merges landed overnight: one restoring name reading from the schema [3], the other honoring the `if_not_exists:` flag in adds and removes [2]. Rails also landed a quality-of-life fix letting `relative_time_in_words` accept `Date` and numeric inputs directly [4], plus a cleanup removing unnecessary reverse calls [5]. Over in Solid Queue, the Puma plugin tests got smarter about port allocation, ditching hardcoded 9222 for dynamic assignment to stop EADDRINUSE cascade failures [6].
Action items
- → If you use SQLite3 and migrations that target foreign keys by name, pull the latest main before your next deploy rails/rails [immediate]
- → Review any SQLite3 migrations that rely on add_check_constraint or add_foreign_key with if_not_exists to confirm they work as intended rails/rails [plan]
- → Update Solid Queue if you run its test suite and see port binding flakes rails/solid_queue [monitor]
References
- [1] Read foreign key names from the schema on SQLite3 rails/rails
- [2] Honor if_not_exists in SQLite3 add_check_constraint and add_foreign_key rails/rails
- [3] Merge pull request #58091 from 55728/fix-sqlite3-add-check-constraint-if-not-exists rails/rails
- [4] Merge pull request #58092 from 55728/fix-relative-time-in-words-non-time-inputs rails/rails
- [5] Remove unnecessary reverse call rails/rails
- [6] Use dynamic port allocation in Puma plugin tests rails/solid_queue