activerecord 6.0.3.4 → 6.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +891 -695
- data/MIT-LICENSE +1 -1
- data/README.rdoc +3 -3
- data/lib/active_record.rb +7 -14
- data/lib/active_record/aggregations.rb +5 -5
- data/lib/active_record/association_relation.rb +30 -12
- data/lib/active_record/associations.rb +118 -11
- data/lib/active_record/associations/alias_tracker.rb +19 -15
- data/lib/active_record/associations/association.rb +44 -28
- data/lib/active_record/associations/association_scope.rb +19 -15
- data/lib/active_record/associations/belongs_to_association.rb +22 -8
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -3
- data/lib/active_record/associations/builder/association.rb +32 -5
- data/lib/active_record/associations/builder/belongs_to.rb +10 -7
- data/lib/active_record/associations/builder/collection_association.rb +5 -4
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +0 -1
- data/lib/active_record/associations/builder/has_many.rb +6 -2
- data/lib/active_record/associations/builder/has_one.rb +11 -14
- data/lib/active_record/associations/builder/singular_association.rb +1 -1
- data/lib/active_record/associations/collection_association.rb +19 -6
- data/lib/active_record/associations/collection_proxy.rb +13 -5
- data/lib/active_record/associations/foreign_association.rb +13 -0
- data/lib/active_record/associations/has_many_association.rb +24 -2
- data/lib/active_record/associations/has_many_through_association.rb +10 -4
- data/lib/active_record/associations/has_one_association.rb +15 -1
- data/lib/active_record/associations/join_dependency.rb +72 -50
- data/lib/active_record/associations/join_dependency/join_association.rb +39 -16
- data/lib/active_record/associations/join_dependency/join_part.rb +3 -3
- data/lib/active_record/associations/preloader.rb +11 -5
- data/lib/active_record/associations/preloader/association.rb +51 -25
- data/lib/active_record/associations/preloader/through_association.rb +2 -2
- data/lib/active_record/associations/singular_association.rb +1 -1
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/attribute_assignment.rb +10 -8
- data/lib/active_record/attribute_methods.rb +64 -54
- data/lib/active_record/attribute_methods/before_type_cast.rb +13 -9
- data/lib/active_record/attribute_methods/dirty.rb +1 -11
- data/lib/active_record/attribute_methods/primary_key.rb +6 -2
- data/lib/active_record/attribute_methods/query.rb +3 -6
- data/lib/active_record/attribute_methods/read.rb +8 -11
- data/lib/active_record/attribute_methods/serialization.rb +11 -5
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +12 -13
- data/lib/active_record/attribute_methods/write.rb +12 -20
- data/lib/active_record/attributes.rb +33 -8
- data/lib/active_record/autosave_association.rb +57 -40
- data/lib/active_record/base.rb +2 -14
- data/lib/active_record/callbacks.rb +152 -22
- data/lib/active_record/coders/yaml_column.rb +1 -1
- data/lib/active_record/connection_adapters.rb +50 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +191 -134
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +2 -44
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +65 -22
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +3 -8
- data/lib/active_record/connection_adapters/abstract/quoting.rb +34 -34
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +3 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +153 -116
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +116 -27
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +3 -3
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +228 -83
- data/lib/active_record/connection_adapters/abstract/transaction.rb +80 -32
- data/lib/active_record/connection_adapters/abstract_adapter.rb +54 -72
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +133 -96
- data/lib/active_record/connection_adapters/column.rb +15 -1
- data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
- data/lib/active_record/connection_adapters/legacy_pool_manager.rb +31 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +23 -25
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/quoting.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +32 -6
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +8 -0
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +5 -2
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +11 -7
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +10 -1
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +31 -12
- data/lib/active_record/connection_adapters/pool_config.rb +73 -0
- data/lib/active_record/connection_adapters/pool_manager.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/column.rb +24 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +13 -54
- data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -5
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +10 -2
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +24 -5
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +11 -1
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +4 -4
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +5 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +61 -29
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +8 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +73 -58
- data/lib/active_record/connection_adapters/schema_cache.rb +98 -15
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +10 -0
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +31 -6
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +1 -1
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +5 -1
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +37 -4
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +49 -50
- data/lib/active_record/connection_handling.rb +218 -71
- data/lib/active_record/core.rb +245 -61
- data/lib/active_record/database_configurations.rb +124 -85
- data/lib/active_record/database_configurations/connection_url_resolver.rb +98 -0
- data/lib/active_record/database_configurations/database_config.rb +52 -9
- data/lib/active_record/database_configurations/hash_config.rb +54 -8
- data/lib/active_record/database_configurations/url_config.rb +15 -40
- data/lib/active_record/delegated_type.rb +209 -0
- data/lib/active_record/destroy_association_async_job.rb +36 -0
- data/lib/active_record/enum.rb +82 -38
- data/lib/active_record/errors.rb +47 -12
- data/lib/active_record/explain.rb +9 -4
- data/lib/active_record/explain_subscriber.rb +1 -1
- data/lib/active_record/fixture_set/file.rb +10 -17
- data/lib/active_record/fixture_set/model_metadata.rb +1 -2
- data/lib/active_record/fixture_set/render_context.rb +1 -1
- data/lib/active_record/fixture_set/table_row.rb +2 -2
- data/lib/active_record/fixtures.rb +58 -9
- data/lib/active_record/gem_version.rb +3 -3
- data/lib/active_record/inheritance.rb +40 -18
- data/lib/active_record/insert_all.rb +35 -6
- data/lib/active_record/integration.rb +3 -5
- data/lib/active_record/internal_metadata.rb +16 -7
- data/lib/active_record/legacy_yaml_adapter.rb +7 -3
- data/lib/active_record/locking/optimistic.rb +33 -17
- data/lib/active_record/locking/pessimistic.rb +6 -2
- data/lib/active_record/log_subscriber.rb +27 -8
- data/lib/active_record/middleware/database_selector.rb +4 -1
- data/lib/active_record/middleware/database_selector/resolver.rb +5 -0
- data/lib/active_record/middleware/database_selector/resolver/session.rb +3 -0
- data/lib/active_record/migration.rb +113 -83
- data/lib/active_record/migration/command_recorder.rb +47 -27
- data/lib/active_record/migration/compatibility.rb +68 -17
- data/lib/active_record/model_schema.rb +117 -13
- data/lib/active_record/nested_attributes.rb +2 -3
- data/lib/active_record/no_touching.rb +1 -1
- data/lib/active_record/persistence.rb +50 -45
- data/lib/active_record/query_cache.rb +15 -5
- data/lib/active_record/querying.rb +11 -6
- data/lib/active_record/railtie.rb +64 -44
- data/lib/active_record/railties/console_sandbox.rb +2 -4
- data/lib/active_record/railties/databases.rake +276 -99
- data/lib/active_record/readonly_attributes.rb +4 -0
- data/lib/active_record/reflection.rb +71 -57
- data/lib/active_record/relation.rb +96 -67
- data/lib/active_record/relation/batches.rb +38 -31
- data/lib/active_record/relation/batches/batch_enumerator.rb +25 -9
- data/lib/active_record/relation/calculations.rb +101 -44
- data/lib/active_record/relation/delegation.rb +2 -1
- data/lib/active_record/relation/finder_methods.rb +45 -15
- data/lib/active_record/relation/from_clause.rb +1 -1
- data/lib/active_record/relation/merger.rb +27 -25
- data/lib/active_record/relation/predicate_builder.rb +59 -38
- data/lib/active_record/relation/predicate_builder/array_handler.rb +8 -9
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +4 -5
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +10 -6
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
- data/lib/active_record/relation/query_methods.rb +333 -195
- data/lib/active_record/relation/record_fetch_warning.rb +3 -3
- data/lib/active_record/relation/spawn_methods.rb +8 -7
- data/lib/active_record/relation/where_clause.rb +104 -57
- data/lib/active_record/result.rb +41 -33
- data/lib/active_record/runtime_registry.rb +2 -2
- data/lib/active_record/sanitization.rb +6 -17
- data/lib/active_record/schema_dumper.rb +34 -4
- data/lib/active_record/schema_migration.rb +2 -8
- data/lib/active_record/scoping/named.rb +6 -17
- data/lib/active_record/secure_token.rb +16 -8
- data/lib/active_record/serialization.rb +5 -3
- data/lib/active_record/signed_id.rb +116 -0
- data/lib/active_record/statement_cache.rb +20 -4
- data/lib/active_record/store.rb +2 -2
- data/lib/active_record/suppressor.rb +2 -2
- data/lib/active_record/table_metadata.rb +42 -51
- data/lib/active_record/tasks/database_tasks.rb +140 -113
- data/lib/active_record/tasks/mysql_database_tasks.rb +34 -35
- data/lib/active_record/tasks/postgresql_database_tasks.rb +24 -26
- data/lib/active_record/tasks/sqlite_database_tasks.rb +13 -9
- data/lib/active_record/test_databases.rb +5 -4
- data/lib/active_record/test_fixtures.rb +37 -16
- data/lib/active_record/timestamp.rb +4 -6
- data/lib/active_record/touch_later.rb +21 -21
- data/lib/active_record/transactions.rb +19 -66
- data/lib/active_record/type.rb +8 -1
- data/lib/active_record/type/serialized.rb +6 -2
- data/lib/active_record/type/time.rb +10 -0
- data/lib/active_record/type_caster/connection.rb +0 -1
- data/lib/active_record/type_caster/map.rb +8 -5
- data/lib/active_record/validations.rb +1 -0
- data/lib/active_record/validations/numericality.rb +35 -0
- data/lib/active_record/validations/uniqueness.rb +24 -4
- data/lib/arel.rb +5 -13
- data/lib/arel/attributes/attribute.rb +4 -0
- data/lib/arel/collectors/bind.rb +5 -0
- data/lib/arel/collectors/composite.rb +8 -0
- data/lib/arel/collectors/sql_string.rb +7 -0
- data/lib/arel/collectors/substitute_binds.rb +7 -0
- data/lib/arel/nodes.rb +3 -1
- data/lib/arel/nodes/binary.rb +82 -8
- data/lib/arel/nodes/bind_param.rb +8 -0
- data/lib/arel/nodes/casted.rb +21 -9
- data/lib/arel/nodes/equality.rb +6 -9
- data/lib/arel/nodes/grouping.rb +3 -0
- data/lib/arel/nodes/homogeneous_in.rb +72 -0
- data/lib/arel/nodes/in.rb +8 -1
- data/lib/arel/nodes/infix_operation.rb +13 -1
- data/lib/arel/nodes/join_source.rb +1 -1
- data/lib/arel/nodes/node.rb +7 -6
- data/lib/arel/nodes/ordering.rb +27 -0
- data/lib/arel/nodes/sql_literal.rb +3 -0
- data/lib/arel/nodes/table_alias.rb +7 -3
- data/lib/arel/nodes/unary.rb +0 -1
- data/lib/arel/predications.rb +12 -18
- data/lib/arel/select_manager.rb +1 -2
- data/lib/arel/table.rb +13 -5
- data/lib/arel/visitors.rb +0 -7
- data/lib/arel/visitors/dot.rb +14 -2
- data/lib/arel/visitors/mysql.rb +11 -1
- data/lib/arel/visitors/postgresql.rb +15 -4
- data/lib/arel/visitors/to_sql.rb +89 -78
- data/lib/rails/generators/active_record/migration.rb +6 -1
- data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -0
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +2 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +3 -3
- data/lib/rails/generators/active_record/model/model_generator.rb +39 -2
- data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +7 -0
- metadata +25 -26
- data/lib/active_record/advisory_lock_base.rb +0 -18
- data/lib/active_record/attribute_decorators.rb +0 -88
- data/lib/active_record/connection_adapters/connection_specification.rb +0 -296
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -29
- data/lib/active_record/define_callbacks.rb +0 -22
- data/lib/active_record/railties/collection_cache_association_loading.rb +0 -34
- data/lib/active_record/relation/predicate_builder/base_handler.rb +0 -18
- data/lib/active_record/relation/where_clause_factory.rb +0 -33
- data/lib/arel/attributes.rb +0 -22
- data/lib/arel/visitors/depth_first.rb +0 -203
- data/lib/arel/visitors/ibm_db.rb +0 -34
- data/lib/arel/visitors/informix.rb +0 -62
- data/lib/arel/visitors/mssql.rb +0 -156
- data/lib/arel/visitors/oracle.rb +0 -158
- data/lib/arel/visitors/oracle12.rb +0 -65
- data/lib/arel/visitors/where_sql.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4112bd4b4d7a00b26db10332f2f6452d2b6ad1fdf3f2ad50988a8229abac9192
|
4
|
+
data.tar.gz: 6fbcb021ae1942e307730ef7aaad54d1f594cd52b749d407f8aafe052bee6794
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb1830fe0587253ecede381d53dd0be5c8de80070559458653d4a6e149c002a03a3ba37a8723e0e869693500b55ec9956f9f18d2d556884f40d28ac9af0e34f6
|
7
|
+
data.tar.gz: d78aeab68b5c4d4d0e2d8a315b7175a0257b6e1bb6db82c1ae04551f44540d72ffd122881af9cfb93cf8c0d8d57b6310a5bd303e612e24795f54fc07b777f307
|
data/CHANGELOG.md
CHANGED
@@ -1,1217 +1,1413 @@
|
|
1
|
-
## Rails 6.
|
1
|
+
## Rails 6.1.2 (February 09, 2021) ##
|
2
2
|
|
3
|
-
*
|
3
|
+
* Fix timestamp type for sqlite3.
|
4
4
|
|
5
|
+
*Eileen M. Uchitelle*
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
* No changes.
|
9
|
-
|
7
|
+
* Make destroy async transactional.
|
10
8
|
|
11
|
-
|
9
|
+
An active record rollback could occur while enqueuing a job. In this
|
10
|
+
case the job would enqueue even though the database deletion
|
11
|
+
rolledback putting things in a funky state.
|
12
12
|
|
13
|
-
|
13
|
+
Now the jobs are only enqueued until after the db transaction has been committed.
|
14
14
|
|
15
|
+
*Cory Gwin*
|
15
16
|
|
16
|
-
|
17
|
+
* Fix malformed packet error in MySQL statement for connection configuration.
|
17
18
|
|
18
|
-
*
|
19
|
+
*robinroestenburg*
|
19
20
|
|
21
|
+
* Connection specification now passes the "url" key as a configuration for the
|
22
|
+
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
|
23
|
+
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
|
24
|
+
are assumed to be adapter specification urls.
|
20
25
|
|
21
|
-
|
26
|
+
Fixes #41137.
|
22
27
|
|
23
|
-
*
|
28
|
+
*Jonathan Bracy*
|
24
29
|
|
25
|
-
|
30
|
+
* Fix granular connection swapping when there are multiple abstract classes.
|
26
31
|
|
27
32
|
*Eileen M. Uchitelle*
|
28
33
|
|
29
|
-
* Fix
|
34
|
+
* Fix `find_by` with custom primary key for belongs_to association.
|
30
35
|
|
31
|
-
*
|
36
|
+
*Ryuta Kamizono*
|
32
37
|
|
33
|
-
* Add support for
|
38
|
+
* Add support for `rails console --sandbox` for multiple database applications.
|
34
39
|
|
35
|
-
*
|
40
|
+
*alpaca-tc*
|
36
41
|
|
37
|
-
* Fix
|
42
|
+
* Fix `where` on polymorphic association with empty array.
|
38
43
|
|
39
|
-
|
44
|
+
*Ryuta Kamizono*
|
40
45
|
|
41
|
-
|
46
|
+
* Fix preventing writes for `ApplicationRecord`.
|
42
47
|
|
43
|
-
*
|
48
|
+
*Eileen M. Uchitelle*
|
44
49
|
|
45
|
-
Add `Regexp.escape` to one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods like `pluck` and `select` fail in certain cases when used with the MS SQL Server adapter.
|
46
50
|
|
47
|
-
|
51
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
48
52
|
|
49
|
-
*
|
53
|
+
* Fix fixtures loading when strict loading is enabled for the association.
|
50
54
|
|
51
|
-
|
55
|
+
*Alex Ghiculescu*
|
52
56
|
|
53
|
-
|
57
|
+
* Fix `where` with custom primary key for belongs_to association.
|
54
58
|
|
55
|
-
*
|
59
|
+
*Ryuta Kamizono*
|
56
60
|
|
57
|
-
*
|
61
|
+
* Fix `where` with aliased associations.
|
58
62
|
|
59
|
-
|
63
|
+
*Ryuta Kamizono*
|
60
64
|
|
61
|
-
|
65
|
+
* Fix `composed_of` with symbol mapping.
|
62
66
|
|
63
|
-
*
|
64
|
-
ActiveRecord::Relation#cache_key_with_version. This method will be used by
|
65
|
-
ActionController::ConditionalGet to ensure that when collection cache versioning
|
66
|
-
is enabled, requests using ConditionalGet don't return the same ETag header
|
67
|
-
after a collection is modified. Fixes #38078.
|
67
|
+
*Ryuta Kamizono*
|
68
68
|
|
69
|
-
|
69
|
+
* Don't skip money's type cast for pluck and calculations.
|
70
70
|
|
71
|
-
*
|
71
|
+
*Ryuta Kamizono*
|
72
72
|
|
73
|
-
|
73
|
+
* Fix `where` on polymorphic association with non Active Record object.
|
74
74
|
|
75
|
-
*
|
75
|
+
*Ryuta Kamizono*
|
76
76
|
|
77
|
-
|
77
|
+
* Make sure `db:prepare` works even the schema file doesn't exist.
|
78
78
|
|
79
|
-
*
|
79
|
+
*Rafael Mendonça França*
|
80
80
|
|
81
|
+
* Fix complicated `has_many :through` with nested where condition.
|
81
82
|
|
82
|
-
|
83
|
+
*Ryuta Kamizono*
|
83
84
|
|
84
|
-
*
|
85
|
+
* Handle STI models for `has_many dependent: :destroy_async`.
|
85
86
|
|
87
|
+
*Muhammad Usman*
|
86
88
|
|
87
|
-
|
89
|
+
* Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
|
88
90
|
|
89
|
-
|
91
|
+
Previously, passing `false` would trigger the option validation logic
|
92
|
+
to throw an error saying :polymorphic would not be a valid option.
|
90
93
|
|
94
|
+
*glaszig*
|
91
95
|
|
92
|
-
|
96
|
+
* Allow adding nonnamed expression indexes to be revertible.
|
93
97
|
|
94
|
-
|
95
|
-
transactional tests for the same database.
|
98
|
+
Fixes #40732.
|
96
99
|
|
97
|
-
|
100
|
+
Previously, the following code would raise an error, when executed while rolling back,
|
101
|
+
and the index name should be specified explicitly. Now, the index name is inferred
|
102
|
+
automatically.
|
98
103
|
|
99
|
-
|
100
|
-
|
104
|
+
```ruby
|
105
|
+
add_index(:items, "to_tsvector('english', description)")
|
106
|
+
```
|
101
107
|
|
102
|
-
*
|
108
|
+
*fatkodima*
|
103
109
|
|
104
|
-
* Fix collection callbacks not terminating when `:abort` is thrown.
|
105
110
|
|
106
|
-
|
111
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
107
112
|
|
108
|
-
*
|
113
|
+
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
109
114
|
|
110
|
-
|
111
|
-
doing a relation query like `where.not(relation: { ... })`
|
112
|
-
wouldn't be properly deprecated and `where.not` would work as
|
113
|
-
NAND instead.
|
115
|
+
Fixes #39065.
|
114
116
|
|
115
|
-
*
|
117
|
+
*Alex Ghiculescu*
|
116
118
|
|
117
|
-
*
|
118
|
-
to the previous database.
|
119
|
+
* Change `attribute_for_inspect` to take `filter_attributes` in consideration.
|
119
120
|
|
120
|
-
|
121
|
-
resulting in the last one to be used by subsequent rake tasks.
|
122
|
-
We should reestablish a connection to the connection that was
|
123
|
-
established before the migrate tasks was run
|
121
|
+
*Rafael Mendonça França*
|
124
122
|
|
125
|
-
|
123
|
+
* Fix odd behavior of inverse_of with multiple belongs_to to same class.
|
126
124
|
|
127
|
-
|
125
|
+
Fixes #35204.
|
128
126
|
|
129
|
-
*
|
127
|
+
*Tomoyuki Kai*
|
130
128
|
|
129
|
+
* Build predicate conditions with objects that delegate `#id` and primary key:
|
131
130
|
|
132
|
-
|
131
|
+
```ruby
|
132
|
+
class AdminAuthor
|
133
|
+
delegate_missing_to :@author
|
133
134
|
|
134
|
-
|
135
|
+
def initialize(author)
|
136
|
+
@author = author
|
137
|
+
end
|
138
|
+
end
|
135
139
|
|
136
|
-
|
140
|
+
Post.where(author: AdminAuthor.new(author))
|
141
|
+
```
|
137
142
|
|
138
|
-
*
|
143
|
+
*Sean Doyle*
|
139
144
|
|
140
|
-
|
145
|
+
* Add `connected_to_many` API.
|
141
146
|
|
142
|
-
|
147
|
+
This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
|
143
148
|
|
144
|
-
|
149
|
+
Before:
|
145
150
|
|
146
|
-
|
147
|
-
|
151
|
+
AnimalsRecord.connected_to(role: :reading) do
|
152
|
+
MealsRecord.connected_to(role: :reading) do
|
153
|
+
Dog.first # read from animals replica
|
154
|
+
Dinner.first # read from meals replica
|
155
|
+
Person.first # read from primary writer
|
156
|
+
end
|
157
|
+
end
|
148
158
|
|
149
|
-
|
159
|
+
After:
|
150
160
|
|
151
|
-
|
152
|
-
|
161
|
+
ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
|
162
|
+
Dog.first # read from animals replica
|
163
|
+
Dinner.first # read from meals replica
|
164
|
+
Person.first # read from primary writer
|
165
|
+
end
|
153
166
|
|
154
|
-
|
167
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
155
168
|
|
156
|
-
*
|
157
|
-
previously-committed record state.
|
169
|
+
* Add option to raise or log for `ActiveRecord::StrictLoadingViolationError`.
|
158
170
|
|
159
|
-
|
171
|
+
Some applications may not want to raise an error in production if using `strict_loading`. This would allow an application to set strict loading to log for the production environment while still raising in development and test environments.
|
160
172
|
|
161
|
-
|
173
|
+
Set `config.active_record.action_on_strict_loading_violation` to `:log` errors instead of raising.
|
162
174
|
|
163
|
-
|
175
|
+
*Eileen M. Uchitelle*
|
164
176
|
|
165
|
-
* `
|
177
|
+
* Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
|
166
178
|
|
167
|
-
|
179
|
+
Fixes #34255.
|
168
180
|
|
169
|
-
*
|
181
|
+
*Steven Weber*
|
170
182
|
|
171
|
-
|
183
|
+
* Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
|
172
184
|
|
173
|
-
|
174
|
-
fixes that idle connections in forked processes wouldn't be reaped.
|
185
|
+
Because the default behaviour when adding an index with multiple columns is to use all column names in the index name, this could frequently lead to overly long index names for polymorphic references which would fail the migration if it exceeded the database limit.
|
175
186
|
|
176
|
-
|
187
|
+
This change reduces the chance of that happening by using the reference name, e.g. `index_my_table_on_my_reference`.
|
177
188
|
|
178
|
-
|
179
|
-
when `ActiveRecord::Relation#reset` or `ActiveRecord::Relation#reload`
|
180
|
-
is called.
|
189
|
+
Fixes #38655.
|
181
190
|
|
182
|
-
*
|
191
|
+
*Luke Redpath*
|
183
192
|
|
184
|
-
*
|
193
|
+
* MySQL: Uniqueness validator now respects default database collation,
|
194
|
+
no longer enforce case sensitive comparison by default.
|
185
195
|
|
186
|
-
*
|
196
|
+
*Ryuta Kamizono*
|
187
197
|
|
188
|
-
*
|
198
|
+
* Remove deprecated methods from `ActiveRecord::ConnectionAdapters::DatabaseLimits`.
|
189
199
|
|
190
|
-
|
200
|
+
`column_name_length`
|
201
|
+
`table_name_length`
|
202
|
+
`columns_per_table`
|
203
|
+
`indexes_per_table`
|
204
|
+
`columns_per_multicolumn_index`
|
205
|
+
`sql_query_length`
|
206
|
+
`joins_per_query`
|
191
207
|
|
192
|
-
*
|
208
|
+
*Rafael Mendonça França*
|
193
209
|
|
194
|
-
|
210
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?`.
|
195
211
|
|
196
|
-
|
212
|
+
*Rafael Mendonça França*
|
197
213
|
|
198
|
-
|
214
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?`.
|
199
215
|
|
200
|
-
*
|
216
|
+
*Rafael Mendonça França*
|
201
217
|
|
202
|
-
|
218
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?`.
|
203
219
|
|
220
|
+
*Rafael Mendonça França*
|
204
221
|
|
205
|
-
|
222
|
+
* Remove deprecated `ActiveRecord::Base#update_attributes` and `ActiveRecord::Base#update_attributes!`.
|
206
223
|
|
207
|
-
*
|
224
|
+
*Rafael Mendonça França*
|
208
225
|
|
209
|
-
|
226
|
+
* Remove deprecated `migrations_path` argument in `ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version`.
|
210
227
|
|
211
|
-
*
|
228
|
+
*Rafael Mendonça França*
|
212
229
|
|
213
|
-
*
|
230
|
+
* Remove deprecated `config.active_record.sqlite3.represent_boolean_as_integer`.
|
214
231
|
|
215
|
-
*
|
232
|
+
*Rafael Mendonça França*
|
216
233
|
|
217
|
-
*
|
234
|
+
* `relation.create` does no longer leak scope to class level querying methods
|
235
|
+
in initialization block and callbacks.
|
218
236
|
|
219
|
-
|
220
|
-
|
237
|
+
Before:
|
238
|
+
|
239
|
+
User.where(name: "John").create do |john|
|
240
|
+
User.find_by(name: "David") # => nil
|
221
241
|
end
|
222
242
|
|
223
|
-
|
243
|
+
After:
|
224
244
|
|
225
|
-
|
245
|
+
User.where(name: "John").create do |john|
|
246
|
+
User.find_by(name: "David") # => #<User name: "David", ...>
|
247
|
+
end
|
226
248
|
|
227
|
-
*
|
249
|
+
*Ryuta Kamizono*
|
228
250
|
|
251
|
+
* Named scope chain does no longer leak scope to class level querying methods.
|
229
252
|
|
230
|
-
|
253
|
+
class User < ActiveRecord::Base
|
254
|
+
scope :david, -> { User.where(name: "David") }
|
255
|
+
end
|
231
256
|
|
232
|
-
|
257
|
+
Before:
|
233
258
|
|
234
|
-
|
259
|
+
User.where(name: "John").david
|
260
|
+
# SELECT * FROM users WHERE name = 'John' AND name = 'David'
|
235
261
|
|
236
|
-
|
262
|
+
After:
|
237
263
|
|
238
|
-
|
264
|
+
User.where(name: "John").david
|
265
|
+
# SELECT * FROM users WHERE name = 'David'
|
239
266
|
|
240
267
|
*Ryuta Kamizono*
|
241
268
|
|
242
|
-
*
|
269
|
+
* Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`.
|
243
270
|
|
244
|
-
|
271
|
+
`fetch`
|
272
|
+
`each`
|
273
|
+
`first`
|
274
|
+
`values`
|
275
|
+
`[]=`
|
245
276
|
|
246
|
-
*
|
277
|
+
*Rafael Mendonça França*
|
247
278
|
|
248
|
-
*
|
279
|
+
* `where.not` now generates NAND predicates instead of NOR.
|
249
280
|
|
250
|
-
|
281
|
+
Before:
|
251
282
|
|
252
|
-
|
283
|
+
User.where.not(name: "Jon", role: "admin")
|
284
|
+
# SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
|
253
285
|
|
254
|
-
|
286
|
+
After:
|
255
287
|
|
256
|
-
|
288
|
+
User.where.not(name: "Jon", role: "admin")
|
289
|
+
# SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
|
257
290
|
|
258
|
-
*
|
291
|
+
*Rafael Mendonça França*
|
259
292
|
|
260
|
-
|
293
|
+
* Remove deprecated `ActiveRecord::Result#to_hash` method.
|
261
294
|
|
262
|
-
*
|
295
|
+
*Rafael Mendonça França*
|
263
296
|
|
264
|
-
|
297
|
+
* Deprecate `ActiveRecord::Base.allow_unsafe_raw_sql`.
|
265
298
|
|
266
|
-
*
|
299
|
+
*Rafael Mendonça França*
|
300
|
+
|
301
|
+
* Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.
|
302
|
+
|
303
|
+
*Rafael Mendonça França*
|
267
304
|
|
305
|
+
* Allow users to silence the "Rails couldn't infer whether you are using multiple databases..."
|
306
|
+
message using `config.active_record.suppress_multiple_database_warning`.
|
268
307
|
|
269
|
-
|
308
|
+
*Omri Gabay*
|
270
309
|
|
271
|
-
*
|
310
|
+
* Connections can be granularly switched for abstract classes when `connected_to` is called.
|
272
311
|
|
273
|
-
|
312
|
+
This change allows `connected_to` to switch a `role` and/or `shard` for a single abstract class instead of all classes globally. Applications that want to use the new feature need to set `config.active_record.legacy_connection_handling` to `false` in their application configuration.
|
274
313
|
|
275
|
-
|
314
|
+
Example usage:
|
315
|
+
|
316
|
+
Given an application we have a `User` model that inherits from `ApplicationRecord` and a `Dog` model that inherits from `AnimalsRecord`. `AnimalsRecord` and `ApplicationRecord` have writing and reading connections as well as shard `default`, `one`, and `two`.
|
276
317
|
|
277
318
|
```ruby
|
278
|
-
|
279
|
-
|
319
|
+
ActiveRecord::Base.connected_to(role: :reading) do
|
320
|
+
User.first # reads from default replica
|
321
|
+
Dog.first # reads from default replica
|
322
|
+
|
323
|
+
AnimalsRecord.connected_to(role: :writing, shard: :one) do
|
324
|
+
User.first # reads from default replica
|
325
|
+
Dog.first # reads from shard one primary
|
326
|
+
end
|
327
|
+
|
328
|
+
User.first # reads from default replica
|
329
|
+
Dog.first # reads from default replica
|
330
|
+
|
331
|
+
ApplicationRecord.connected_to(role: :writing, shard: :two) do
|
332
|
+
User.first # reads from shard two primary
|
333
|
+
Dog.first # reads from default replica
|
334
|
+
end
|
335
|
+
end
|
280
336
|
```
|
281
337
|
|
282
|
-
|
338
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
339
|
+
|
340
|
+
* Allow double-dash comment syntax when querying read-only databases
|
341
|
+
|
342
|
+
*James Adam*
|
343
|
+
|
344
|
+
* Add `values_at` method.
|
345
|
+
|
346
|
+
Returns an array containing the values associated with the given methods.
|
283
347
|
|
284
348
|
```ruby
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
e.estimate_of_type == sapphire.class.polymorphic_name
|
289
|
-
}.reject { |e|
|
290
|
-
e.estimate_of_id == sapphire.id
|
291
|
-
}
|
292
|
-
assert_equal [cars(:honda)], nor
|
293
|
-
|
294
|
-
without_sapphire = PriceEstimate.where.not(
|
295
|
-
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
296
|
-
)
|
297
|
-
assert_equal nor, without_sapphire.map(&:estimate_of)
|
349
|
+
topic = Topic.first
|
350
|
+
topic.values_at(:title, :author_name)
|
351
|
+
# => ["Budget", "Jason"]
|
298
352
|
```
|
299
353
|
|
300
|
-
|
354
|
+
Similar to `Hash#values_at` but on an Active Record instance.
|
355
|
+
|
356
|
+
*Guillaume Briday*
|
357
|
+
|
358
|
+
* Fix `read_attribute_before_type_cast` to consider attribute aliases.
|
359
|
+
|
360
|
+
*Marcelo Lauxen*
|
361
|
+
|
362
|
+
* Support passing record to uniqueness validator `:conditions` callable:
|
301
363
|
|
302
364
|
```ruby
|
303
|
-
|
365
|
+
class Article < ApplicationRecord
|
366
|
+
validates_uniqueness_of :title, conditions: ->(article) {
|
367
|
+
published_at = article.published_at
|
368
|
+
where(published_at: published_at.beginning_of_year..published_at.end_of_year)
|
369
|
+
}
|
370
|
+
end
|
371
|
+
```
|
304
372
|
|
305
|
-
|
306
|
-
assert_equal [treasures(:diamond), cars(:honda)], nand
|
373
|
+
*Eliot Sykes*
|
307
374
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
375
|
+
* `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
|
376
|
+
total number of rows affected, just like their non-batched counterparts.
|
377
|
+
|
378
|
+
```ruby
|
379
|
+
Person.in_batches.update_all("first_name = 'Eugene'") # => 42
|
380
|
+
Person.in_batches.delete_all # => 42
|
312
381
|
```
|
313
382
|
|
314
|
-
|
383
|
+
Fixes #40287.
|
315
384
|
|
316
|
-
*
|
385
|
+
*Eugene Kenny*
|
317
386
|
|
318
|
-
|
387
|
+
* Add support for PostgreSQL `interval` data type with conversion to
|
388
|
+
`ActiveSupport::Duration` when loading records from database and
|
389
|
+
serialization to ISO 8601 formatted duration string on save.
|
390
|
+
Add support to define a column in migrations and get it in a schema dump.
|
391
|
+
Optional column precision is supported.
|
319
392
|
|
320
|
-
|
393
|
+
To use this in 6.1, you need to place the next string to your model file:
|
321
394
|
|
322
|
-
|
323
|
-
the versioned entries in `ActiveSupport::Cache`. This also means that
|
324
|
-
`ActiveRecord::Relation#cache_key` will now return a stable key that does not
|
325
|
-
include the max timestamp or count any more.
|
395
|
+
attribute :duration, :interval
|
326
396
|
|
327
|
-
|
328
|
-
cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
|
329
|
-
That's the setting for all new apps on Rails 6.0+
|
397
|
+
To keep old behavior until 6.2 is released:
|
330
398
|
|
331
|
-
|
399
|
+
attribute :duration, :string
|
332
400
|
|
333
|
-
|
401
|
+
Example:
|
334
402
|
|
335
|
-
|
403
|
+
create_table :events do |t|
|
404
|
+
t.string :name
|
405
|
+
t.interval :duration
|
406
|
+
end
|
336
407
|
|
337
|
-
|
408
|
+
class Event < ApplicationRecord
|
409
|
+
attribute :duration, :interval
|
410
|
+
end
|
338
411
|
|
339
|
-
|
340
|
-
|
412
|
+
Event.create!(name: 'Rock Fest', duration: 2.days)
|
413
|
+
Event.last.duration # => 2 days
|
414
|
+
Event.last.duration.iso8601 # => "P2D"
|
415
|
+
Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
|
416
|
+
Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
|
341
417
|
|
342
|
-
*
|
418
|
+
*Andrey Novikov*
|
343
419
|
|
344
|
-
*
|
420
|
+
* Allow associations supporting the `dependent:` key to take `dependent: :destroy_async`.
|
345
421
|
|
346
|
-
|
422
|
+
```ruby
|
423
|
+
class Account < ActiveRecord::Base
|
424
|
+
belongs_to :supplier, dependent: :destroy_async
|
425
|
+
end
|
426
|
+
```
|
347
427
|
|
348
|
-
|
428
|
+
`:destroy_async` will enqueue a job to destroy associated records in the background.
|
349
429
|
|
350
|
-
*
|
430
|
+
*DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
|
351
431
|
|
352
|
-
|
353
|
-
associations, the callback for a `has_many` association was run while
|
354
|
-
another instance of the same callback on the same association hadn't
|
355
|
-
finished running. When control returned to the first instance of the
|
356
|
-
callback, the instance variable had changed, and subsequent associated
|
357
|
-
records weren't saved correctly. Specifically, the ID field for the
|
358
|
-
`belongs_to` corresponding to the `has_many` was `nil`.
|
432
|
+
* Add `SKIP_TEST_DATABASE` environment variable to disable modifying the test database when `rails db:create` and `rails db:drop` are called.
|
359
433
|
|
360
|
-
|
434
|
+
*Jason Schweier*
|
361
435
|
|
362
|
-
|
436
|
+
* `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
|
363
437
|
|
364
|
-
|
438
|
+
Ensure that `connects_to` can only be called from `ActiveRecord::Base` or abstract classes. This protects the application from opening duplicate or too many connections.
|
365
439
|
|
366
|
-
|
440
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
367
441
|
|
368
|
-
|
369
|
-
|
370
|
-
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
371
|
-
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
|
372
|
-
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
|
373
|
-
```
|
442
|
+
* All connection adapters `execute` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
443
|
+
`ActiveRecord::StatementInvalid` when they encounter a connection error.
|
374
444
|
|
375
|
-
|
445
|
+
*Jean Boussier*
|
446
|
+
|
447
|
+
* `Mysql2Adapter#quote_string` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
448
|
+
`ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
|
449
|
+
|
450
|
+
*Jean Boussier*
|
451
|
+
|
452
|
+
* Add support for check constraints that are `NOT VALID` via `validate: false` (PostgreSQL-only).
|
453
|
+
|
454
|
+
*Alex Robbin*
|
455
|
+
|
456
|
+
* Ensure the default configuration is considered primary or first for an environment
|
457
|
+
|
458
|
+
If a multiple database application provides a configuration named primary, that will be treated as default. In applications that do not have a primary entry, the default database configuration will be the first configuration for an environment.
|
459
|
+
|
460
|
+
*Eileen M. Uchitelle*
|
461
|
+
|
462
|
+
* Allow `where` references association names as joined table name aliases.
|
376
463
|
|
377
464
|
```ruby
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
465
|
+
class Comment < ActiveRecord::Base
|
466
|
+
enum label: [:default, :child]
|
467
|
+
has_many :children, class_name: "Comment", foreign_key: :parent_id
|
468
|
+
end
|
469
|
+
|
470
|
+
# ... FROM comments LEFT OUTER JOIN comments children ON ... WHERE children.label = 1
|
471
|
+
Comment.includes(:children).where("children.label": "child")
|
382
472
|
```
|
383
473
|
|
384
474
|
*Ryuta Kamizono*
|
385
475
|
|
386
|
-
*
|
387
|
-
whether preloaded / eager loaded or not, with the exception of `unscoped`.
|
476
|
+
* Support storing demodulized class name for polymorphic type.
|
388
477
|
|
389
|
-
Before
|
478
|
+
Before Rails 6.1, storing demodulized class name is supported only for STI type
|
479
|
+
by `store_full_sti_class` class attribute.
|
480
|
+
|
481
|
+
Now `store_full_class_name` class attribute can handle both STI and polymorphic types.
|
482
|
+
|
483
|
+
*Ryuta Kamizono*
|
484
|
+
|
485
|
+
* Deprecate `rails db:structure:{load, dump}` tasks and extend
|
486
|
+
`rails db:schema:{load, dump}` tasks to work with either `:ruby` or `:sql` format,
|
487
|
+
depending on `config.active_record.schema_format` configuration value.
|
488
|
+
|
489
|
+
*fatkodima*
|
490
|
+
|
491
|
+
* Respect the `select` values for eager loading.
|
390
492
|
|
391
493
|
```ruby
|
392
|
-
Post.
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
494
|
+
post = Post.select("UPPER(title) AS title").first
|
495
|
+
post.title # => "WELCOME TO THE WEBLOG"
|
496
|
+
post.body # => ActiveModel::MissingAttributeError
|
497
|
+
|
498
|
+
# Rails 6.0 (ignore the `select` values)
|
499
|
+
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
500
|
+
post.title # => "Welcome to the weblog"
|
501
|
+
post.body # => "Such a lovely day"
|
502
|
+
|
503
|
+
# Rails 6.1 (respect the `select` values)
|
504
|
+
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
505
|
+
post.title # => "WELCOME TO THE WEBLOG"
|
506
|
+
post.body # => ActiveModel::MissingAttributeError
|
397
507
|
```
|
398
508
|
|
399
|
-
|
509
|
+
*Ryuta Kamizono*
|
510
|
+
|
511
|
+
* Allow attribute's default to be configured but keeping its own type.
|
400
512
|
|
401
513
|
```ruby
|
402
|
-
Post
|
403
|
-
|
404
|
-
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
405
|
-
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
514
|
+
class Post < ActiveRecord::Base
|
515
|
+
attribute :written_at, default: -> { Time.now.utc }
|
406
516
|
end
|
407
|
-
```
|
408
517
|
|
409
|
-
|
518
|
+
# Rails 6.0
|
519
|
+
Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
|
520
|
+
|
521
|
+
# Rails 6.1
|
522
|
+
Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>
|
523
|
+
```
|
410
524
|
|
411
525
|
*Ryuta Kamizono*
|
412
526
|
|
413
|
-
*
|
527
|
+
* Allow default to be configured for Enum.
|
414
528
|
|
415
|
-
|
529
|
+
```ruby
|
530
|
+
class Book < ActiveRecord::Base
|
531
|
+
enum status: [:proposed, :written, :published], _default: :published
|
532
|
+
end
|
416
533
|
|
417
|
-
|
534
|
+
Book.new.status # => "published"
|
535
|
+
```
|
418
536
|
|
419
|
-
*
|
537
|
+
*Ryuta Kamizono*
|
420
538
|
|
421
|
-
|
539
|
+
* Deprecate YAML loading from legacy format older than Rails 5.0.
|
422
540
|
|
423
|
-
*
|
424
|
-
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
541
|
+
*Ryuta Kamizono*
|
425
542
|
|
426
|
-
|
543
|
+
* Added the setting `ActiveRecord::Base.immutable_strings_by_default`, which
|
544
|
+
allows you to specify that all string columns should be frozen unless
|
545
|
+
otherwise specified. This will reduce memory pressure for applications which
|
546
|
+
do not generally mutate string properties of Active Record objects.
|
427
547
|
|
428
|
-
*
|
548
|
+
*Sean Griffin*, *Ryuta Kamizono*
|
429
549
|
|
430
|
-
*
|
550
|
+
* Deprecate `map!` and `collect!` on `ActiveRecord::Result`.
|
431
551
|
|
432
|
-
|
433
|
-
account.memberships.extract_associated(:user)
|
434
|
-
# => Returns collection of User records
|
435
|
-
```
|
552
|
+
*Ryuta Kamizono*
|
436
553
|
|
437
|
-
|
554
|
+
* Support `relation.and` for intersection as Set theory.
|
438
555
|
|
439
|
-
|
556
|
+
```ruby
|
557
|
+
david_and_mary = Author.where(id: [david, mary])
|
558
|
+
mary_and_bob = Author.where(id: [mary, bob])
|
440
559
|
|
441
|
-
|
560
|
+
david_and_mary.merge(mary_and_bob) # => [mary, bob]
|
442
561
|
|
443
|
-
|
444
|
-
|
445
|
-
# SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
|
562
|
+
david_and_mary.and(mary_and_bob) # => [mary]
|
563
|
+
david_and_mary.or(mary_and_bob) # => [david, mary, bob]
|
446
564
|
```
|
447
565
|
|
448
|
-
|
449
|
-
|
450
|
-
*Matt Yoho*
|
566
|
+
*Ryuta Kamizono*
|
451
567
|
|
452
|
-
*
|
568
|
+
* Merging conditions on the same column no longer maintain both conditions,
|
569
|
+
and will be consistently replaced by the latter condition in Rails 6.2.
|
570
|
+
To migrate to Rails 6.2's behavior, use `relation.merge(other, rewhere: true)`.
|
453
571
|
|
454
|
-
|
455
|
-
|
572
|
+
```ruby
|
573
|
+
# Rails 6.1 (IN clause is replaced by merger side equality condition)
|
574
|
+
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
456
575
|
|
457
|
-
|
576
|
+
# Rails 6.1 (both conflict conditions exists, deprecated)
|
577
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
|
458
578
|
|
459
|
-
|
460
|
-
|
579
|
+
# Rails 6.1 with rewhere to migrate to Rails 6.2's behavior
|
580
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
|
461
581
|
|
462
|
-
|
582
|
+
# Rails 6.2 (same behavior with IN clause, mergee side condition is consistently replaced)
|
583
|
+
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
584
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
|
585
|
+
```
|
463
586
|
|
464
|
-
|
465
|
-
# SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
|
587
|
+
*Ryuta Kamizono*
|
466
588
|
|
467
|
-
|
589
|
+
* Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
|
468
590
|
|
469
|
-
*
|
470
|
-
* https://pghintplan.osdn.jp/pg_hint_plan.html
|
471
|
-
* https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
|
472
|
-
* https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
|
473
|
-
* https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
|
591
|
+
*Peter Fry*
|
474
592
|
|
475
|
-
|
593
|
+
* Resolve issue with insert_all unique_by option when used with expression index.
|
476
594
|
|
477
|
-
|
595
|
+
When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
|
596
|
+
`ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
|
597
|
+
was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
|
478
598
|
|
479
|
-
|
599
|
+
Usage:
|
480
600
|
|
481
|
-
```
|
482
|
-
|
483
|
-
|
601
|
+
```ruby
|
602
|
+
create_table :books, id: :integer, force: true do |t|
|
603
|
+
t.column :name, :string
|
604
|
+
t.index "lower(name)", unique: true
|
484
605
|
end
|
485
606
|
|
486
|
-
|
607
|
+
Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
|
487
608
|
```
|
488
609
|
|
489
|
-
|
610
|
+
Fixes #39516.
|
490
611
|
|
491
|
-
*
|
612
|
+
*Austen Madden*
|
492
613
|
|
493
|
-
|
614
|
+
* Add basic support for CHECK constraints to database migrations.
|
494
615
|
|
495
|
-
|
496
|
-
allowing bulk inserts akin to the bulk updates provided by `update_all` and
|
497
|
-
bulk deletes by `delete_all`.
|
616
|
+
Usage:
|
498
617
|
|
499
|
-
|
500
|
-
|
501
|
-
|
618
|
+
```ruby
|
619
|
+
add_check_constraint :products, "price > 0", name: "price_check"
|
620
|
+
remove_check_constraint :products, name: "price_check"
|
621
|
+
```
|
502
622
|
|
503
|
-
*
|
623
|
+
*fatkodima*
|
504
624
|
|
505
|
-
* Add `
|
506
|
-
for
|
625
|
+
* Add `ActiveRecord::Base.strict_loading_by_default` and `ActiveRecord::Base.strict_loading_by_default=`
|
626
|
+
to enable/disable strict_loading mode by default for a model. The configuration's value is
|
627
|
+
inheritable by subclasses, but they can override that value and it will not impact parent class.
|
507
628
|
|
508
|
-
|
629
|
+
Usage:
|
509
630
|
|
510
|
-
|
631
|
+
```ruby
|
632
|
+
class Developer < ApplicationRecord
|
633
|
+
self.strict_loading_by_default = true
|
511
634
|
|
512
|
-
|
635
|
+
has_many :projects
|
636
|
+
end
|
513
637
|
|
514
|
-
|
638
|
+
dev = Developer.first
|
639
|
+
dev.projects.first
|
640
|
+
# => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.
|
641
|
+
```
|
515
642
|
|
516
|
-
|
517
|
-
|
518
|
-
|
643
|
+
*bogdanvlviv*
|
644
|
+
|
645
|
+
* Deprecate passing an Active Record object to `quote`/`type_cast` directly.
|
519
646
|
|
520
647
|
*Ryuta Kamizono*
|
521
648
|
|
522
|
-
*
|
649
|
+
* Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic.
|
523
650
|
|
524
|
-
|
651
|
+
Before:
|
525
652
|
|
526
|
-
|
653
|
+
```ruby
|
654
|
+
create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
|
655
|
+
end
|
656
|
+
```
|
527
657
|
|
528
|
-
|
658
|
+
After:
|
529
659
|
|
530
|
-
|
660
|
+
```ruby
|
661
|
+
create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
662
|
+
end
|
663
|
+
```
|
531
664
|
|
532
|
-
|
533
|
-
enum status: %i[ drafted active trashed ]
|
534
|
-
end
|
665
|
+
*Ryuta Kamizono*
|
535
666
|
|
536
|
-
|
537
|
-
|
538
|
-
Post.not_trashed # => where.not(status: :trashed)
|
667
|
+
* Added delegated type as an alternative to single-table inheritance for representing class hierarchies.
|
668
|
+
See ActiveRecord::DelegatedType for the full description.
|
539
669
|
|
540
670
|
*DHH*
|
541
671
|
|
542
|
-
*
|
672
|
+
* Deprecate aggregations with group by duplicated fields.
|
543
673
|
|
544
|
-
|
674
|
+
To migrate to Rails 6.2's behavior, use `uniq!(:group)` to deduplicate group fields.
|
545
675
|
|
546
|
-
|
676
|
+
```ruby
|
677
|
+
accounts = Account.group(:firm_id)
|
678
|
+
|
679
|
+
# duplicated group fields, deprecated.
|
680
|
+
accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
|
681
|
+
# => {
|
682
|
+
# [1, 1] => 50,
|
683
|
+
# [2, 2] => 60
|
684
|
+
# }
|
685
|
+
|
686
|
+
# use `uniq!(:group)` to deduplicate group fields.
|
687
|
+
accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
|
688
|
+
# => {
|
689
|
+
# 1 => 50,
|
690
|
+
# 2 => 60
|
691
|
+
# }
|
692
|
+
```
|
547
693
|
|
694
|
+
*Ryuta Kamizono*
|
548
695
|
|
549
|
-
|
696
|
+
* Deprecate duplicated query annotations.
|
550
697
|
|
551
|
-
|
698
|
+
To migrate to Rails 6.2's behavior, use `uniq!(:annotate)` to deduplicate query annotations.
|
552
699
|
|
700
|
+
```ruby
|
701
|
+
accounts = Account.where(id: [1, 2]).annotate("david and mary")
|
553
702
|
|
554
|
-
|
703
|
+
# duplicated annotations, deprecated.
|
704
|
+
accounts.merge(accounts.rewhere(id: 3))
|
705
|
+
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
|
555
706
|
|
556
|
-
|
707
|
+
# use `uniq!(:annotate)` to deduplicate annotations.
|
708
|
+
accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
|
709
|
+
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
|
710
|
+
```
|
557
711
|
|
558
712
|
*Ryuta Kamizono*
|
559
713
|
|
560
|
-
*
|
714
|
+
* Resolve conflict between counter cache and optimistic locking.
|
561
715
|
|
562
|
-
|
716
|
+
Bump an Active Record instance's lock version after updating its counter
|
717
|
+
cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
|
718
|
+
upon subsequent transactions by maintaining parity with the corresponding
|
719
|
+
database record's `lock_version` column.
|
563
720
|
|
564
|
-
|
721
|
+
Fixes #16449.
|
565
722
|
|
566
|
-
*
|
723
|
+
*Aaron Lipman*
|
567
724
|
|
568
|
-
*
|
725
|
+
* Support merging option `:rewhere` to allow mergee side condition to be replaced exactly.
|
569
726
|
|
570
|
-
|
571
|
-
|
727
|
+
```ruby
|
728
|
+
david_and_mary = Author.where(id: david.id..mary.id)
|
572
729
|
|
573
|
-
|
730
|
+
# both conflict conditions exists
|
731
|
+
david_and_mary.merge(Author.where(id: bob)) # => []
|
574
732
|
|
575
|
-
|
576
|
-
|
733
|
+
# mergee side condition is replaced by rewhere
|
734
|
+
david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
|
577
735
|
|
578
|
-
|
579
|
-
|
736
|
+
# mergee side condition is replaced by rewhere option
|
737
|
+
david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]
|
738
|
+
```
|
580
739
|
|
581
|
-
|
582
|
-
`delete_all` on the matched records.
|
740
|
+
*Ryuta Kamizono*
|
583
741
|
|
584
|
-
|
742
|
+
* Add support for finding records based on signed ids, which are tamper-proof, verified ids that can be
|
743
|
+
set to expire and scoped with a purpose. This is particularly useful for things like password reset
|
744
|
+
or email verification, where you want the bearer of the signed id to be able to interact with the
|
745
|
+
underlying record, but usually only within a certain time period.
|
585
746
|
|
586
|
-
|
587
|
-
|
747
|
+
```ruby
|
748
|
+
signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
|
588
749
|
|
589
|
-
|
590
|
-
david.posts.delete_by(id: [1, 2, 3])
|
750
|
+
User.find_signed signed_id # => nil, since the purpose does not match
|
591
751
|
|
592
|
-
|
752
|
+
travel 16.minutes
|
753
|
+
User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
|
593
754
|
|
594
|
-
|
755
|
+
travel_back
|
756
|
+
User.find_signed signed_id, purpose: :password_reset # => User.first
|
595
757
|
|
596
|
-
|
758
|
+
User.find_signed! "bad data" # => ActiveSupport::MessageVerifier::InvalidSignature
|
759
|
+
```
|
597
760
|
|
598
|
-
*
|
761
|
+
*DHH*
|
599
762
|
|
600
|
-
*
|
763
|
+
* Support `ALGORITHM = INSTANT` DDL option for index operations on MySQL.
|
601
764
|
|
602
765
|
*Ryuta Kamizono*
|
603
766
|
|
604
|
-
*
|
605
|
-
regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
|
767
|
+
* Fix index creation to preserve index comment in bulk change table on MySQL.
|
606
768
|
|
607
769
|
*Ryuta Kamizono*
|
608
770
|
|
609
|
-
* Allow
|
771
|
+
* Allow `unscope` to be aware of table name qualified values.
|
610
772
|
|
611
|
-
|
612
|
-
application to automatically switch between the writing and reading
|
613
|
-
database connections.
|
773
|
+
It is possible to unscope only the column in the specified table.
|
614
774
|
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
an argument for a Resolver class and an Operations class where you are able
|
619
|
-
to change how the auto-switcher works to be most beneficial for your
|
620
|
-
application.
|
775
|
+
```ruby
|
776
|
+
posts = Post.joins(:comments).group(:"posts.hidden")
|
777
|
+
posts = posts.where("posts.hidden": false, "comments.hidden": false)
|
621
778
|
|
622
|
-
|
623
|
-
|
779
|
+
posts.count
|
780
|
+
# => { false => 10 }
|
624
781
|
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
782
|
+
# unscope both hidden columns
|
783
|
+
posts.unscope(where: :hidden).count
|
784
|
+
# => { false => 11, true => 1 }
|
785
|
+
|
786
|
+
# unscope only comments.hidden column
|
787
|
+
posts.unscope(where: :"comments.hidden").count
|
788
|
+
# => { false => 11 }
|
629
789
|
```
|
630
790
|
|
631
|
-
|
632
|
-
configuration options:
|
791
|
+
*Ryuta Kamizono*, *Slava Korolev*
|
633
792
|
|
793
|
+
* Fix `rewhere` to truly overwrite collided where clause by new where clause.
|
794
|
+
|
795
|
+
```ruby
|
796
|
+
steve = Person.find_by(name: "Steve")
|
797
|
+
david = Author.find_by(name: "David")
|
798
|
+
|
799
|
+
relation = Essay.where(writer: steve)
|
800
|
+
|
801
|
+
# Before
|
802
|
+
relation.rewhere(writer: david).to_a # => []
|
803
|
+
|
804
|
+
# After
|
805
|
+
relation.rewhere(writer: david).to_a # => [david]
|
634
806
|
```
|
635
|
-
|
636
|
-
|
637
|
-
|
807
|
+
|
808
|
+
*Ryuta Kamizono*
|
809
|
+
|
810
|
+
* Inspect time attributes with subsec and time zone offset.
|
811
|
+
|
812
|
+
```ruby
|
813
|
+
p Knot.create
|
814
|
+
=> #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
|
638
815
|
```
|
639
816
|
|
640
|
-
*
|
817
|
+
*akinomaeni*, *Jonathan Hefner*
|
641
818
|
|
642
|
-
*
|
819
|
+
* Deprecate passing a column to `type_cast`.
|
643
820
|
|
644
821
|
*Ryuta Kamizono*
|
645
822
|
|
646
|
-
*
|
823
|
+
* Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.
|
647
824
|
|
648
825
|
*Ryuta Kamizono*
|
649
826
|
|
827
|
+
* Support bulk insert/upsert on relation to preserve scope values.
|
650
828
|
|
651
|
-
|
829
|
+
*Josef Šimánek*, *Ryuta Kamizono*
|
652
830
|
|
653
|
-
*
|
831
|
+
* Preserve column comment value on changing column name on MySQL.
|
654
832
|
|
655
|
-
*
|
833
|
+
*Islam Taha*
|
656
834
|
|
657
|
-
*
|
835
|
+
* Add support for `if_exists` option for removing an index.
|
658
836
|
|
659
|
-
|
837
|
+
The `remove_index` method can take an `if_exists` option. If this is set to true an error won't be raised if the index doesn't exist.
|
660
838
|
|
661
|
-
*
|
839
|
+
*Eileen M. Uchitelle*
|
662
840
|
|
663
|
-
|
841
|
+
* Remove ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base.
|
664
842
|
|
665
|
-
*
|
843
|
+
*Ryuta Kamizono*
|
666
844
|
|
667
|
-
|
845
|
+
* Prevent `build_association` from `touching` a parent record if the record isn't persisted for `has_one` associations.
|
668
846
|
|
669
|
-
|
847
|
+
Fixes #38219.
|
670
848
|
|
671
|
-
*
|
849
|
+
*Josh Brody*
|
672
850
|
|
673
|
-
*
|
851
|
+
* Add support for `if_not_exists` option for adding index.
|
674
852
|
|
675
|
-
|
853
|
+
The `add_index` method respects `if_not_exists` option. If it is set to true
|
854
|
+
index won't be added.
|
676
855
|
|
677
|
-
|
856
|
+
Usage:
|
678
857
|
|
679
|
-
|
858
|
+
```ruby
|
859
|
+
add_index :users, :account_id, if_not_exists: true
|
860
|
+
```
|
680
861
|
|
681
|
-
|
862
|
+
The `if_not_exists` option passed to `create_table` also gets propagated to indexes
|
863
|
+
created within that migration so that if table and its indexes exist then there is no
|
864
|
+
attempt to create them again.
|
682
865
|
|
683
|
-
*
|
866
|
+
*Prathamesh Sonpatki*
|
684
867
|
|
685
|
-
*
|
868
|
+
* Add `ActiveRecord::Base#previously_new_record?` to show if a record was new before the last save.
|
686
869
|
|
687
|
-
*
|
870
|
+
*Tom Ward*
|
688
871
|
|
689
|
-
*
|
872
|
+
* Support descending order for `find_each`, `find_in_batches`, and `in_batches`.
|
690
873
|
|
691
|
-
|
874
|
+
Batch processing methods allow you to work with the records in batches, greatly reducing memory consumption, but records are always batched from oldest id to newest.
|
692
875
|
|
693
|
-
|
876
|
+
This change allows reversing the order, batching from newest to oldest. This is useful when you need to process newer batches of records first.
|
694
877
|
|
695
|
-
|
878
|
+
Pass `order: :desc` to yield batches in descending order. The default remains `order: :asc`.
|
696
879
|
|
697
|
-
|
880
|
+
```ruby
|
881
|
+
Person.find_each(order: :desc) do |person|
|
882
|
+
person.party_all_night!
|
883
|
+
end
|
884
|
+
```
|
698
885
|
|
699
|
-
*
|
886
|
+
*Alexey Vasiliev*
|
700
887
|
|
701
|
-
*
|
888
|
+
* Fix `insert_all` with enum values.
|
702
889
|
|
703
|
-
|
890
|
+
Fixes #38716.
|
704
891
|
|
705
|
-
*
|
892
|
+
*Joel Blum*
|
706
893
|
|
707
|
-
|
894
|
+
* Add support for `db:rollback:name` for multiple database applications.
|
708
895
|
|
709
|
-
|
896
|
+
Multiple database applications will now raise if `db:rollback` is call and recommend using the `db:rollback:[NAME]` to rollback migrations.
|
710
897
|
|
711
|
-
*
|
898
|
+
*Eileen M. Uchitelle*
|
712
899
|
|
713
|
-
|
900
|
+
* `Relation#pick` now uses already loaded results instead of making another query.
|
714
901
|
|
715
|
-
*
|
902
|
+
*Eugene Kenny*
|
716
903
|
|
717
|
-
|
904
|
+
* Deprecate using `return`, `break` or `throw` to exit a transaction block after writes.
|
718
905
|
|
719
|
-
*
|
906
|
+
*Dylan Thacker-Smith*
|
720
907
|
|
721
|
-
|
908
|
+
* Dump the schema or structure of a database when calling `db:migrate:name`.
|
722
909
|
|
723
|
-
|
910
|
+
In previous versions of Rails, `rails db:migrate` would dump the schema of the database. In Rails 6, that holds true (`rails db:migrate` dumps all databases' schemas), but `rails db:migrate:name` does not share that behavior.
|
724
911
|
|
725
|
-
|
726
|
-
format for InnoDB tables. The default setting is `DYNAMIC`.
|
727
|
-
The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
|
912
|
+
Going forward, calls to `rails db:migrate:name` will dump the schema (or structure) of the database being migrated.
|
728
913
|
|
729
|
-
*
|
914
|
+
*Kyle Thompson*
|
730
915
|
|
731
|
-
*
|
916
|
+
* Reset the `ActiveRecord::Base` connection after `rails db:migrate:name`.
|
732
917
|
|
733
|
-
|
918
|
+
When `rails db:migrate` has finished, it ensures the `ActiveRecord::Base` connection is reset to its original configuration. Going forward, `rails db:migrate:name` will have the same behavior.
|
734
919
|
|
735
|
-
*
|
920
|
+
*Kyle Thompson*
|
736
921
|
|
737
|
-
|
922
|
+
* Disallow calling `connected_to` on subclasses of `ActiveRecord::Base`.
|
738
923
|
|
739
|
-
|
924
|
+
Behavior has not changed here but the previous API could be misleading to people who thought it would switch connections for only that class. `connected_to` switches the context from which we are getting connections, not the connections themselves.
|
740
925
|
|
741
|
-
*
|
926
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
742
927
|
|
743
|
-
*
|
928
|
+
* Add support for horizontal sharding to `connects_to` and `connected_to`.
|
744
929
|
|
745
|
-
|
930
|
+
Applications can now connect to multiple shards and switch between their shards in an application. Note that the shard swapping is still a manual process as this change does not include an API for automatic shard swapping.
|
746
931
|
|
747
|
-
|
932
|
+
Usage:
|
748
933
|
|
749
|
-
|
750
|
-
you're building out multiple databases and want to make sure you're not sending
|
751
|
-
writes when you want a read.
|
934
|
+
Given the following configuration:
|
752
935
|
|
753
|
-
|
754
|
-
|
755
|
-
|
936
|
+
```yaml
|
937
|
+
# config/database.yml
|
938
|
+
production:
|
939
|
+
primary:
|
940
|
+
database: my_database
|
941
|
+
primary_shard_one:
|
942
|
+
database: my_database_shard_one
|
943
|
+
```
|
756
944
|
|
757
|
-
|
758
|
-
read-only queries without opening a second connection. One purpose of this is to
|
759
|
-
catch accidental writes, not all writes.
|
945
|
+
Connect to multiple shards:
|
760
946
|
|
761
|
-
|
947
|
+
```ruby
|
948
|
+
class ApplicationRecord < ActiveRecord::Base
|
949
|
+
self.abstract_class = true
|
762
950
|
|
763
|
-
|
951
|
+
connects_to shards: {
|
952
|
+
default: { writing: :primary },
|
953
|
+
shard_one: { writing: :primary_shard_one }
|
954
|
+
}
|
955
|
+
```
|
764
956
|
|
765
|
-
|
957
|
+
Swap between shards in your controller / model code:
|
958
|
+
|
959
|
+
```ruby
|
960
|
+
ActiveRecord::Base.connected_to(shard: :shard_one) do
|
961
|
+
# Read from shard one
|
962
|
+
end
|
963
|
+
```
|
766
964
|
|
767
|
-
|
965
|
+
The horizontal sharding API also supports read replicas. See guides for more details.
|
768
966
|
|
769
|
-
|
967
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
770
968
|
|
771
|
-
|
969
|
+
* Deprecate `spec_name` in favor of `name` on database configurations.
|
772
970
|
|
773
|
-
|
971
|
+
The accessors for `spec_name` on `configs_for` and `DatabaseConfig` are deprecated. Please use `name` instead.
|
774
972
|
|
775
|
-
|
776
|
-
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
973
|
+
Deprecated behavior:
|
777
974
|
|
778
975
|
```ruby
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
end
|
783
|
-
end
|
976
|
+
db_config = ActiveRecord::Base.configs_for(env_name: "development", spec_name: "primary")
|
977
|
+
db_config.spec_name
|
978
|
+
```
|
784
979
|
|
785
|
-
|
786
|
-
self.table_name = "developers"
|
980
|
+
New behavior:
|
787
981
|
|
788
|
-
|
982
|
+
```ruby
|
983
|
+
db_config = ActiveRecord::Base.configs_for(env_name: "development", name: "primary")
|
984
|
+
db_config.name
|
985
|
+
```
|
789
986
|
|
790
|
-
|
791
|
-
end
|
987
|
+
*Eileen M. Uchitelle*
|
792
988
|
|
793
|
-
|
794
|
-
developer.update_column :name, "name"
|
989
|
+
* Add additional database-specific rake tasks for multi-database users.
|
795
990
|
|
796
|
-
|
797
|
-
|
991
|
+
Previously, `rails db:create`, `rails db:drop`, and `rails db:migrate` were the only rails tasks that could operate on a single
|
992
|
+
database. For example:
|
993
|
+
|
994
|
+
```
|
995
|
+
rails db:create
|
996
|
+
rails db:create:primary
|
997
|
+
rails db:create:animals
|
998
|
+
rails db:drop
|
999
|
+
rails db:drop:primary
|
1000
|
+
rails db:drop:animals
|
1001
|
+
rails db:migrate
|
1002
|
+
rails db:migrate:primary
|
1003
|
+
rails db:migrate:animals
|
798
1004
|
```
|
799
1005
|
|
800
|
-
|
1006
|
+
With these changes, `rails db:schema:dump`, `rails db:schema:load`, `rails db:structure:dump`, `rails db:structure:load` and
|
1007
|
+
`rails db:test:prepare` can additionally operate on a single database. For example:
|
801
1008
|
|
802
|
-
|
1009
|
+
```
|
1010
|
+
rails db:schema:dump
|
1011
|
+
rails db:schema:dump:primary
|
1012
|
+
rails db:schema:dump:animals
|
1013
|
+
rails db:schema:load
|
1014
|
+
rails db:schema:load:primary
|
1015
|
+
rails db:schema:load:animals
|
1016
|
+
rails db:structure:dump
|
1017
|
+
rails db:structure:dump:primary
|
1018
|
+
rails db:structure:dump:animals
|
1019
|
+
rails db:structure:load
|
1020
|
+
rails db:structure:load:primary
|
1021
|
+
rails db:structure:load:animals
|
1022
|
+
rails db:test:prepare
|
1023
|
+
rails db:test:prepare:primary
|
1024
|
+
rails db:test:prepare:animals
|
1025
|
+
```
|
803
1026
|
|
804
|
-
|
805
|
-
explicit order clause, ActiveRecord sorts records by primary key. This can
|
806
|
-
result in unpredictable and surprising behaviour when the primary key is
|
807
|
-
not an auto-incrementing integer, for example when it's a UUID. This change
|
808
|
-
makes it possible to override the column used for implicit ordering such
|
809
|
-
that `first` and `last` will return more predictable results.
|
1027
|
+
*Kyle Thompson*
|
810
1028
|
|
811
|
-
|
1029
|
+
* Add support for `strict_loading` mode on association declarations.
|
812
1030
|
|
813
|
-
|
814
|
-
|
815
|
-
|
1031
|
+
Raise an error if attempting to load a record from an association that has been marked as `strict_loading` unless it was explicitly eager loaded.
|
1032
|
+
|
1033
|
+
Usage:
|
1034
|
+
|
1035
|
+
```ruby
|
1036
|
+
class Developer < ApplicationRecord
|
1037
|
+
has_many :projects, strict_loading: true
|
1038
|
+
end
|
1039
|
+
|
1040
|
+
dev = Developer.first
|
1041
|
+
dev.projects.first
|
1042
|
+
# => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.
|
1043
|
+
```
|
1044
|
+
|
1045
|
+
*Kevin Deisz*
|
816
1046
|
|
817
|
-
|
1047
|
+
* Add support for `strict_loading` mode to prevent lazy loading of records.
|
818
1048
|
|
819
|
-
|
1049
|
+
Raise an error if a parent record is marked as `strict_loading` and attempts to lazily load its associations. This is useful for finding places you may want to preload an association and avoid additional queries.
|
820
1050
|
|
821
|
-
|
1051
|
+
Usage:
|
822
1052
|
|
823
|
-
|
1053
|
+
```ruby
|
1054
|
+
dev = Developer.strict_loading.first
|
1055
|
+
dev.audit_logs.to_a
|
1056
|
+
# => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
|
1057
|
+
```
|
824
1058
|
|
825
|
-
*
|
1059
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*
|
826
1060
|
|
827
|
-
*
|
1061
|
+
* Add support for PostgreSQL 11+ partitioned indexes when using `upsert_all`.
|
828
1062
|
|
829
|
-
|
1063
|
+
*Sebastián Palma*
|
830
1064
|
|
831
|
-
|
1065
|
+
* Adds support for `if_not_exists` to `add_column` and `if_exists` to `remove_column`.
|
832
1066
|
|
833
|
-
|
1067
|
+
Applications can set their migrations to ignore exceptions raised when adding a column that already exists or when removing a column that does not exist.
|
834
1068
|
|
835
|
-
Example:
|
1069
|
+
Example Usage:
|
836
1070
|
|
1071
|
+
```ruby
|
1072
|
+
class AddColumnTitle < ActiveRecord::Migration[6.1]
|
1073
|
+
def change
|
1074
|
+
add_column :posts, :title, :string, if_not_exists: true
|
1075
|
+
end
|
1076
|
+
end
|
837
1077
|
```
|
838
|
-
|
839
|
-
|
840
|
-
|
1078
|
+
|
1079
|
+
```ruby
|
1080
|
+
class RemoveColumnTitle < ActiveRecord::Migration[6.1]
|
1081
|
+
def change
|
1082
|
+
remove_column :posts, :title, if_exists: true
|
841
1083
|
end
|
842
1084
|
end
|
843
1085
|
```
|
844
1086
|
|
845
|
-
*
|
1087
|
+
*Eileen M. Uchitelle*
|
846
1088
|
|
847
|
-
*
|
1089
|
+
* Regexp-escape table name for MS SQL Server.
|
848
1090
|
|
849
|
-
|
1091
|
+
Add `Regexp.escape` to one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods like `pluck` and `select` fail in certain cases when used with the MS SQL Server adapter.
|
850
1092
|
|
851
|
-
|
852
|
-
t.string :title
|
853
|
-
end
|
1093
|
+
*Larry Reid*
|
854
1094
|
|
855
|
-
|
1095
|
+
* Store advisory locks on their own named connection.
|
856
1096
|
|
857
|
-
|
858
|
-
...
|
859
|
-
)
|
1097
|
+
Previously advisory locks were taken out against a connection when a migration started. This works fine in single database applications but doesn't work well when migrations need to open new connections which results in the lock getting dropped.
|
860
1098
|
|
861
|
-
|
862
|
-
exception whereas `if_not_exists: true` does nothing.
|
1099
|
+
In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdvisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
|
863
1100
|
|
864
|
-
*
|
1101
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
865
1102
|
|
866
|
-
*
|
1103
|
+
* Allow schema cache path to be defined in the database configuration file.
|
867
1104
|
|
868
|
-
|
1105
|
+
For example:
|
869
1106
|
|
870
|
-
|
1107
|
+
```yaml
|
1108
|
+
development:
|
1109
|
+
adapter: postgresql
|
1110
|
+
database: blog_development
|
1111
|
+
pool: 5
|
1112
|
+
schema_cache_path: tmp/schema/main.yml
|
1113
|
+
```
|
871
1114
|
|
872
|
-
*
|
1115
|
+
*Katrina Owen*
|
873
1116
|
|
874
|
-
* `
|
875
|
-
if the attribute does not exist.
|
1117
|
+
* Deprecate `#remove_connection` in favor of `#remove_connection_pool` when called on the handler.
|
876
1118
|
|
877
|
-
|
1119
|
+
`#remove_connection` is deprecated in order to support returning a `DatabaseConfig` object instead of a `Hash`. Use `#remove_connection_pool`, `#remove_connection` will be removed in 6.2.
|
878
1120
|
|
879
|
-
*
|
1121
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
880
1122
|
|
881
|
-
|
882
|
-
User.connected_to(database: { writing: "postgres://foo" }) do
|
883
|
-
User.create!(name: "Gannon")
|
884
|
-
end
|
1123
|
+
* Deprecate `#default_hash` and it's alias `#[]` on database configurations.
|
885
1124
|
|
886
|
-
|
887
|
-
User.connected_to(database: { reading: config }) do
|
888
|
-
User.count
|
889
|
-
end
|
890
|
-
````
|
1125
|
+
Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in 6.2.
|
891
1126
|
|
892
|
-
*
|
1127
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
893
1128
|
|
894
|
-
*
|
1129
|
+
* Add scale support to `ActiveRecord::Validations::NumericalityValidator`.
|
895
1130
|
|
896
|
-
|
1131
|
+
*Gannon McGibbon*
|
897
1132
|
|
898
|
-
|
1133
|
+
* Find orphans by looking for missing relations through chaining `where.missing`:
|
899
1134
|
|
900
|
-
|
1135
|
+
Before:
|
901
1136
|
|
902
|
-
|
1137
|
+
```ruby
|
1138
|
+
Post.left_joins(:author).where(authors: { id: nil })
|
1139
|
+
```
|
903
1140
|
|
904
|
-
|
905
|
-
expression values rather than column or column prefix values.
|
1141
|
+
After:
|
906
1142
|
|
907
|
-
|
1143
|
+
```ruby
|
1144
|
+
Post.where.missing(:author)
|
1145
|
+
```
|
908
1146
|
|
909
|
-
*
|
1147
|
+
*Tom Rossi*
|
910
1148
|
|
911
|
-
*
|
1149
|
+
* Ensure `:reading` connections always raise if a write is attempted.
|
912
1150
|
|
913
|
-
|
1151
|
+
Now Rails will raise an `ActiveRecord::ReadOnlyError` if any connection on the reading handler attempts to make a write. If your reading role needs to write you should name the role something other than `:reading`.
|
914
1152
|
|
915
|
-
*
|
1153
|
+
*Eileen M. Uchitelle*
|
916
1154
|
|
917
|
-
*
|
1155
|
+
* Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
|
918
1156
|
|
919
|
-
|
1157
|
+
`"primary"` has been deprecated as the `connection_specification_name` for `ActiveRecord::Base` in favor of using `"ActiveRecord::Base"`. This change affects calls to `ActiveRecord::Base.connection_handler.retrieve_connection` and `ActiveRecord::Base.connection_handler.remove_connection`. If you're calling these methods with `"primary"`, please switch to `"ActiveRecord::Base"`.
|
920
1158
|
|
921
|
-
|
922
|
-
class AnimalsModel < ApplicationRecord
|
923
|
-
self.abstract_class = true
|
924
|
-
|
925
|
-
connects_to database: { writing: :animals_primary, reading: :animals_replica }
|
926
|
-
end
|
1159
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
927
1160
|
|
928
|
-
|
929
|
-
|
930
|
-
end
|
931
|
-
```
|
1161
|
+
* Add `ActiveRecord::Validations::NumericalityValidator` with
|
1162
|
+
support for casting floats using a database columns' precision value.
|
932
1163
|
|
933
|
-
|
934
|
-
a database that the model didn't connect to. Connecting to the database in this block is
|
935
|
-
useful when you have another defined connection, for example `slow_replica` that you don't
|
936
|
-
want to connect to by default but need in the console, or a specific code block.
|
1164
|
+
*Gannon McGibbon*
|
937
1165
|
|
938
|
-
|
939
|
-
ActiveRecord::
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
```
|
1166
|
+
* Enforce fresh ETag header after a collection's contents change by adding
|
1167
|
+
ActiveRecord::Relation#cache_key_with_version. This method will be used by
|
1168
|
+
ActionController::ConditionalGet to ensure that when collection cache versioning
|
1169
|
+
is enabled, requests using ConditionalGet don't return the same ETag header
|
1170
|
+
after a collection is modified.
|
944
1171
|
|
945
|
-
|
946
|
-
ActiveRecord::Base.connected_to(database: :slow_replica) do
|
947
|
-
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
|
948
|
-
end
|
949
|
-
```
|
1172
|
+
Fixes #38078.
|
950
1173
|
|
951
|
-
*
|
1174
|
+
*Aaron Lipman*
|
952
1175
|
|
953
|
-
*
|
1176
|
+
* Skip test database when running `db:create` or `db:drop` in development
|
1177
|
+
with `DATABASE_URL` set.
|
954
1178
|
|
955
|
-
|
956
|
-
commit checks that only valid definition values are provided, those can
|
957
|
-
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
958
|
-
raises an `ArgumentError`.
|
1179
|
+
*Brian Buchalter*
|
959
1180
|
|
960
|
-
|
1181
|
+
* Don't allow mutations on the database configurations hash.
|
961
1182
|
|
962
|
-
|
1183
|
+
Freeze the configurations hash to disallow directly changing it. If applications need to change the hash, for example to create databases for parallelization, they should use the `DatabaseConfig` object directly.
|
963
1184
|
|
964
|
-
|
1185
|
+
Before:
|
965
1186
|
|
1187
|
+
```ruby
|
1188
|
+
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
|
1189
|
+
@db_config.configuration_hash.merge!(idle_timeout: "0.02")
|
966
1190
|
```
|
967
|
-
class Post < ActiveRecord::Base
|
968
|
-
has_one :category
|
969
|
-
belongs_to :author
|
970
|
-
has_many :comments
|
971
|
-
end
|
972
1191
|
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
1192
|
+
After:
|
1193
|
+
|
1194
|
+
```ruby
|
1195
|
+
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
|
1196
|
+
config = @db_config.configuration_hash.merge(idle_timeout: "0.02")
|
1197
|
+
db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)
|
977
1198
|
```
|
978
1199
|
|
979
|
-
*
|
1200
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
980
1201
|
|
981
|
-
*
|
982
|
-
With this change you can create indexes while adding new
|
983
|
-
columns into the existing tables.
|
1202
|
+
* Remove `:connection_id` from the `sql.active_record` notification.
|
984
1203
|
|
985
|
-
|
1204
|
+
*Aaron Patterson*, *Rafael Mendonça França*
|
986
1205
|
|
987
|
-
|
988
|
-
t.string :country_code, index: true
|
989
|
-
end
|
1206
|
+
* The `:name` key will no longer be returned as part of `DatabaseConfig#configuration_hash`. Please use `DatabaseConfig#owner_name` instead.
|
990
1207
|
|
991
|
-
*
|
1208
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
992
1209
|
|
993
|
-
*
|
1210
|
+
* ActiveRecord's `belongs_to_required_by_default` flag can now be set per model.
|
994
1211
|
|
995
|
-
|
996
|
-
|
1212
|
+
You can now opt-out/opt-in specific models from having their associations required
|
1213
|
+
by default.
|
997
1214
|
|
998
|
-
|
1215
|
+
This change is meant to ease the process of migrating all your models to have
|
1216
|
+
their association required.
|
999
1217
|
|
1000
|
-
*
|
1218
|
+
*Edouard Chin*
|
1001
1219
|
|
1002
|
-
|
1220
|
+
* The `connection_config` method has been deprecated, please use `connection_db_config` instead which will return a `DatabaseConfigurations::DatabaseConfig` instead of a `Hash`.
|
1003
1221
|
|
1004
|
-
*
|
1222
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1005
1223
|
|
1006
|
-
|
1224
|
+
* Retain explicit selections on the base model after applying `includes` and `joins`.
|
1007
1225
|
|
1008
|
-
|
1226
|
+
Resolves #34889.
|
1009
1227
|
|
1010
|
-
|
1228
|
+
*Patrick Rebsch*
|
1011
1229
|
|
1012
|
-
|
1230
|
+
* The `database` kwarg is deprecated without replacement because it can't be used for sharding and creates an issue if it's used during a request. Applications that need to create new connections should use `connects_to` instead.
|
1013
1231
|
|
1014
|
-
*
|
1232
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1015
1233
|
|
1016
|
-
|
1234
|
+
* Allow attributes to be fetched from Arel node groupings.
|
1017
1235
|
|
1018
|
-
*
|
1236
|
+
*Jeff Emminger*, *Gannon McGibbon*
|
1019
1237
|
|
1020
|
-
|
1021
|
-
create_table :users do |t|
|
1022
|
-
t.string :email
|
1023
|
-
end
|
1238
|
+
* A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgreSQL `options`.
|
1024
1239
|
|
1025
|
-
|
1026
|
-
```
|
1240
|
+
*Joshua Flanagan*
|
1027
1241
|
|
1028
|
-
|
1242
|
+
* Calling methods like `establish_connection` with a `Hash` which is invalid (eg: no `adapter`) will now raise an error the same way as connections defined in `config/database.yml`.
|
1029
1243
|
|
1030
|
-
*
|
1244
|
+
*John Crepezzi*
|
1031
1245
|
|
1032
|
-
|
1246
|
+
* Specifying `implicit_order_column` now subsorts the records by primary key if available to ensure deterministic results.
|
1033
1247
|
|
1034
|
-
*
|
1248
|
+
*Paweł Urbanek*
|
1035
1249
|
|
1036
|
-
*
|
1250
|
+
* `where(attr => [])` now loads an empty result without making a query.
|
1037
1251
|
|
1038
|
-
*
|
1252
|
+
*John Hawthorn*
|
1039
1253
|
|
1040
|
-
*
|
1254
|
+
* Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
|
1041
1255
|
|
1042
|
-
|
1043
|
-
The previous default 3-Byte encoding character set `utf8` is not enough to support them.
|
1256
|
+
*Hiroyuki Ishii*
|
1044
1257
|
|
1045
|
-
|
1258
|
+
* Add support for `belongs_to` to `has_many` inversing.
|
1046
1259
|
|
1047
|
-
*
|
1260
|
+
*Gannon McGibbon*
|
1048
1261
|
|
1049
|
-
|
1262
|
+
* Allow length configuration for `has_secure_token` method. The minimum length
|
1263
|
+
is set at 24 characters.
|
1050
1264
|
|
1051
|
-
|
1052
|
-
sensitive values of database columns when calling `#inspect`.
|
1053
|
-
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
1054
|
-
specify sensitive attributes to specific model.
|
1265
|
+
Before:
|
1055
1266
|
|
1267
|
+
```ruby
|
1268
|
+
has_secure_token :auth_token
|
1056
1269
|
```
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1270
|
+
|
1271
|
+
After:
|
1272
|
+
|
1273
|
+
```ruby
|
1274
|
+
has_secure_token :default_token # 24 characters
|
1275
|
+
has_secure_token :auth_token, length: 36 # 36 characters
|
1276
|
+
has_secure_token :invalid_token, length: 12 # => ActiveRecord::SecureToken::MinimumLengthError
|
1061
1277
|
```
|
1062
1278
|
|
1063
|
-
*
|
1279
|
+
*Bernardo de Araujo*
|
1064
1280
|
|
1065
|
-
* Deprecate `
|
1066
|
-
`indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
|
1067
|
-
and `joins_per_query` methods in `DatabaseLimits`.
|
1281
|
+
* Deprecate `DatabaseConfigurations#to_h`. These connection hashes are still available via `ActiveRecord::Base.configurations.configs_for`.
|
1068
1282
|
|
1069
|
-
*
|
1283
|
+
*Eileen Uchitelle*, *John Crepezzi*
|
1070
1284
|
|
1071
|
-
* `
|
1285
|
+
* Add `DatabaseConfig#configuration_hash` to return database configuration hashes with symbol keys, and use all symbol-key configuration hashes internally. Deprecate `DatabaseConfig#config` which returns a String-keyed `Hash` with the same values.
|
1072
1286
|
|
1073
|
-
|
1074
|
-
is an inflexible data model. In order to improve multiple-database
|
1075
|
-
handling in Rails, we've changed this to return an object. Some methods
|
1076
|
-
are provided to make the object behave hash-like in order to ease the
|
1077
|
-
transition process. Since most applications don't manipulate the hash
|
1078
|
-
we've decided to add backwards-compatible functionality that will throw
|
1079
|
-
a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
|
1080
|
-
will use the new version internally and externally.
|
1287
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
1081
1288
|
|
1082
|
-
|
1289
|
+
* Allow column names to be passed to `remove_index` positionally along with other options.
|
1083
1290
|
|
1084
|
-
|
1085
|
-
development:
|
1086
|
-
adapter: sqlite3
|
1087
|
-
database: db/development.sqlite3
|
1088
|
-
```
|
1291
|
+
Passing other options can be necessary to make `remove_index` correctly reversible.
|
1089
1292
|
|
1090
|
-
|
1293
|
+
Before:
|
1091
1294
|
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1295
|
+
add_index :reports, :report_id # => works
|
1296
|
+
add_index :reports, :report_id, unique: true # => works
|
1297
|
+
remove_index :reports, :report_id # => works
|
1298
|
+
remove_index :reports, :report_id, unique: true # => ArgumentError
|
1095
1299
|
|
1096
|
-
|
1300
|
+
After:
|
1097
1301
|
|
1098
|
-
|
1099
|
-
#<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
|
1100
|
-
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
1101
|
-
@spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
|
1102
|
-
]
|
1103
|
-
```
|
1302
|
+
remove_index :reports, :report_id, unique: true # => works
|
1104
1303
|
|
1105
|
-
|
1106
|
-
calling hash methods on the `configurations` hash directly, a new method `configs_for` has
|
1107
|
-
been provided that allows you to select the correct configuration. `env_name` and
|
1108
|
-
`spec_name` arguments are optional. For example, these return an array of
|
1109
|
-
database config objects for the requested environment and a single database config object
|
1110
|
-
will be returned for the requested environment and specification name respectively.
|
1304
|
+
*Eugene Kenny*
|
1111
1305
|
|
1112
|
-
|
1113
|
-
ActiveRecord::Base.configurations.configs_for(env_name: "development")
|
1114
|
-
ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
|
1115
|
-
```
|
1306
|
+
* Allow bulk `ALTER` statements to drop and recreate indexes with the same name.
|
1116
1307
|
|
1117
|
-
*
|
1308
|
+
*Eugene Kenny*
|
1118
1309
|
|
1119
|
-
*
|
1310
|
+
* `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
|
1120
1311
|
|
1121
|
-
|
1122
|
-
production:
|
1123
|
-
adapter: postgresql
|
1124
|
-
advisory_locks: false
|
1125
|
-
```
|
1312
|
+
*Eugene Kenny*
|
1126
1313
|
|
1127
|
-
|
1314
|
+
* Call `while_preventing_writes` directly from `connected_to`.
|
1128
1315
|
|
1129
|
-
|
1316
|
+
In some cases application authors want to use the database switching middleware and make explicit calls with `connected_to`. It's possible for an app to turn off writes and not turn them back on by the time we call `connected_to(role: :writing)`.
|
1130
1317
|
|
1131
|
-
|
1318
|
+
This change allows apps to fix this by assuming if a role is writing we want to allow writes, except in the case it's explicitly turned off.
|
1132
1319
|
|
1133
|
-
*
|
1320
|
+
*Eileen M. Uchitelle*
|
1134
1321
|
|
1135
|
-
|
1322
|
+
* Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
|
1323
|
+
|
1324
|
+
*Kir Shatrov*
|
1136
1325
|
|
1137
|
-
|
1326
|
+
* Stop trying to read yaml file fixtures when loading Active Record fixtures.
|
1138
1327
|
|
1139
|
-
*
|
1328
|
+
*Gannon McGibbon*
|
1140
1329
|
|
1141
|
-
*
|
1142
|
-
seed load in environments without Rails and custom DB configuration
|
1330
|
+
* Deprecate `.reorder(nil)` with `.first` / `.first!` taking non-deterministic result.
|
1143
1331
|
|
1144
|
-
|
1332
|
+
To continue taking non-deterministic result, use `.take` / `.take!` instead.
|
1145
1333
|
|
1146
|
-
*
|
1334
|
+
*Ryuta Kamizono*
|
1147
1335
|
|
1148
|
-
|
1336
|
+
* Preserve user supplied joins order as much as possible.
|
1149
1337
|
|
1150
|
-
|
1338
|
+
Fixes #36761, #34328, #24281, #12953.
|
1151
1339
|
|
1152
1340
|
*Ryuta Kamizono*
|
1153
1341
|
|
1154
|
-
*
|
1342
|
+
* Allow `matches_regex` and `does_not_match_regexp` on the MySQL Arel visitor.
|
1343
|
+
|
1344
|
+
*James Pearson*
|
1345
|
+
|
1346
|
+
* Allow specifying fixtures to be ignored by setting `ignore` in YAML file's '_fixture' section.
|
1155
1347
|
|
1156
|
-
|
1348
|
+
*Tongfei Gao*
|
1157
1349
|
|
1158
|
-
|
1350
|
+
* Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
|
1159
1351
|
|
1160
|
-
*
|
1352
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
1161
1353
|
|
1162
|
-
|
1354
|
+
* Add a warning for enum elements with 'not_' prefix.
|
1163
1355
|
|
1164
|
-
|
1356
|
+
class Foo
|
1357
|
+
enum status: [:sent, :not_sent]
|
1358
|
+
end
|
1165
1359
|
|
1166
|
-
|
1360
|
+
*Edu Depetris*
|
1167
1361
|
|
1168
|
-
|
1362
|
+
* Make currency symbols optional for money column type in PostgreSQL.
|
1169
1363
|
|
1170
|
-
*
|
1364
|
+
*Joel Schneider*
|
1171
1365
|
|
1172
|
-
|
1366
|
+
* Add support for beginless ranges, introduced in Ruby 2.7.
|
1173
1367
|
|
1174
|
-
*
|
1175
|
-
use loaded association ids if present.
|
1368
|
+
*Josh Goodall*
|
1176
1369
|
|
1177
|
-
|
1370
|
+
* Add `database_exists?` method to connection adapters to check if a database exists.
|
1178
1371
|
|
1179
|
-
*
|
1372
|
+
*Guilherme Mansur*
|
1180
1373
|
|
1181
|
-
|
1374
|
+
* Loading the schema for a model that has no `table_name` raises a `TableNotSpecified` error.
|
1182
1375
|
|
1183
|
-
*
|
1376
|
+
*Guilherme Mansur*, *Eugene Kenny*
|
1184
1377
|
|
1185
|
-
|
1378
|
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
1186
1379
|
|
1187
|
-
|
1380
|
+
Fixes #36022.
|
1188
1381
|
|
1189
|
-
*
|
1382
|
+
*Ryuta Kamizono*
|
1190
1383
|
|
1191
|
-
*
|
1384
|
+
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
1385
|
+
|
1386
|
+
Fixes #36465.
|
1192
1387
|
|
1193
|
-
*
|
1388
|
+
*Jeff Doering*
|
1194
1389
|
|
1195
|
-
* Add
|
1390
|
+
* Add support for multiple databases to `rails db:abort_if_pending_migrations`.
|
1196
1391
|
|
1197
|
-
*
|
1392
|
+
*Mark Lee*
|
1198
1393
|
|
1199
|
-
*
|
1394
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
1395
|
+
|
1396
|
+
*Martin R. Schuster*
|
1200
1397
|
|
1201
|
-
|
1398
|
+
* Fix invalid schema when primary key column has a comment.
|
1202
1399
|
|
1203
|
-
|
1400
|
+
Fixes #29966.
|
1204
1401
|
|
1205
|
-
*
|
1402
|
+
*Guilherme Goettems Schneider*
|
1206
1403
|
|
1207
|
-
*
|
1208
|
-
`ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
|
1404
|
+
* Fix table comment also being applied to the primary key column.
|
1209
1405
|
|
1210
|
-
*
|
1406
|
+
*Guilherme Goettems Schneider*
|
1211
1407
|
|
1212
|
-
*
|
1408
|
+
* Allow generated `create_table` migrations to include or skip timestamps.
|
1213
1409
|
|
1214
|
-
*
|
1410
|
+
*Michael Duchemin*
|
1215
1411
|
|
1216
1412
|
|
1217
|
-
Please check [
|
1413
|
+
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activerecord/CHANGELOG.md) for previous changes.
|