2018-12-27 19:21:09 -05:00
|
|
|
* Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
|
|
|
|
|
|
|
|
*Ryuta Kamizono*
|
|
|
|
|
2018-11-06 04:08:02 -05:00
|
|
|
* MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
|
|
|
|
|
|
|
|
Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
|
|
|
|
format for InnoDB tables. The default setting is `DYNAMIC`.
|
|
|
|
The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
|
|
|
|
|
|
|
|
*Ryuta Kamizono*
|
|
|
|
|
2018-12-05 10:52:17 -05:00
|
|
|
* Fix join table column quoting with SQLite.
|
|
|
|
|
|
|
|
*Gannon McGibbon*
|
|
|
|
|
2018-12-03 04:52:59 -05:00
|
|
|
* Allow disabling scopes generated by `ActiveRecord.enum`.
|
|
|
|
|
|
|
|
*Alfred Dominic*
|
|
|
|
|
2018-12-04 00:33:31 -05:00
|
|
|
* Ensure that `delete_all` on collection proxy returns affected count.
|
|
|
|
|
|
|
|
*Ryuta Kamizono*
|
|
|
|
|
2018-12-03 17:24:29 -05:00
|
|
|
* Reset scope after delete on collection association to clear stale offsets of removed records.
|
|
|
|
|
|
|
|
*Gannon McGibbon*
|
|
|
|
|
2018-11-21 15:29:46 -05:00
|
|
|
* Add the ability to prevent writes to a database for the duration of a block.
|
|
|
|
|
|
|
|
Allows the application to prevent writes to a database. This can be useful when
|
|
|
|
you're building out multiple databases and want to make sure you're not sending
|
|
|
|
writes when you want a read.
|
|
|
|
|
|
|
|
If `while_preventing_writes` is called and the query is considered a write
|
|
|
|
query the database will raise an exception regardless of whether the database
|
|
|
|
user is able to write.
|
|
|
|
|
|
|
|
This is not meant to be a catch-all for write queries but rather a way to enforce
|
|
|
|
read-only queries without opening a second connection. One purpose of this is to
|
|
|
|
catch accidental writes, not all writes.
|
|
|
|
|
|
|
|
*Eileen M. Uchitelle*
|
|
|
|
|
2018-11-29 14:43:38 -05:00
|
|
|
* Allow aliased attributes to be used in `#update_columns` and `#update`.
|
|
|
|
|
|
|
|
*Gannon McGibbon*
|
|
|
|
|
2018-11-28 16:15:21 -05:00
|
|
|
* Allow spaces in postgres table names.
|
|
|
|
|
|
|
|
Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
|
|
|
|
|
|
|
|
*Gannon McGibbon*
|
|
|
|
|
2018-11-26 03:12:42 -05:00
|
|
|
* Cached columns_hash fields should be excluded from ResultSet#column_types
|
|
|
|
|
|
|
|
PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
|
|
|
|
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
class DeveloperName < ActiveRecord::Type::String
|
|
|
|
def deserialize(value)
|
|
|
|
"Developer: #{value}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class AttributedDeveloper < ActiveRecord::Base
|
|
|
|
self.table_name = "developers"
|
|
|
|
|
|
|
|
attribute :name, DeveloperName.new
|
|
|
|
|
|
|
|
self.ignored_columns += ["name"]
|
|
|
|
end
|
|
|
|
|
|
|
|
developer = AttributedDeveloper.create
|
|
|
|
developer.update_column :name, "name"
|
|
|
|
|
|
|
|
loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
|
|
|
|
puts loaded_developer.name # should be "Developer: name" but it's just "name"
|
|
|
|
```
|
|
|
|
|
|
|
|
*Dmitry Tsepelev*
|
|
|
|
|
2018-11-17 16:50:01 -05:00
|
|
|
* Make the implicit order column configurable.
|
|
|
|
|
|
|
|
When calling ordered finder methods such as +first+ or +last+ without an
|
|
|
|
explicit order clause, ActiveRecord sorts records by primary key. This can
|
|
|
|
result in unpredictable and surprising behaviour when the primary key is
|
|
|
|
not an auto-incrementing integer, for example when it's a UUID. This change
|
|
|
|
makes it possible to override the column used for implicit ordering such
|
|
|
|
that +first+ and +last+ will return more predictable results.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
class Project < ActiveRecord::Base
|
|
|
|
self.implicit_order_column = "created_at"
|
|
|
|
end
|
|
|
|
|
|
|
|
*Tekin Suleyman*
|
|
|
|
|
2018-09-23 00:45:19 -04:00
|
|
|
* Bump minimum PostgreSQL version to 9.3.
|
|
|
|
|
|
|
|
*Yasuo Honda*
|
|
|
|
|
2018-11-23 18:55:31 -05:00
|
|
|
* Values of enum are frozen, raising an error when attempting to modify them.
|
|
|
|
|
|
|
|
*Emmanuel Byrd*
|
|
|
|
|
2018-11-15 19:55:47 -05:00
|
|
|
* Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
|
|
|
|
|
|
|
|
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
|
|
|
|
|
|
|
|
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
|
|
|
|
|
|
|
|
Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
```
|
|
|
|
class MySubclassedError < ActiveRecord::StatementInvalid
|
|
|
|
def initialize(message, sql:, binds:)
|
|
|
|
super(message, sql: sql, binds: binds)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
*Gannon McGibbon*
|
|
|
|
|
2017-12-09 11:02:51 -05:00
|
|
|
* Add an `:if_not_exists` option to `create_table`.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
create_table :posts, if_not_exists: true do |t|
|
|
|
|
t.string :title
|
|
|
|
end
|
|
|
|
|
|
|
|
That would execute:
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS posts (
|
|
|
|
...
|
|
|
|
)
|
|
|
|
|
|
|
|
If the table already exists, `if_not_exists: false` (the default) raises an
|
|
|
|
exception whereas `if_not_exists: true` does nothing.
|
|
|
|
|
|
|
|
*fatkodima*, *Stefan Kanev*
|
|
|
|
|
2018-11-07 17:38:41 -05:00
|
|
|
* Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
|
|
|
|
|
|
|
|
*Christophe Maximin*
|
|
|
|
|
|
|
|
* Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
|
2018-10-05 16:06:10 -04:00
|
|
|
|
|
|
|
*Gannon McGibbon*
|
|
|
|
|
2018-10-30 14:52:23 -04:00
|
|
|
* `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
|
|
|
|
if the attribute does not exist.
|
|
|
|
|
|
|
|
*Sean Griffin*
|
|
|
|
|
2018-10-11 17:54:56 -04:00
|
|
|
* Add support for hash and url configs in database hash of `ActiveRecord::Base.connected_to`.
|
|
|
|
|
|
|
|
````
|
|
|
|
User.connected_to(database: { writing: "postgres://foo" }) do
|
|
|
|
User.create!(name: "Gannon")
|
|
|
|
end
|
|
|
|
|
|
|
|
config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
|
|
|
|
User.connected_to(database: { reading: config }) do
|
|
|
|
User.count
|
|
|
|
end
|
|
|
|
````
|
|
|
|
|
|
|
|
*Gannon McGibbon*
|
|
|
|
|
2018-10-24 21:11:31 -04:00
|
|
|
* Support default expression for MySQL.
|
|
|
|
|
|
|
|
MySQL 8.0.13 and higher supports default value to be a function or expression.
|
|
|
|
|
|
|
|
https://dev.mysql.com/doc/refman/8.0/en/create-table.html
|
|
|
|
|
|
|
|
*Ryuta Kamizono*
|
|
|
|
|
2018-10-24 18:29:51 -04:00
|
|
|
* Support expression indexes for MySQL.
|
|
|
|
|
|
|
|
MySQL 8.0.13 and higher supports functional key parts that index
|
|
|
|
expression values rather than column or column prefix values.
|
|
|
|
|
|
|
|
https://dev.mysql.com/doc/refman/8.0/en/create-index.html
|
|
|
|
|
|
|
|
*Ryuta Kamizono*
|
|
|
|
|
2018-10-15 20:51:32 -04:00
|
|
|
* Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
|
2018-06-07 00:05:30 -04:00
|
|
|
|
|
|
|
Fixes #33056.
|
|
|
|
|
|
|
|
*Federico Martinez*
|
|
|
|
|
2018-09-28 16:52:54 -04:00
|
|
|
* Add basic API for connection switching to support multiple databases.
|
|
|
|
|
|
|
|
1) Adds a `connects_to` method for models to connect to multiple databases. Example:
|
|
|
|
|
|
|
|
```
|
|
|
|
class AnimalsModel < ApplicationRecord
|
|
|
|
self.abstract_class = true
|
|
|
|
|
|
|
|
connects_to database: { writing: :animals_primary, reading: :animals_replica }
|
|
|
|
end
|
|
|
|
|
|
|
|
class Dog < AnimalsModel
|
|
|
|
# connected to both the animals_primary db for writing and the animals_replica for reading
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
2) Adds a `connected_to` block method for switching connection roles or connecting to
|
|
|
|
a database that the model didn't connect to. Connecting to the database in this block is
|
|
|
|
useful when you have another defined connection, for example `slow_replica` that you don't
|
|
|
|
want to connect to by default but need in the console, or a specific code block.
|
|
|
|
|
|
|
|
```
|
|
|
|
ActiveRecord::Base.connected_to(role: :reading) do
|
|
|
|
Dog.first # finds dog from replica connected to AnimalsBase
|
|
|
|
Book.first # doesn't have a reading connection, will raise an error
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
```
|
|
|
|
ActiveRecord::Base.connected_to(database: :slow_replica) do
|
|
|
|
SlowReplicaModel.first # if the db config has a slow_replica configuration this will be used to do the lookup, otherwise this will throw an exception
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
*Eileen M. Uchitelle*
|
|
|
|
|
2018-10-06 12:08:45 -04:00
|
|
|
* Enum raises on invalid definition values
|
|
|
|
|
|
|
|
When defining a Hash enum it can be easy to use [] instead of {}. This
|
|
|
|
commit checks that only valid definition values are provided, those can
|
|
|
|
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
|
|
|
raises an ArgumentError.
|
|
|
|
|
|
|
|
Fixes #33961
|
|
|
|
|
|
|
|
*Alberto Almagro*
|
|
|
|
|
2018-10-05 08:00:45 -04:00
|
|
|
* Reloading associations now clears the Query Cache like `Persistence#reload` does.
|
|
|
|
|
|
|
|
```
|
|
|
|
class Post < ActiveRecord::Base
|
|
|
|
has_one :category
|
|
|
|
belongs_to :author
|
|
|
|
has_many :comments
|
|
|
|
end
|
|
|
|
|
|
|
|
# Each of the following will now clear the query cache.
|
|
|
|
post.reload_category
|
|
|
|
post.reload_author
|
|
|
|
post.comments.reload
|
|
|
|
```
|
|
|
|
|
|
|
|
*Christophe Maximin*
|
|
|
|
|
2018-09-22 10:47:57 -04:00
|
|
|
* Added `index` option for `change_table` migration helpers.
|
|
|
|
With this change you can create indexes while adding new
|
|
|
|
columns into the existing tables.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
change_table(:languages) do |t|
|
|
|
|
t.string :country_code, index: true
|
|
|
|
end
|
|
|
|
|
|
|
|
*Mehmet Emin İNAÇ*
|
|
|
|
|
2017-12-30 21:19:43 -05:00
|
|
|
* Fix `transaction` reverting for migrations.
|
|
|
|
|
|
|
|
Before: Commands inside a `transaction` in a reverted migration ran uninverted.
|
|
|
|
Now: This change fixes that by reverting commands inside `transaction` block.
|
|
|
|
|
|
|
|
*fatkodima*, *David Verhasselt*
|
|
|
|
|
2018-09-25 18:52:45 -04:00
|
|
|
* Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
|
|
|
|
|
|
|
|
*Gannon McGibbon*, *Max Albrecht*
|
|
|
|
|
2018-09-24 13:20:03 -04:00
|
|
|
* Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
|
|
|
|
|
|
|
|
*Gannon McGibbon*
|
|
|
|
|
2018-08-07 17:35:13 -04:00
|
|
|
* Don't update counter cache unless the record is actually saved.
|
|
|
|
|
|
|
|
Fixes #31493, #33113, #33117.
|
|
|
|
|
|
|
|
*Ryuta Kamizono*
|
|
|
|
|
2016-01-29 17:44:04 -05:00
|
|
|
* Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
|
|
|
|
|
|
|
|
*Gannon McGibbon*, *Kevin Cheng*
|
|
|
|
|
2018-09-13 20:19:49 -04:00
|
|
|
* SQLite3 adapter supports expression indexes.
|
2018-09-13 16:00:51 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
create_table :users do |t|
|
|
|
|
t.string :email
|
|
|
|
end
|
|
|
|
|
|
|
|
add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
|
|
|
|
```
|
|
|
|
|
|
|
|
*Gray Kemmey*
|
|
|
|
|
2018-07-17 05:55:30 -04:00
|
|
|
* Allow subclasses to redefine autosave callbacks for associated records.
|
|
|
|
|
|
|
|
Fixes #33305.
|
|
|
|
|
|
|
|
*Andrey Subbota*
|
|
|
|
|
2018-09-13 06:45:32 -04:00
|
|
|
* Bump minimum MySQL version to 5.5.8.
|
|
|
|
|
|
|
|
*Yasuo Honda*
|
|
|
|
|
2018-09-11 16:03:34 -04:00
|
|
|
* Use MySQL utf8mb4 character set by default.
|
|
|
|
|
|
|
|
`utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
|
|
|
|
The previous default 3-Byte encoding character set `utf8` is not enough to support them.
|
|
|
|
|
|
|
|
*Yasuo Honda*
|
|
|
|
|
2018-08-15 20:18:51 -04:00
|
|
|
* Fix duplicated record creation when using nested attributes with `create_with`.
|
|
|
|
|
|
|
|
*Darwin Wu*
|
|
|
|
|
2018-09-10 12:10:44 -04:00
|
|
|
* Configuration item `config.filter_parameters` could also filter out
|
|
|
|
sensitive values of database columns when call `#inspect`.
|
|
|
|
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
|
|
|
specify sensitive attributes to specific model.
|
2018-09-06 21:46:54 -04:00
|
|
|
|
|
|
|
```
|
2018-10-09 03:14:51 -04:00
|
|
|
Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
|
|
|
|
Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
|
2018-09-10 12:10:44 -04:00
|
|
|
SecureAccount.filter_attributes += [:name]
|
|
|
|
SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
|
2018-09-06 21:46:54 -04:00
|
|
|
```
|
|
|
|
|
2018-10-09 03:14:51 -04:00
|
|
|
*Zhang Kang*, *Yoshiyuki Kinjo*
|
2018-09-06 21:46:54 -04:00
|
|
|
|
2018-09-05 10:45:52 -04:00
|
|
|
* Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
|
|
|
|
`indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
|
|
|
|
and `joins_per_query` methods in `DatabaseLimits`.
|
|
|
|
|
|
|
|
*Ryuta Kamizono*
|
|
|
|
|
2018-09-06 18:56:31 -04:00
|
|
|
* `ActiveRecord::Base.configurations` now returns an object.
|
Refactors Active Record connection management
While the three-tier config makes it easier to define databases for
multiple database applications, it quickly became clear to offer full
support for multiple databases we need to change the way the connections
hash was handled.
A three-tier config means that when Rails needed to choose a default
configuration (in the case a user doesn't ask for a specific
configuration) it wasn't clear to Rails which the default was. I
[bandaid fixed this so the rake tasks could work](#32271) but that fix
wasn't correct because it actually doubled up the configuration hashes.
Instead of attemping to manipulate the hashes @tenderlove and I decided
that it made more sense if we converted the hashes to objects so we can
easily ask those object questions. In a three tier config like this:
```
development:
primary:
database: "my_primary_db"
animals:
database; "my_animals_db"
```
We end up with an object like this:
```
@configurations=[
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
@env_name="development",@spec_name="primary",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>,
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90
@env_name="development",@spec_name="animals",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
]>
```
The configurations setter takes the database configuration set by your
application and turns them into an
`ActiveRecord::DatabaseConfigurations` object that has one getter -
`@configurations` which is an array of all the database objects.
The configurations getter returns this object by default since it acts
like a hash in most of the cases we need. For example if you need to
access the default `development` database we can simply request it as we
did before:
```
ActiveRecord::Base.configurations["development"]
```
This will return primary development database configuration hash:
```
{ "database" => "my_primary_db" }
```
Internally all of Active Record has been converted to use the new
objects. I've built this to be backwards compatible but allow for
accessing the hash if needed for a deprecation period. To get the
original hash instead of the object you can either add `to_h` on the
configurations call or pass `legacy: true` to `configurations.
```
ActiveRecord::Base.configurations.to_h
=> { "development => { "database" => "my_primary_db" } }
ActiveRecord::Base.configurations(legacy: true)
=> { "development => { "database" => "my_primary_db" } }
```
The new configurations object allows us to iterate over the Active
Record configurations without losing the known environment or
specification name for that configuration. You can also select all the
configs for an env or env and spec. With this we can always ask
any object what environment it belongs to:
```
db_configs = ActiveRecord::Base.configurations.configurations_for("development")
=> #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800
@configurations=[
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
@env_name="development",@spec_name="primary",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>,
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90
@env_name="development",@spec_name="animals",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
]>
db_config.env_name
=> "development"
db_config.spec_name
=> "primary"
db_config.config
=> { "adapter"=>"sqlite3", "database"=>"db/development.sqlite3" }
```
The configurations object is more flexible than the configurations hash
and will allow us to build on top of the connection management in order
to add support for primary/replica connections, sharding, and
constructing queries for associations that live in multiple databases.
2018-08-16 15:49:18 -04:00
|
|
|
|
2018-09-06 18:56:31 -04:00
|
|
|
`ActiveRecord::Base.configurations` used to return a hash, but this
|
Refactors Active Record connection management
While the three-tier config makes it easier to define databases for
multiple database applications, it quickly became clear to offer full
support for multiple databases we need to change the way the connections
hash was handled.
A three-tier config means that when Rails needed to choose a default
configuration (in the case a user doesn't ask for a specific
configuration) it wasn't clear to Rails which the default was. I
[bandaid fixed this so the rake tasks could work](#32271) but that fix
wasn't correct because it actually doubled up the configuration hashes.
Instead of attemping to manipulate the hashes @tenderlove and I decided
that it made more sense if we converted the hashes to objects so we can
easily ask those object questions. In a three tier config like this:
```
development:
primary:
database: "my_primary_db"
animals:
database; "my_animals_db"
```
We end up with an object like this:
```
@configurations=[
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
@env_name="development",@spec_name="primary",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>,
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90
@env_name="development",@spec_name="animals",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
]>
```
The configurations setter takes the database configuration set by your
application and turns them into an
`ActiveRecord::DatabaseConfigurations` object that has one getter -
`@configurations` which is an array of all the database objects.
The configurations getter returns this object by default since it acts
like a hash in most of the cases we need. For example if you need to
access the default `development` database we can simply request it as we
did before:
```
ActiveRecord::Base.configurations["development"]
```
This will return primary development database configuration hash:
```
{ "database" => "my_primary_db" }
```
Internally all of Active Record has been converted to use the new
objects. I've built this to be backwards compatible but allow for
accessing the hash if needed for a deprecation period. To get the
original hash instead of the object you can either add `to_h` on the
configurations call or pass `legacy: true` to `configurations.
```
ActiveRecord::Base.configurations.to_h
=> { "development => { "database" => "my_primary_db" } }
ActiveRecord::Base.configurations(legacy: true)
=> { "development => { "database" => "my_primary_db" } }
```
The new configurations object allows us to iterate over the Active
Record configurations without losing the known environment or
specification name for that configuration. You can also select all the
configs for an env or env and spec. With this we can always ask
any object what environment it belongs to:
```
db_configs = ActiveRecord::Base.configurations.configurations_for("development")
=> #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800
@configurations=[
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
@env_name="development",@spec_name="primary",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>,
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90
@env_name="development",@spec_name="animals",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
]>
db_config.env_name
=> "development"
db_config.spec_name
=> "primary"
db_config.config
=> { "adapter"=>"sqlite3", "database"=>"db/development.sqlite3" }
```
The configurations object is more flexible than the configurations hash
and will allow us to build on top of the connection management in order
to add support for primary/replica connections, sharding, and
constructing queries for associations that live in multiple databases.
2018-08-16 15:49:18 -04:00
|
|
|
is an inflexible data model. In order to improve multiple-database
|
|
|
|
handling in Rails, we've changed this to return an object. Some methods
|
|
|
|
are provided to make the object behave hash-like in order to ease the
|
|
|
|
transition process. Since most applications don't manipulate the hash
|
|
|
|
we've decided to add backwards-compatible functionality that will throw
|
|
|
|
a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
|
|
|
|
will use the new version internally and externally.
|
|
|
|
|
2018-09-08 09:06:23 -04:00
|
|
|
For example, the following `database.yml`:
|
Refactors Active Record connection management
While the three-tier config makes it easier to define databases for
multiple database applications, it quickly became clear to offer full
support for multiple databases we need to change the way the connections
hash was handled.
A three-tier config means that when Rails needed to choose a default
configuration (in the case a user doesn't ask for a specific
configuration) it wasn't clear to Rails which the default was. I
[bandaid fixed this so the rake tasks could work](#32271) but that fix
wasn't correct because it actually doubled up the configuration hashes.
Instead of attemping to manipulate the hashes @tenderlove and I decided
that it made more sense if we converted the hashes to objects so we can
easily ask those object questions. In a three tier config like this:
```
development:
primary:
database: "my_primary_db"
animals:
database; "my_animals_db"
```
We end up with an object like this:
```
@configurations=[
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
@env_name="development",@spec_name="primary",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>,
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90
@env_name="development",@spec_name="animals",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
]>
```
The configurations setter takes the database configuration set by your
application and turns them into an
`ActiveRecord::DatabaseConfigurations` object that has one getter -
`@configurations` which is an array of all the database objects.
The configurations getter returns this object by default since it acts
like a hash in most of the cases we need. For example if you need to
access the default `development` database we can simply request it as we
did before:
```
ActiveRecord::Base.configurations["development"]
```
This will return primary development database configuration hash:
```
{ "database" => "my_primary_db" }
```
Internally all of Active Record has been converted to use the new
objects. I've built this to be backwards compatible but allow for
accessing the hash if needed for a deprecation period. To get the
original hash instead of the object you can either add `to_h` on the
configurations call or pass `legacy: true` to `configurations.
```
ActiveRecord::Base.configurations.to_h
=> { "development => { "database" => "my_primary_db" } }
ActiveRecord::Base.configurations(legacy: true)
=> { "development => { "database" => "my_primary_db" } }
```
The new configurations object allows us to iterate over the Active
Record configurations without losing the known environment or
specification name for that configuration. You can also select all the
configs for an env or env and spec. With this we can always ask
any object what environment it belongs to:
```
db_configs = ActiveRecord::Base.configurations.configurations_for("development")
=> #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800
@configurations=[
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
@env_name="development",@spec_name="primary",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>,
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90
@env_name="development",@spec_name="animals",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
]>
db_config.env_name
=> "development"
db_config.spec_name
=> "primary"
db_config.config
=> { "adapter"=>"sqlite3", "database"=>"db/development.sqlite3" }
```
The configurations object is more flexible than the configurations hash
and will allow us to build on top of the connection management in order
to add support for primary/replica connections, sharding, and
constructing queries for associations that live in multiple databases.
2018-08-16 15:49:18 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
development:
|
|
|
|
adapter: sqlite3
|
|
|
|
database: db/development.sqlite3
|
|
|
|
```
|
|
|
|
|
|
|
|
Used to become a hash:
|
|
|
|
|
|
|
|
```
|
|
|
|
{ "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
|
|
|
|
```
|
|
|
|
|
|
|
|
Is now converted into the following object:
|
|
|
|
|
|
|
|
```
|
|
|
|
#<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
|
|
|
|
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
|
|
|
@spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
|
|
|
|
]
|
|
|
|
```
|
|
|
|
|
|
|
|
Iterating over the database configurations has also changed. Instead of
|
|
|
|
calling hash methods on the `configurations` hash directly, a new method `configs_for` has
|
2018-09-08 09:06:23 -04:00
|
|
|
been provided that allows you to select the correct configuration. `env_name`, and
|
|
|
|
`spec_name` arguments are optional. For example these return an array of
|
|
|
|
database config objects for the requested environment and a single database config object
|
|
|
|
will be returned for the requested environment and specification name respectively.
|
Refactors Active Record connection management
While the three-tier config makes it easier to define databases for
multiple database applications, it quickly became clear to offer full
support for multiple databases we need to change the way the connections
hash was handled.
A three-tier config means that when Rails needed to choose a default
configuration (in the case a user doesn't ask for a specific
configuration) it wasn't clear to Rails which the default was. I
[bandaid fixed this so the rake tasks could work](#32271) but that fix
wasn't correct because it actually doubled up the configuration hashes.
Instead of attemping to manipulate the hashes @tenderlove and I decided
that it made more sense if we converted the hashes to objects so we can
easily ask those object questions. In a three tier config like this:
```
development:
primary:
database: "my_primary_db"
animals:
database; "my_animals_db"
```
We end up with an object like this:
```
@configurations=[
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
@env_name="development",@spec_name="primary",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>,
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90
@env_name="development",@spec_name="animals",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
]>
```
The configurations setter takes the database configuration set by your
application and turns them into an
`ActiveRecord::DatabaseConfigurations` object that has one getter -
`@configurations` which is an array of all the database objects.
The configurations getter returns this object by default since it acts
like a hash in most of the cases we need. For example if you need to
access the default `development` database we can simply request it as we
did before:
```
ActiveRecord::Base.configurations["development"]
```
This will return primary development database configuration hash:
```
{ "database" => "my_primary_db" }
```
Internally all of Active Record has been converted to use the new
objects. I've built this to be backwards compatible but allow for
accessing the hash if needed for a deprecation period. To get the
original hash instead of the object you can either add `to_h` on the
configurations call or pass `legacy: true` to `configurations.
```
ActiveRecord::Base.configurations.to_h
=> { "development => { "database" => "my_primary_db" } }
ActiveRecord::Base.configurations(legacy: true)
=> { "development => { "database" => "my_primary_db" } }
```
The new configurations object allows us to iterate over the Active
Record configurations without losing the known environment or
specification name for that configuration. You can also select all the
configs for an env or env and spec. With this we can always ask
any object what environment it belongs to:
```
db_configs = ActiveRecord::Base.configurations.configurations_for("development")
=> #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800
@configurations=[
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
@env_name="development",@spec_name="primary",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>,
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90
@env_name="development",@spec_name="animals",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
]>
db_config.env_name
=> "development"
db_config.spec_name
=> "primary"
db_config.config
=> { "adapter"=>"sqlite3", "database"=>"db/development.sqlite3" }
```
The configurations object is more flexible than the configurations hash
and will allow us to build on top of the connection management in order
to add support for primary/replica connections, sharding, and
constructing queries for associations that live in multiple databases.
2018-08-16 15:49:18 -04:00
|
|
|
|
|
|
|
```
|
2018-09-08 09:06:23 -04:00
|
|
|
ActiveRecord::Base.configurations.configs_for(env_name: "development")
|
|
|
|
ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
|
Refactors Active Record connection management
While the three-tier config makes it easier to define databases for
multiple database applications, it quickly became clear to offer full
support for multiple databases we need to change the way the connections
hash was handled.
A three-tier config means that when Rails needed to choose a default
configuration (in the case a user doesn't ask for a specific
configuration) it wasn't clear to Rails which the default was. I
[bandaid fixed this so the rake tasks could work](#32271) but that fix
wasn't correct because it actually doubled up the configuration hashes.
Instead of attemping to manipulate the hashes @tenderlove and I decided
that it made more sense if we converted the hashes to objects so we can
easily ask those object questions. In a three tier config like this:
```
development:
primary:
database: "my_primary_db"
animals:
database; "my_animals_db"
```
We end up with an object like this:
```
@configurations=[
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
@env_name="development",@spec_name="primary",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>,
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90
@env_name="development",@spec_name="animals",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
]>
```
The configurations setter takes the database configuration set by your
application and turns them into an
`ActiveRecord::DatabaseConfigurations` object that has one getter -
`@configurations` which is an array of all the database objects.
The configurations getter returns this object by default since it acts
like a hash in most of the cases we need. For example if you need to
access the default `development` database we can simply request it as we
did before:
```
ActiveRecord::Base.configurations["development"]
```
This will return primary development database configuration hash:
```
{ "database" => "my_primary_db" }
```
Internally all of Active Record has been converted to use the new
objects. I've built this to be backwards compatible but allow for
accessing the hash if needed for a deprecation period. To get the
original hash instead of the object you can either add `to_h` on the
configurations call or pass `legacy: true` to `configurations.
```
ActiveRecord::Base.configurations.to_h
=> { "development => { "database" => "my_primary_db" } }
ActiveRecord::Base.configurations(legacy: true)
=> { "development => { "database" => "my_primary_db" } }
```
The new configurations object allows us to iterate over the Active
Record configurations without losing the known environment or
specification name for that configuration. You can also select all the
configs for an env or env and spec. With this we can always ask
any object what environment it belongs to:
```
db_configs = ActiveRecord::Base.configurations.configurations_for("development")
=> #<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800
@configurations=[
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
@env_name="development",@spec_name="primary",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>,
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbdea90
@env_name="development",@spec_name="animals",
@config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
]>
db_config.env_name
=> "development"
db_config.spec_name
=> "primary"
db_config.config
=> { "adapter"=>"sqlite3", "database"=>"db/development.sqlite3" }
```
The configurations object is more flexible than the configurations hash
and will allow us to build on top of the connection management in order
to add support for primary/replica connections, sharding, and
constructing queries for associations that live in multiple databases.
2018-08-16 15:49:18 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
*Eileen M. Uchitelle*, *Aaron Patterson*
|
|
|
|
|
2018-08-22 09:00:01 -04:00
|
|
|
* Add database configuration to disable advisory locks.
|
|
|
|
|
|
|
|
```
|
|
|
|
production:
|
|
|
|
adapter: postgresql
|
|
|
|
advisory_locks: false
|
|
|
|
```
|
|
|
|
|
|
|
|
*Guo Xiang*
|
|
|
|
|
2018-08-06 07:38:44 -04:00
|
|
|
* SQLite3 adapter `alter_table` method restores foreign keys.
|
|
|
|
|
|
|
|
*Yasuo Honda*
|
|
|
|
|
2018-08-14 17:29:59 -04:00
|
|
|
* Allow `:to_table` option to `invert_remove_foreign_key`.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
remove_foreign_key :accounts, to_table: :owners
|
|
|
|
|
|
|
|
*Nikolay Epifanov*, *Rich Chen*
|
|
|
|
|
2015-10-07 05:45:31 -04:00
|
|
|
* Add environment & load_config dependency to `bin/rake db:seed` to enable
|
|
|
|
seed load in environments without Rails and custom DB configuration
|
|
|
|
|
|
|
|
*Tobias Bielohlawek*
|
|
|
|
|
2018-07-08 15:06:06 -04:00
|
|
|
* Fix default value for mysql time types with specified precision.
|
2018-07-03 03:17:40 -04:00
|
|
|
|
|
|
|
*Nikolay Kondratyev*
|
|
|
|
|
2018-06-09 04:30:00 -04:00
|
|
|
* Fix `touch` option to behave consistently with `Persistence#touch` method.
|
|
|
|
|
|
|
|
*Ryuta Kamizono*
|
|
|
|
|
2018-05-30 23:49:25 -04:00
|
|
|
* Migrations raise when duplicate column definition.
|
|
|
|
|
|
|
|
Fixes #33024.
|
|
|
|
|
|
|
|
*Federico Martinez*
|
2018-06-10 07:39:10 -04:00
|
|
|
|
2018-06-01 02:55:40 -04:00
|
|
|
* Bump minimum SQLite version to 3.8
|
|
|
|
|
|
|
|
*Yasuo Honda*
|
|
|
|
|
2018-05-28 17:56:46 -04:00
|
|
|
* Fix parent record should not get saved with duplicate children records.
|
2018-05-22 09:34:24 -04:00
|
|
|
|
2018-05-28 17:56:46 -04:00
|
|
|
Fixes #32940.
|
2018-05-22 09:34:24 -04:00
|
|
|
|
|
|
|
*Santosh Wadghule*
|
|
|
|
|
2018-05-03 20:27:20 -04:00
|
|
|
* Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
|
|
|
|
|
|
|
|
*Brian Durand*
|
|
|
|
|
2018-04-17 21:56:33 -04:00
|
|
|
* Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
|
|
|
|
use loaded association ids if present.
|
|
|
|
|
|
|
|
*Graham Turner*
|
|
|
|
|
2018-04-19 20:56:49 -04:00
|
|
|
* Add support to preload associations of polymorphic associations when not all the records have the requested associations.
|
|
|
|
|
|
|
|
*Dana Sherson*
|
|
|
|
|
2017-12-19 13:42:46 -05:00
|
|
|
* Add `touch_all` method to `ActiveRecord::Relation`.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
|
|
|
|
|
|
|
|
*fatkodima*, *duggiefresh*
|
|
|
|
|
2018-04-02 10:30:24 -04:00
|
|
|
* Add `ActiveRecord::Base.base_class?` predicate.
|
2018-04-02 07:17:24 -04:00
|
|
|
|
|
|
|
*Bogdan Gusiev*
|
|
|
|
|
2018-06-12 22:03:03 -04:00
|
|
|
* Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
|
2018-03-20 02:02:23 -04:00
|
|
|
|
2018-06-12 22:03:03 -04:00
|
|
|
*Tan Huynh*, *Yukio Mizuta*
|
2018-03-20 02:02:23 -04:00
|
|
|
|
2018-12-19 15:09:34 -05:00
|
|
|
* Rails 6 requires Ruby 2.5.0 or newer.
|
2018-02-17 16:02:18 -05:00
|
|
|
|
2018-12-19 15:09:34 -05:00
|
|
|
*Jeremy Daer*, *Kasper Timm Hansen*
|
2018-02-17 16:02:18 -05:00
|
|
|
|
2018-02-14 21:33:02 -05:00
|
|
|
* Deprecate `update_attributes`/`!` in favor of `update`/`!`.
|
|
|
|
|
|
|
|
*Eddie Lebow*
|
2018-02-14 19:51:15 -05:00
|
|
|
|
2018-09-06 18:56:31 -04:00
|
|
|
* Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
|
|
|
|
`ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
|
2018-02-14 19:51:15 -05:00
|
|
|
|
|
|
|
*DHH*
|
2018-01-29 07:28:42 -05:00
|
|
|
|
2018-02-18 10:01:46 -05:00
|
|
|
* Add `Relation#pick` as short-hand for single-value plucks.
|
|
|
|
|
|
|
|
*DHH*
|
|
|
|
|
2018-01-29 07:28:42 -05:00
|
|
|
|
2018-01-30 18:51:17 -05:00
|
|
|
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.
|