Hi, it’s Greg, bring you the latest changes in the Rails codebase.
Rails 7.1 beta release
The first beta version of Rails 7.1 has been released! There have been over five thousand commits made by over 800 contributors since Rails 7.0, so this release is packed with new features and improvements. You can read a summary of the changes in the announcement.
Ignore env files (except templates)
To prevent accidentally leaking secrets to code repositories, the default .gitignore file excludes .env(except template ones) files from now on.
Explicit primary_key: option should always take priority in associations
This pull request fixes the issue where the
primary_key: option was ignored if the associated model had a
query_constraints configured. Now
primary_key: option always takes priority, and only if there is no
primary_key: option, the
query_constraints are used to determine the
Instrument Active Record transactions
This pull request adds a new
transaction.active_record event to track when Active Record-managed transactions occur. It includes the connection in the payload (useful, for example, in differentiating transactions to different databases),
Add Bun support
Bun is a new and viable alternative to the node.js runtime, yarn package manager, and esbuild bundler. Bun’s primary differentiating characteristic is speed. It’s often multiple times faster than node.js and friends.
Add dedicated guide for composite primary keys
This pull request adds a dedicated guide for composite primary key usage.
Besides the dedicated guide, #49218 added a suggestion to use composite primary keys on join tables of
Support composite foreign keys via migration helpers
The Rails migration helpers now support composite primary keys. A few examples of using them:
# Assuming "carts" table has "(shop_id, id)" as a primary key.
add_foreign_key(:orders, :carts, primary_key: [:shop_id, :id])
add_foreign_key(:orders, :carts, column: [:cart_shop_id, :cart_id])
remove_foreign_key(:orders, :carts, primary_key: [:shop_id, :id])
foreign_key_exists?(:orders, :carts, primary_key: [:shop_id, :id])
Add “Testing View Partials” section to the Testing Guides
A “Testing View Partials” section is added to the guides that expand upon the variety of tooling available to tests that inherit from
Adds support for if_not_exists when adding a check constraint.
add_check_constraint method now accepts an
if_not_exists option. If set to true an error won’t be raised if the check constraint already exists. In addition,
if_not_exists options are transposed if set when reversing
add_check_constraint. This enables the simple creation of idempotent, non-transactional migrations.
Encryption: support support_unencrypted_data at a per-attribute level
ActiveRecord::Encryption.config.support_unencrypted_data is enabled, this change allows you to override that global setting on an attribute should you need.
Raise error when generating attribute with a dangerous name
Generating a model with attributes named
save should raise an error instead of generating a migration with an invalid attribute, and this pull request made that happen.
You can view the whole list of changes here.
We had 28 contributors to the Rails codebase this past week!
Until next time!