2024-01-06 00:13:01 +08:00
|
|
|
* The object returned by `explain` now responds to `pluck`, `first`,
|
|
|
|
`last`, `average`, `count`, `maximum`, `minimum`, and `sum`. Those
|
|
|
|
new methods run `EXPLAIN` on the corresponding queries:
|
2023-12-22 03:45:50 +08:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
User.all.explain.count
|
|
|
|
# EXPLAIN SELECT COUNT(*) FROM `users`
|
|
|
|
# ...
|
|
|
|
|
|
|
|
User.all.explain.maximum(:id)
|
|
|
|
# EXPLAIN SELECT MAX(`users`.`id`) FROM `users`
|
|
|
|
# ...
|
|
|
|
```
|
|
|
|
|
|
|
|
*Petrik de Heus*
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
* Fixes an issue where `validates_associated` `:on` option wasn't respected
|
|
|
|
when validating associated records.
|
2022-10-14 01:47:41 +08:00
|
|
|
|
|
|
|
*Austen Madden*, *Alex Ghiculescu*, *Rafał Brize*
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
* Allow overriding SQLite defaults from `database.yml`.
|
2024-01-02 19:52:54 +08:00
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
Any PRAGMA configuration set under the `pragmas` key in the configuration
|
|
|
|
file takes precedence over Rails' defaults, and additional PRAGMAs can be
|
|
|
|
set as well.
|
2024-01-02 19:52:54 +08:00
|
|
|
|
|
|
|
```yaml
|
|
|
|
database: storage/development.sqlite3
|
|
|
|
timeout: 5000
|
|
|
|
pragmas:
|
|
|
|
journal_mode: off
|
|
|
|
temp_store: memory
|
|
|
|
```
|
|
|
|
|
|
|
|
*Stephen Margheim*
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
* Remove warning message when running SQLite in production, but leave it unconfigured.
|
2023-12-28 03:56:47 +08:00
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
There are valid use cases for running SQLite in production. However it must be done
|
2023-12-28 03:56:47 +08:00
|
|
|
with care, so instead of a warning most users won't see anyway, it's preferable to
|
|
|
|
leave the configuration commented out to force them to think about having the database
|
|
|
|
on a persistent volume etc.
|
|
|
|
|
|
|
|
*Jacopo Beschi*, *Jean Boussier*
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
* Add support for generated columns to the SQLite3 adapter.
|
2023-09-21 20:56:45 +08:00
|
|
|
|
|
|
|
Generated columns (both stored and dynamic) are supported since version 3.31.0 of SQLite.
|
|
|
|
This adds support for those to the SQLite3 adapter.
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
create_table :users do |t|
|
|
|
|
t.string :name
|
|
|
|
t.virtual :name_upper, type: :string, as: 'UPPER(name)'
|
|
|
|
t.virtual :name_lower, type: :string, as: 'LOWER(name)', stored: true
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
*Stephen Margheim*
|
|
|
|
|
2023-12-14 00:30:21 +08:00
|
|
|
* TrilogyAdapter: ignore `host` if `socket` parameter is set.
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
This allows to configure a connection on a UNIX socket via `DATABASE_URL`:
|
2023-12-14 00:30:21 +08:00
|
|
|
|
|
|
|
```
|
|
|
|
DATABASE_URL=trilogy://does-not-matter/my_db_production?socket=/var/run/mysql.sock
|
|
|
|
```
|
|
|
|
|
|
|
|
*Jean Boussier*
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
* Make `assert_queries_count`, `assert_no_queries`, `assert_queries_match`, and
|
2023-12-20 18:28:55 +08:00
|
|
|
`assert_no_queries_match` assertions public.
|
2023-03-01 20:57:02 +08:00
|
|
|
|
2023-12-20 18:28:55 +08:00
|
|
|
To assert the expected number of queries are made, Rails internally uses `assert_queries_count` and
|
|
|
|
`assert_no_queries`. To assert that specific SQL queries are made, `assert_queries_match` and
|
|
|
|
`assert_no_queries_match` are used. These assertions can now be used in applications as well.
|
2023-03-01 20:57:02 +08:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
class ArticleTest < ActiveSupport::TestCase
|
|
|
|
test "queries are made" do
|
2023-12-20 18:28:55 +08:00
|
|
|
assert_queries_count(1) { Article.first }
|
|
|
|
end
|
|
|
|
|
|
|
|
test "creates a foreign key" do
|
|
|
|
assert_queries_match(/ADD FOREIGN KEY/i, include_schema: true) do
|
|
|
|
@connection.add_foreign_key(:comments, :posts)
|
|
|
|
end
|
2023-03-01 20:57:02 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
2023-12-20 18:28:55 +08:00
|
|
|
*Petrik de Heus*, *fatkodima*
|
2023-03-01 20:57:02 +08:00
|
|
|
|
2023-12-03 18:10:51 +08:00
|
|
|
* Fix `has_secure_token` calls the setter method on initialize.
|
|
|
|
|
|
|
|
*Abeid Ahmed*
|
|
|
|
|
2023-11-23 02:06:37 +08:00
|
|
|
* When using a `DATABASE_URL`, allow for a configuration to map the protocol in the URL to a specific database
|
|
|
|
adapter. This allows decoupling the adapter the application chooses to use from the database connection details
|
|
|
|
set in the deployment environment.
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
# ENV['DATABASE_URL'] = "mysql://localhost/example_database"
|
|
|
|
config.active_record.protocol_adapters.mysql = "trilogy"
|
|
|
|
# will connect to MySQL using the trilogy adapter
|
|
|
|
```
|
|
|
|
|
|
|
|
*Jean Boussier*, *Kevin McPhillips*
|
|
|
|
|
2023-11-14 03:39:14 +08:00
|
|
|
* In cases where MySQL returns `warning_count` greater than zero, but returns no warnings when
|
|
|
|
the `SHOW WARNINGS` query is executed, `ActiveRecord.db_warnings_action` proc will still be
|
|
|
|
called with a generic warning message rather than silently ignoring the warning(s).
|
|
|
|
|
|
|
|
*Kevin McPhillips*
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
* `DatabaseConfigurations#configs_for` accepts a symbol in the `name` parameter.
|
2023-11-15 06:25:07 +08:00
|
|
|
|
|
|
|
*Andrew Novoselac*
|
|
|
|
|
2023-08-27 22:41:11 +08:00
|
|
|
* Fix `where(field: values)` queries when `field` is a serialized attribute
|
|
|
|
(for example, when `field` uses `ActiveRecord::Base.serialize` or is a JSON
|
|
|
|
column).
|
|
|
|
|
|
|
|
*João Alves*
|
|
|
|
|
2023-10-21 06:27:33 +08:00
|
|
|
* Make the output of `ActiveRecord::Core#inspect` configurable.
|
|
|
|
|
|
|
|
By default, calling `inspect` on a record will yield a formatted string including just the `id`.
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
Post.first.inspect #=> "#<Post id: 1>"
|
|
|
|
```
|
|
|
|
|
|
|
|
The attributes to be included in the output of `inspect` can be configured with
|
|
|
|
`ActiveRecord::Core#attributes_for_inspect`.
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
Post.attributes_for_inspect = [:id, :title]
|
|
|
|
Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!">"
|
|
|
|
```
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
With `attributes_for_inspect` set to `:all`, `inspect` will list all the record's attributes.
|
2023-10-21 06:27:33 +08:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
Post.attributes_for_inspect = :all
|
|
|
|
Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!", published_at: "2023-10-23 14:28:11 +0000">"
|
|
|
|
```
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
In `development` and `test` mode, `attributes_for_inspect` will be set to `:all` by default.
|
2023-10-21 06:27:33 +08:00
|
|
|
|
|
|
|
You can also call `full_inspect` to get an inspection with all the attributes.
|
|
|
|
|
|
|
|
The attributes in `attribute_for_inspect` will also be used for `pretty_print`.
|
|
|
|
|
|
|
|
*Andrew Novoselac*
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
* Don't mark attributes as changed when reassigned to `Float::INFINITY` or
|
|
|
|
`-Float::INFINITY`.
|
2023-11-03 23:24:19 +08:00
|
|
|
|
|
|
|
*Maicol Bentancor*
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
* Support the `RETURNING` clause for MariaDB.
|
2023-10-30 07:13:48 +08:00
|
|
|
|
|
|
|
*fatkodima*, *Nikolay Kondratyev*
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
* The SQLite3 adapter now implements the `supports_deferrable_constraints?` contract.
|
2023-09-25 05:14:02 +08:00
|
|
|
|
|
|
|
Allows foreign keys to be deferred by adding the `:deferrable` key to the `foreign_key` options.
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
add_reference :person, :alias, foreign_key: { deferrable: :deferred }
|
|
|
|
add_reference :alias, :person, foreign_key: { deferrable: :deferred }
|
|
|
|
```
|
|
|
|
|
|
|
|
*Stephen Margheim*
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
* Add the `set_constraints` helper to PostgreSQL connections.
|
2023-09-07 06:26:29 +08:00
|
|
|
|
|
|
|
```ruby
|
|
|
|
Post.create!(user_id: -1) # => ActiveRecord::InvalidForeignKey
|
|
|
|
|
|
|
|
Post.transaction do
|
|
|
|
Post.connection.set_constraints(:deferred)
|
|
|
|
p = Post.create!(user_id: -1)
|
|
|
|
u = User.create!
|
|
|
|
p.user = u
|
|
|
|
p.save!
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
*Cody Cutrer*
|
|
|
|
|
2024-01-06 00:40:06 +08:00
|
|
|
* Include `ActiveModel::API` in `ActiveRecord::Base`.
|
2023-10-18 07:08:16 +08:00
|
|
|
|
|
|
|
*Sean Doyle*
|
|
|
|
|
2023-10-06 21:24:37 +08:00
|
|
|
* Ensure `#signed_id` outputs `url_safe` strings.
|
|
|
|
|
|
|
|
*Jason Meller*
|
2023-09-27 11:08:31 +08:00
|
|
|
|
2023-11-16 05:06:25 +08:00
|
|
|
* Add `nulls_last` and working `desc.nulls_first` for MySQL.
|
|
|
|
|
|
|
|
*Tristan Fellows*
|
|
|
|
|
2023-09-27 11:59:11 +08:00
|
|
|
Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/activerecord/CHANGELOG.md) for previous changes.
|