This Week in Rails

November 3, 2023

"INSERT...RETURNING" for MariaDB, "SET CONSTRAINTS" for PostgreSQL, "DEFERRABLE" foreign keys for SQLite and much more!

Hey, zzak here with the first edition of This Week in Rails for November, 2023.

Support RETURNING clause for MariaDB
This PR adds support for the INSERT ... RETURNING expression for the MariaDB adapter.
You can read more about this feature in the official MariaDB docs.

Simplify attr_internal_define
This PR optimizes the internals of Module.attr_internal_naming_format= to eagerly strip the “@” prefix from the given format.
Providing a “@” prefix to this method is no longer accepted and will raise a deprecation warning.

Accept service as a Proc with “has_one_attached” and “has_many_attached”
Now you can specify the service as a callable Proc to make specialized attachment associations even more flexible in Active Storage.
class User < ActiveRecord::Base
  has_one_attached :avatar, service: ->(user) do
    user.in_europe_region? ? :s3_europe : :s3_usa
  end
end

Move “quote_string” to the AbstractMysqlAadapter class
Implementations of the method were exactly the same for trilogy and mysql2 adapters, so it made sense to refactor them into the inherited parent class.
If you were expecting this method to be defined on the Mysql2Adapter it has moved without a deprecation warning, or changelog as of writing this.

Fix using trix in sprockets
Action Text was updated to include the latest release of Trix v2.0.7 and an issue was fixed when trying to use the library with Sprockets.

Make Dockerfile template compatible with Kubernetes rootless pods
As the title says, the generated Dockerfile when running rails new now works when running in rootless pods in Kubernetes.
This may have an impact on other environments, but essentially changes from a user and group name to use a UID and GID.

Non-zero exit status on migration file creation errors
If an error occurs when running bin/rails generate migration a non-zero exist status is now returned.

Add support for deferred foreign keys to the SQLite3 adapter
This PR is a step into the direction to make SQLite a viable option in production, this time adding support for deferred foreign keys.

Add support for “SET CONSTRAINTS” to the PostgreSQL adapter
Now you can use the set_constraints method instead of executing a query by hand.
See the PostgreSQL docs for more.

Improve error messages when asserting change
Now the assert_changes and assert_no_changes error messages show objects using .inspect to make it easier to differentiate nil from empty strings, strings vs symbols, etc.

You can view the whole list of changes here.
We had 30 contributors to the Rails codebase this past week!

Until next time!

About This Week in Rails

Your weekly inside scoop of interesting commits, pull requests and more from Rails.