Implementing Native Composite Primary Key Support in Rails 7.1
summary
Rails 7.1 adds native composite primary key support so tables can use multiple columns as the primary key, with a new id_value helper to read an ID column when it becomes part of a composite, a where “triple” syntax for bulk queries, and an association option query_constraints that acts as a composite foreign key or virtual primary key. Shopify migration shows the tradeoff concretely: about 5x faster queries for tenant-scoped reads but roughly 10x slower inserts after switching to composite keys.
AI-written summary · about
chapters (9)
- 0:00Introduction
- 2:18Fundamentals
- 5:04Multitenant Applications
- 11:02Tenant Based Sharding
- 13:41Composite Primary Keys
- 16:33Where Query
- 17:12Constraints
- 18:32Virtual Primary Key
- 19:45Conclusion
related talks
24mImplementing Native Composite Primary Key Support in Rails 7.1
59mSQL primary key, surrogate key, composite keys, foreign keys... and JPA
30mNew and Improved Features in Rails 8.1
23mHow Shopify Sharded Rails
42mPowerful Rails Features You Might Not Know
38mMigrating Shopify’s Core Rails Monolith to Trilogy
31mRails anti-patterns: how not to design your database
01h 09mAll the Things I Thought I Couldn't Do
