activerecord 5.2.4 → 6.0.2.1
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 +718 -564
- data/MIT-LICENSE +3 -1
- data/README.rdoc +4 -2
- data/examples/performance.rb +1 -1
- data/lib/active_record.rb +9 -2
- data/lib/active_record/aggregations.rb +4 -2
- data/lib/active_record/association_relation.rb +15 -6
- data/lib/active_record/associations.rb +20 -15
- data/lib/active_record/associations/association.rb +61 -20
- data/lib/active_record/associations/association_scope.rb +4 -6
- data/lib/active_record/associations/belongs_to_association.rb +36 -42
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +0 -4
- data/lib/active_record/associations/builder/association.rb +14 -18
- data/lib/active_record/associations/builder/belongs_to.rb +19 -52
- data/lib/active_record/associations/builder/collection_association.rb +3 -13
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -38
- data/lib/active_record/associations/builder/has_many.rb +2 -0
- data/lib/active_record/associations/builder/has_one.rb +35 -1
- data/lib/active_record/associations/builder/singular_association.rb +2 -0
- data/lib/active_record/associations/collection_association.rb +12 -23
- data/lib/active_record/associations/collection_proxy.rb +12 -15
- data/lib/active_record/associations/foreign_association.rb +7 -0
- data/lib/active_record/associations/has_many_association.rb +2 -10
- data/lib/active_record/associations/has_many_through_association.rb +14 -14
- data/lib/active_record/associations/has_one_association.rb +28 -30
- data/lib/active_record/associations/has_one_through_association.rb +5 -5
- data/lib/active_record/associations/join_dependency.rb +28 -28
- data/lib/active_record/associations/join_dependency/join_association.rb +9 -10
- data/lib/active_record/associations/join_dependency/join_part.rb +2 -2
- data/lib/active_record/associations/preloader.rb +39 -31
- data/lib/active_record/associations/preloader/association.rb +38 -36
- data/lib/active_record/associations/preloader/through_association.rb +48 -39
- data/lib/active_record/associations/singular_association.rb +2 -16
- data/lib/active_record/attribute_assignment.rb +7 -10
- data/lib/active_record/attribute_methods.rb +28 -100
- data/lib/active_record/attribute_methods/before_type_cast.rb +4 -1
- data/lib/active_record/attribute_methods/dirty.rb +111 -40
- data/lib/active_record/attribute_methods/primary_key.rb +15 -22
- data/lib/active_record/attribute_methods/query.rb +2 -3
- data/lib/active_record/attribute_methods/read.rb +15 -53
- data/lib/active_record/attribute_methods/serialization.rb +1 -1
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
- data/lib/active_record/attribute_methods/write.rb +17 -24
- data/lib/active_record/attributes.rb +13 -0
- data/lib/active_record/autosave_association.rb +2 -2
- data/lib/active_record/base.rb +2 -3
- data/lib/active_record/callbacks.rb +5 -19
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +104 -16
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +17 -4
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +99 -123
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +18 -8
- data/lib/active_record/connection_adapters/abstract/quoting.rb +68 -17
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +19 -12
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +76 -48
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -3
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +132 -53
- data/lib/active_record/connection_adapters/abstract/transaction.rb +96 -56
- data/lib/active_record/connection_adapters/abstract_adapter.rb +187 -43
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +138 -195
- data/lib/active_record/connection_adapters/column.rb +17 -13
- data/lib/active_record/connection_adapters/connection_specification.rb +53 -43
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +6 -10
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +75 -13
- data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +3 -4
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +40 -32
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +14 -6
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +129 -13
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +26 -9
- data/lib/active_record/connection_adapters/postgresql/column.rb +17 -31
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +22 -1
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +9 -7
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +6 -3
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +12 -1
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -91
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +55 -53
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +24 -27
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +164 -74
- data/lib/active_record/connection_adapters/schema_cache.rb +37 -14
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +11 -8
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +120 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +42 -6
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +42 -11
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +129 -141
- data/lib/active_record/connection_handling.rb +155 -26
- data/lib/active_record/core.rb +103 -59
- data/lib/active_record/counter_cache.rb +4 -29
- data/lib/active_record/database_configurations.rb +233 -0
- data/lib/active_record/database_configurations/database_config.rb +37 -0
- data/lib/active_record/database_configurations/hash_config.rb +50 -0
- data/lib/active_record/database_configurations/url_config.rb +79 -0
- data/lib/active_record/dynamic_matchers.rb +1 -1
- data/lib/active_record/enum.rb +37 -7
- data/lib/active_record/errors.rb +15 -7
- data/lib/active_record/explain.rb +1 -1
- data/lib/active_record/fixture_set/model_metadata.rb +33 -0
- data/lib/active_record/fixture_set/render_context.rb +17 -0
- data/lib/active_record/fixture_set/table_row.rb +153 -0
- data/lib/active_record/fixture_set/table_rows.rb +47 -0
- data/lib/active_record/fixtures.rb +145 -472
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +13 -3
- data/lib/active_record/insert_all.rb +179 -0
- data/lib/active_record/integration.rb +68 -16
- data/lib/active_record/internal_metadata.rb +10 -2
- data/lib/active_record/locking/optimistic.rb +5 -6
- data/lib/active_record/locking/pessimistic.rb +3 -3
- data/lib/active_record/log_subscriber.rb +7 -26
- data/lib/active_record/middleware/database_selector.rb +75 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +88 -0
- data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
- data/lib/active_record/migration.rb +100 -81
- data/lib/active_record/migration/command_recorder.rb +50 -6
- data/lib/active_record/migration/compatibility.rb +76 -49
- data/lib/active_record/model_schema.rb +33 -9
- data/lib/active_record/nested_attributes.rb +2 -2
- data/lib/active_record/no_touching.rb +7 -0
- data/lib/active_record/persistence.rb +228 -24
- data/lib/active_record/query_cache.rb +11 -4
- data/lib/active_record/querying.rb +32 -20
- data/lib/active_record/railtie.rb +80 -43
- data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
- data/lib/active_record/railties/controller_runtime.rb +30 -35
- data/lib/active_record/railties/databases.rake +199 -46
- data/lib/active_record/reflection.rb +32 -30
- data/lib/active_record/relation.rb +311 -80
- data/lib/active_record/relation/batches.rb +13 -10
- data/lib/active_record/relation/calculations.rb +53 -47
- data/lib/active_record/relation/delegation.rb +26 -43
- data/lib/active_record/relation/finder_methods.rb +23 -27
- data/lib/active_record/relation/merger.rb +11 -20
- data/lib/active_record/relation/predicate_builder.rb +4 -6
- data/lib/active_record/relation/predicate_builder/array_handler.rb +5 -4
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +1 -4
- data/lib/active_record/relation/predicate_builder/base_handler.rb +1 -2
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -4
- data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
- data/lib/active_record/relation/query_attribute.rb +13 -8
- data/lib/active_record/relation/query_methods.rb +213 -64
- data/lib/active_record/relation/spawn_methods.rb +1 -1
- data/lib/active_record/relation/where_clause.rb +14 -10
- data/lib/active_record/relation/where_clause_factory.rb +1 -2
- data/lib/active_record/result.rb +30 -11
- data/lib/active_record/sanitization.rb +32 -40
- data/lib/active_record/schema.rb +2 -11
- data/lib/active_record/schema_dumper.rb +22 -7
- data/lib/active_record/schema_migration.rb +5 -1
- data/lib/active_record/scoping.rb +8 -8
- data/lib/active_record/scoping/default.rb +4 -5
- data/lib/active_record/scoping/named.rb +20 -15
- data/lib/active_record/statement_cache.rb +30 -3
- data/lib/active_record/store.rb +87 -8
- data/lib/active_record/table_metadata.rb +10 -17
- data/lib/active_record/tasks/database_tasks.rb +194 -25
- data/lib/active_record/tasks/mysql_database_tasks.rb +5 -5
- data/lib/active_record/tasks/postgresql_database_tasks.rb +5 -7
- data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -8
- data/lib/active_record/test_databases.rb +23 -0
- data/lib/active_record/test_fixtures.rb +225 -0
- data/lib/active_record/timestamp.rb +39 -25
- data/lib/active_record/touch_later.rb +4 -2
- data/lib/active_record/transactions.rb +56 -65
- data/lib/active_record/translation.rb +1 -1
- data/lib/active_record/type.rb +3 -4
- data/lib/active_record/type/adapter_specific_registry.rb +1 -8
- data/lib/active_record/type_caster/connection.rb +15 -14
- data/lib/active_record/type_caster/map.rb +1 -4
- data/lib/active_record/validations.rb +1 -0
- data/lib/active_record/validations/uniqueness.rb +15 -27
- data/lib/arel.rb +58 -0
- data/lib/arel/alias_predication.rb +9 -0
- data/lib/arel/attributes.rb +22 -0
- data/lib/arel/attributes/attribute.rb +37 -0
- data/lib/arel/collectors/bind.rb +24 -0
- data/lib/arel/collectors/composite.rb +31 -0
- data/lib/arel/collectors/plain_string.rb +20 -0
- data/lib/arel/collectors/sql_string.rb +20 -0
- data/lib/arel/collectors/substitute_binds.rb +28 -0
- data/lib/arel/crud.rb +42 -0
- data/lib/arel/delete_manager.rb +18 -0
- data/lib/arel/errors.rb +9 -0
- data/lib/arel/expressions.rb +29 -0
- data/lib/arel/factory_methods.rb +49 -0
- data/lib/arel/insert_manager.rb +49 -0
- data/lib/arel/math.rb +45 -0
- data/lib/arel/nodes.rb +68 -0
- data/lib/arel/nodes/and.rb +32 -0
- data/lib/arel/nodes/ascending.rb +23 -0
- data/lib/arel/nodes/binary.rb +52 -0
- data/lib/arel/nodes/bind_param.rb +36 -0
- data/lib/arel/nodes/case.rb +55 -0
- data/lib/arel/nodes/casted.rb +50 -0
- data/lib/arel/nodes/comment.rb +29 -0
- data/lib/arel/nodes/count.rb +12 -0
- data/lib/arel/nodes/delete_statement.rb +45 -0
- data/lib/arel/nodes/descending.rb +23 -0
- data/lib/arel/nodes/equality.rb +18 -0
- data/lib/arel/nodes/extract.rb +24 -0
- data/lib/arel/nodes/false.rb +16 -0
- data/lib/arel/nodes/full_outer_join.rb +8 -0
- data/lib/arel/nodes/function.rb +44 -0
- data/lib/arel/nodes/grouping.rb +8 -0
- data/lib/arel/nodes/in.rb +8 -0
- data/lib/arel/nodes/infix_operation.rb +80 -0
- data/lib/arel/nodes/inner_join.rb +8 -0
- data/lib/arel/nodes/insert_statement.rb +37 -0
- data/lib/arel/nodes/join_source.rb +20 -0
- data/lib/arel/nodes/matches.rb +18 -0
- data/lib/arel/nodes/named_function.rb +23 -0
- data/lib/arel/nodes/node.rb +50 -0
- data/lib/arel/nodes/node_expression.rb +13 -0
- data/lib/arel/nodes/outer_join.rb +8 -0
- data/lib/arel/nodes/over.rb +15 -0
- data/lib/arel/nodes/regexp.rb +16 -0
- data/lib/arel/nodes/right_outer_join.rb +8 -0
- data/lib/arel/nodes/select_core.rb +67 -0
- data/lib/arel/nodes/select_statement.rb +41 -0
- data/lib/arel/nodes/sql_literal.rb +16 -0
- data/lib/arel/nodes/string_join.rb +11 -0
- data/lib/arel/nodes/table_alias.rb +27 -0
- data/lib/arel/nodes/terminal.rb +16 -0
- data/lib/arel/nodes/true.rb +16 -0
- data/lib/arel/nodes/unary.rb +45 -0
- data/lib/arel/nodes/unary_operation.rb +20 -0
- data/lib/arel/nodes/unqualified_column.rb +22 -0
- data/lib/arel/nodes/update_statement.rb +41 -0
- data/lib/arel/nodes/values_list.rb +9 -0
- data/lib/arel/nodes/window.rb +126 -0
- data/lib/arel/nodes/with.rb +11 -0
- data/lib/arel/order_predications.rb +13 -0
- data/lib/arel/predications.rb +257 -0
- data/lib/arel/select_manager.rb +271 -0
- data/lib/arel/table.rb +110 -0
- data/lib/arel/tree_manager.rb +72 -0
- data/lib/arel/update_manager.rb +34 -0
- data/lib/arel/visitors.rb +20 -0
- data/lib/arel/visitors/depth_first.rb +204 -0
- data/lib/arel/visitors/dot.rb +297 -0
- data/lib/arel/visitors/ibm_db.rb +34 -0
- data/lib/arel/visitors/informix.rb +62 -0
- data/lib/arel/visitors/mssql.rb +157 -0
- data/lib/arel/visitors/mysql.rb +83 -0
- data/lib/arel/visitors/oracle.rb +159 -0
- data/lib/arel/visitors/oracle12.rb +66 -0
- data/lib/arel/visitors/postgresql.rb +110 -0
- data/lib/arel/visitors/sqlite.rb +39 -0
- data/lib/arel/visitors/to_sql.rb +889 -0
- data/lib/arel/visitors/visitor.rb +46 -0
- data/lib/arel/visitors/where_sql.rb +23 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/rails/generators/active_record/migration.rb +14 -1
- data/lib/rails/generators/active_record/migration/migration_generator.rb +2 -5
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +1 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -2
- data/lib/rails/generators/active_record/model/model_generator.rb +1 -0
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
- metadata +110 -25
- data/lib/active_record/collection_cache_key.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b844e5b4888dfdc55740902f2bcc3536f40fef6e186eef4ccd0e8619203fc9cf
|
4
|
+
data.tar.gz: 798c0127c79bc052cf8030c7878b77fcc6de6e52312699fb9006e8793e814740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0038869b12cb3dfa9f94243e3cedbaf83ea430fbdd120d61d95a880f5b67d00b848ce90ce977877170e7b6d188ebe36b8426698127202c859cda743773e3d84a'
|
7
|
+
data.tar.gz: 4de1fa66740767dc99d3d2dab5c1a2f962cbe162b9b0412706f17ab7b62f8a01d0effeada1d6f7616e6ead9f8ea8f6dd1b4b7232cd5378594f26c06fa06cc43f
|
data/CHANGELOG.md
CHANGED
@@ -1,977 +1,1131 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 6.0.2.1 (December 18, 2019) ##
|
2
2
|
|
3
|
-
*
|
4
|
-
|
5
|
-
Prior to the fix, when there was a circular series of `autosave: true`
|
6
|
-
associations, the callback for a `has_many` association was run while
|
7
|
-
another instance of the same callback on the same association hadn't
|
8
|
-
finished running. When control returned to the first instance of the
|
9
|
-
callback, the instance variable had changed, and subsequent associated
|
10
|
-
records weren't saved correctly. Specifically, the ID field for the
|
11
|
-
`belongs_to` corresponding to the `has_many` was `nil`.
|
12
|
-
|
13
|
-
Fixes #28080.
|
14
|
-
|
15
|
-
*Larry Reid*
|
3
|
+
* No changes.
|
16
4
|
|
17
|
-
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
18
5
|
|
19
|
-
|
6
|
+
## Rails 6.0.2 (December 13, 2019) ##
|
20
7
|
|
21
|
-
|
8
|
+
* Share the same connection pool for primary and replica databases in the
|
9
|
+
transactional tests for the same database.
|
22
10
|
|
23
|
-
*
|
11
|
+
*Edouard Chin*
|
24
12
|
|
25
|
-
|
13
|
+
* Fix the preloader when one record is fetched using `after_initialize`
|
14
|
+
but not the entire collection.
|
26
15
|
|
27
|
-
*
|
16
|
+
*Bradley Price*
|
28
17
|
|
29
|
-
|
30
|
-
|
31
|
-
*Jeff Doering*
|
32
|
-
|
33
|
-
* Assign all attributes before calling `build` to ensure the child record is visible in
|
34
|
-
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
18
|
+
* Fix collection callbacks not terminating when `:abort` is thrown.
|
35
19
|
|
36
|
-
|
20
|
+
*Edouard Chin*, *Ryuta Kamizono*
|
37
21
|
|
38
|
-
|
22
|
+
* Correctly deprecate `where.not` working as NOR for relations.
|
39
23
|
|
24
|
+
12a9664 deprecated where.not working as NOR, however
|
25
|
+
doing a relation query like `where.not(relation: { ... })`
|
26
|
+
wouldn't be properly deprecated and `where.not` would work as
|
27
|
+
NAND instead.
|
40
28
|
|
41
|
-
|
29
|
+
*Edouard Chin*
|
42
30
|
|
43
|
-
* Fix
|
31
|
+
* Fix `db:migrate` task with multiple databases to restore the connection
|
32
|
+
to the previous database.
|
44
33
|
|
45
|
-
|
34
|
+
The migrate task iterates and establish a connection over each db
|
35
|
+
resulting in the last one to be used by subsequent rake tasks.
|
36
|
+
We should reestablish a connection to the connection that was
|
37
|
+
established before the migrate tasks was run
|
46
38
|
|
47
|
-
*
|
39
|
+
*Edouard Chin*
|
48
40
|
|
49
|
-
* Fix
|
41
|
+
* Fix multi-threaded issue for `AcceptanceValidator`.
|
50
42
|
|
51
43
|
*Ryuta Kamizono*
|
52
44
|
|
53
|
-
* Don't allow `where` with invalid value matches to nil values.
|
54
45
|
|
55
|
-
|
46
|
+
## Rails 6.0.1 (November 5, 2019) ##
|
56
47
|
|
57
|
-
|
48
|
+
* Common Table Expressions are allowed on read-only connections.
|
58
49
|
|
59
|
-
*
|
50
|
+
*Chris Morris*
|
60
51
|
|
61
|
-
|
52
|
+
* New record instantiation respects `unscope`.
|
62
53
|
|
63
|
-
|
54
|
+
*Ryuta Kamizono*
|
64
55
|
|
65
|
-
*
|
56
|
+
* Fixed a case where `find_in_batches` could halt too early.
|
66
57
|
|
67
|
-
|
58
|
+
*Takayuki Nakata*
|
68
59
|
|
69
|
-
*
|
60
|
+
* Autosaved associations always perform validations when a custom validation
|
61
|
+
context is used.
|
70
62
|
|
71
|
-
|
63
|
+
*Tekin Suleyman*
|
72
64
|
|
73
|
-
*
|
65
|
+
* `sql.active_record` notifications now include the `:connection` in
|
66
|
+
their payloads.
|
74
67
|
|
75
|
-
|
68
|
+
*Eugene Kenny*
|
76
69
|
|
70
|
+
* A rollback encountered in an `after_commit` callback does not reset
|
71
|
+
previously-committed record state.
|
77
72
|
|
78
|
-
|
73
|
+
*Ryuta Kamizono*
|
79
74
|
|
80
|
-
*
|
75
|
+
* Fixed that join order was lost when eager-loading.
|
81
76
|
|
77
|
+
*Ryuta Kamizono*
|
82
78
|
|
83
|
-
|
79
|
+
* `DESCRIBE` queries are allowed on read-only connections.
|
84
80
|
|
85
|
-
*
|
81
|
+
*Dylan Thacker-Smith*
|
86
82
|
|
87
|
-
|
83
|
+
* Fixed that records that had been `inspect`ed could not be marshaled.
|
88
84
|
|
89
|
-
*
|
85
|
+
*Eugene Kenny*
|
90
86
|
|
91
|
-
|
87
|
+
* The connection pool reaper thread is respawned in forked processes. This
|
88
|
+
fixes that idle connections in forked processes wouldn't be reaped.
|
92
89
|
|
93
|
-
*
|
90
|
+
*John Hawthorn*
|
94
91
|
|
95
|
-
|
96
|
-
|
92
|
+
* The memoized result of `ActiveRecord::Relation#take` is properly cleared
|
93
|
+
when `ActiveRecord::Relation#reset` or `ActiveRecord::Relation#reload`
|
94
|
+
is called.
|
97
95
|
|
98
|
-
*
|
96
|
+
*Anmol Arora*
|
99
97
|
|
100
|
-
*
|
98
|
+
* Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
|
101
99
|
|
102
|
-
|
103
|
-
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
100
|
+
*Hiroyuki Ishii*
|
104
101
|
|
105
|
-
|
106
|
-
class DeveloperName < ActiveRecord::Type::String
|
107
|
-
def deserialize(value)
|
108
|
-
"Developer: #{value}"
|
109
|
-
end
|
110
|
-
end
|
102
|
+
* `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
|
111
103
|
|
112
|
-
|
113
|
-
self.table_name = "developers"
|
104
|
+
*Eugene Kenny*
|
114
105
|
|
115
|
-
|
106
|
+
* Call `while_preventing_writes` directly from `connected_to`.
|
116
107
|
|
117
|
-
|
118
|
-
end
|
108
|
+
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)`.
|
119
109
|
|
120
|
-
|
121
|
-
developer.update_column :name, "name"
|
110
|
+
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.
|
122
111
|
|
123
|
-
|
124
|
-
puts loaded_developer.name # should be "Developer: name" but it's just "name"
|
125
|
-
```
|
112
|
+
*Eileen M. Uchitelle*
|
126
113
|
|
127
|
-
|
114
|
+
* Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
|
128
115
|
|
129
|
-
*
|
116
|
+
*Kir Shatrov*
|
130
117
|
|
131
|
-
*Emmanuel Byrd*
|
132
118
|
|
133
|
-
|
134
|
-
if the attribute does not exist.
|
119
|
+
## Rails 6.0.0 (August 16, 2019) ##
|
135
120
|
|
136
|
-
|
121
|
+
* Preserve user supplied joins order as much as possible.
|
137
122
|
|
138
|
-
|
123
|
+
Fixes #36761, #34328, #24281, #12953.
|
139
124
|
|
140
125
|
*Ryuta Kamizono*
|
141
126
|
|
142
|
-
*
|
127
|
+
* Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
|
143
128
|
|
144
|
-
*Eileen
|
129
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
145
130
|
|
146
|
-
*
|
131
|
+
* Add a warning for enum elements with 'not_' prefix.
|
147
132
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
* Fix duplicated record creation when using nested attributes with `create_with`.
|
153
|
-
|
154
|
-
*Darwin Wu*
|
155
|
-
|
156
|
-
* Fix regression setting children record in parent `before_save` callback.
|
157
|
-
|
158
|
-
*Guo Xiang Tan*
|
133
|
+
class Foo
|
134
|
+
enum status: [:sent, :not_sent]
|
135
|
+
end
|
159
136
|
|
160
|
-
*
|
137
|
+
*Edu Depetris*
|
161
138
|
|
162
|
-
|
139
|
+
* Make currency symbols optional for money column type in PostgreSQL
|
163
140
|
|
164
|
-
*
|
141
|
+
*Joel Schneider*
|
165
142
|
|
166
|
-
*Yuya Tanaka*
|
167
143
|
|
168
|
-
|
144
|
+
## Rails 6.0.0.rc2 (July 22, 2019) ##
|
169
145
|
|
170
|
-
|
146
|
+
* Add database_exists? method to connection adapters to check if a database exists.
|
171
147
|
|
172
|
-
*
|
148
|
+
*Guilherme Mansur*
|
173
149
|
|
174
|
-
|
150
|
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
175
151
|
|
176
|
-
|
152
|
+
Fixes #36022.
|
177
153
|
|
178
154
|
*Ryuta Kamizono*
|
179
155
|
|
180
|
-
*
|
156
|
+
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
181
157
|
|
182
|
-
|
158
|
+
Fixes #36465.
|
183
159
|
|
160
|
+
*Jeff Doering*
|
184
161
|
|
185
|
-
|
162
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
186
163
|
|
187
|
-
*
|
164
|
+
*Martin R. Schuster*
|
188
165
|
|
166
|
+
* Fix invalid schema when primary key column has a comment.
|
189
167
|
|
190
|
-
|
168
|
+
Fixes #29966.
|
191
169
|
|
192
|
-
*
|
170
|
+
*Guilherme Goettems Schneider*
|
193
171
|
|
194
|
-
|
172
|
+
* Fix table comment also being applied to the primary key column.
|
195
173
|
|
196
|
-
*
|
174
|
+
*Guilherme Goettems Schneider*
|
197
175
|
|
198
|
-
*
|
176
|
+
* Fix merging left_joins to maintain its own `join_type` context.
|
199
177
|
|
200
|
-
|
178
|
+
Fixes #36103.
|
201
179
|
|
202
|
-
*
|
180
|
+
*Ryuta Kamizono*
|
203
181
|
|
204
|
-
*Nikolay Kondratyev*
|
205
182
|
|
206
|
-
|
183
|
+
## Rails 6.0.0.rc1 (April 24, 2019) ##
|
207
184
|
|
208
|
-
|
185
|
+
* Add `touch` option to `has_one` association.
|
209
186
|
|
210
|
-
*
|
187
|
+
*Abhay Nikam*
|
211
188
|
|
212
|
-
|
189
|
+
* Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
|
213
190
|
|
214
|
-
|
215
|
-
|
216
|
-
|
191
|
+
```ruby
|
192
|
+
all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
|
193
|
+
assert_equal all, PriceEstimate.all.map(&:estimate_of)
|
194
|
+
```
|
217
195
|
|
218
|
-
|
196
|
+
In Rails 6.0:
|
219
197
|
|
220
|
-
|
198
|
+
```ruby
|
199
|
+
sapphire = treasures(:sapphire)
|
200
|
+
|
201
|
+
nor = all.reject { |e|
|
202
|
+
e.estimate_of_type == sapphire.class.polymorphic_name
|
203
|
+
}.reject { |e|
|
204
|
+
e.estimate_of_id == sapphire.id
|
205
|
+
}
|
206
|
+
assert_equal [cars(:honda)], nor
|
207
|
+
|
208
|
+
without_sapphire = PriceEstimate.where.not(
|
209
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
210
|
+
)
|
211
|
+
assert_equal nor, without_sapphire.map(&:estimate_of)
|
212
|
+
```
|
221
213
|
|
222
|
-
|
214
|
+
In Rails 6.1:
|
223
215
|
|
224
|
-
|
216
|
+
```ruby
|
217
|
+
sapphire = treasures(:sapphire)
|
225
218
|
|
226
|
-
|
219
|
+
nand = all - [sapphire]
|
220
|
+
assert_equal [treasures(:diamond), cars(:honda)], nand
|
227
221
|
|
228
|
-
|
222
|
+
without_sapphire = PriceEstimate.where.not(
|
223
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
224
|
+
)
|
225
|
+
assert_equal nand, without_sapphire.map(&:estimate_of)
|
226
|
+
```
|
229
227
|
|
230
228
|
*Ryuta Kamizono*
|
231
229
|
|
232
|
-
*
|
230
|
+
* Fix dirty tracking after rollback.
|
233
231
|
|
234
|
-
Fixes #
|
232
|
+
Fixes #15018, #30167, #33868.
|
235
233
|
|
236
234
|
*Ryuta Kamizono*
|
237
235
|
|
238
|
-
*
|
236
|
+
* Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
|
237
|
+
the versioned entries in `ActiveSupport::Cache`. This also means that
|
238
|
+
`ActiveRecord::Relation#cache_key` will now return a stable key that does not
|
239
|
+
include the max timestamp or count any more.
|
239
240
|
|
240
|
-
|
241
|
+
NOTE: This feature is turned off by default, and `cache_key` will still return
|
242
|
+
cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
|
243
|
+
That's the setting for all new apps on Rails 6.0+
|
241
244
|
|
242
|
-
*
|
243
|
-
wrongly persists through record.
|
245
|
+
*Lachlan Sylvester*
|
244
246
|
|
245
|
-
|
247
|
+
* Fix dirty tracking for `touch` to track saved changes.
|
246
248
|
|
247
|
-
|
249
|
+
Fixes #33429.
|
248
250
|
|
249
|
-
*
|
250
|
-
query cache.
|
251
|
+
*Ryuta Kamzono*
|
251
252
|
|
252
|
-
|
253
|
+
* `change_column_comment` and `change_table_comment` are invertible only if
|
254
|
+
`to` and `from` options are specified.
|
253
255
|
|
256
|
+
*Yoshiyuki Kinjo*
|
254
257
|
|
255
|
-
|
258
|
+
* Don't call commit/rollback callbacks when a record isn't saved.
|
256
259
|
|
257
|
-
|
260
|
+
Fixes #29747.
|
258
261
|
|
259
|
-
*
|
262
|
+
*Ryuta Kamizono*
|
260
263
|
|
261
|
-
*
|
264
|
+
* Fix circular `autosave: true` causes invalid records to be saved.
|
262
265
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
+
Prior to the fix, when there was a circular series of `autosave: true`
|
267
|
+
associations, the callback for a `has_many` association was run while
|
268
|
+
another instance of the same callback on the same association hadn't
|
269
|
+
finished running. When control returned to the first instance of the
|
270
|
+
callback, the instance variable had changed, and subsequent associated
|
271
|
+
records weren't saved correctly. Specifically, the ID field for the
|
272
|
+
`belongs_to` corresponding to the `has_many` was `nil`.
|
266
273
|
|
267
|
-
Fixes #
|
274
|
+
Fixes #28080.
|
268
275
|
|
269
|
-
*
|
276
|
+
*Larry Reid*
|
270
277
|
|
271
|
-
*
|
278
|
+
* Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
|
272
279
|
|
273
|
-
|
274
|
-
because until #24542 the quoting for time columns didn't remove the date
|
275
|
-
component. To ensure that values are consistent we now normalize the
|
276
|
-
date component to 2001-01-01 on reading and writing.
|
280
|
+
Before:
|
277
281
|
|
278
|
-
|
282
|
+
```ruby
|
283
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
284
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
285
|
+
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
|
286
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
|
287
|
+
```
|
279
288
|
|
280
|
-
|
289
|
+
After:
|
281
290
|
|
282
|
-
|
283
|
-
|
284
|
-
|
291
|
+
```ruby
|
292
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
293
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
294
|
+
add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
|
295
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
|
296
|
+
```
|
285
297
|
|
286
|
-
*
|
298
|
+
*Ryuta Kamizono*
|
287
299
|
|
288
|
-
*
|
289
|
-
|
300
|
+
* Association loading isn't to be affected by scoping consistently
|
301
|
+
whether preloaded / eager loaded or not, with the exception of `unscoped`.
|
290
302
|
|
291
|
-
|
303
|
+
Before:
|
292
304
|
|
293
|
-
|
305
|
+
```ruby
|
306
|
+
Post.where("1=0").scoping do
|
307
|
+
Comment.find(1).post # => nil
|
308
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
309
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
310
|
+
end
|
311
|
+
```
|
294
312
|
|
295
|
-
|
313
|
+
After:
|
296
314
|
|
297
|
-
|
315
|
+
```ruby
|
316
|
+
Post.where("1=0").scoping do
|
317
|
+
Comment.find(1).post # => #<Post id: 1, ...>
|
318
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
319
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
320
|
+
end
|
321
|
+
```
|
298
322
|
|
299
|
-
|
323
|
+
Fixes #34638, #35398.
|
300
324
|
|
301
325
|
*Ryuta Kamizono*
|
302
326
|
|
303
|
-
*
|
304
|
-
`ActiveRecord::FinderMethods#limited_ids_for` use correct primary key values
|
305
|
-
even if `ORDER BY` columns include other table's primary key.
|
306
|
-
|
307
|
-
Fixes #28364.
|
308
|
-
|
309
|
-
*Takumi Kagiyama*
|
327
|
+
* Add `rails db:prepare` to migrate or setup a database.
|
310
328
|
|
311
|
-
|
329
|
+
Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
|
312
330
|
|
313
|
-
|
331
|
+
*Roberto Miranda*
|
314
332
|
|
315
|
-
|
333
|
+
* Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
|
316
334
|
|
317
|
-
*
|
335
|
+
*DHH*
|
318
336
|
|
319
|
-
|
337
|
+
* Assign all attributes before calling `build` to ensure the child record is visible in
|
338
|
+
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
320
339
|
|
321
|
-
|
322
|
-
Using a `Relation` for performing queries is the prefered API.
|
340
|
+
Fixes #33249.
|
323
341
|
|
324
|
-
*
|
342
|
+
*Ryan H. Kerr*
|
325
343
|
|
326
|
-
*
|
344
|
+
* Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
|
327
345
|
|
328
346
|
```
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
# Before: WHERE `customers`.`balance` = NULL
|
333
|
-
# After : WHERE `customers`.`balance` = 50
|
347
|
+
account.memberships.extract_associated(:user)
|
348
|
+
# => Returns collection of User records
|
334
349
|
```
|
335
350
|
|
336
|
-
|
337
|
-
|
338
|
-
*Yutaro Kanagawa*
|
351
|
+
*DHH*
|
339
352
|
|
340
|
-
*
|
353
|
+
* Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
|
341
354
|
|
342
|
-
|
355
|
+
For example:
|
343
356
|
|
344
|
-
|
357
|
+
```
|
358
|
+
Post.where(id: 123).annotate("this is a comment").to_sql
|
359
|
+
# SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
|
360
|
+
```
|
345
361
|
|
346
|
-
|
362
|
+
This can be useful in instrumentation or other analysis of issued queries.
|
347
363
|
|
348
|
-
|
364
|
+
*Matt Yoho*
|
349
365
|
|
350
|
-
|
366
|
+
* Support Optimizer Hints.
|
351
367
|
|
352
|
-
|
368
|
+
In most databases, a way to control the optimizer is by using optimizer hints,
|
369
|
+
which can be specified within individual statements.
|
353
370
|
|
354
|
-
|
371
|
+
Example (for MySQL):
|
355
372
|
|
356
|
-
|
373
|
+
Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
|
374
|
+
# SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
|
357
375
|
|
358
|
-
|
376
|
+
Example (for PostgreSQL with pg_hint_plan):
|
359
377
|
|
360
|
-
|
378
|
+
Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
|
379
|
+
# SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
|
361
380
|
|
362
|
-
|
381
|
+
See also:
|
363
382
|
|
364
|
-
*
|
383
|
+
* https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
|
384
|
+
* https://pghintplan.osdn.jp/pg_hint_plan.html
|
385
|
+
* https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
|
386
|
+
* https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
|
387
|
+
* https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
|
365
388
|
|
366
|
-
|
389
|
+
*Ryuta Kamizono*
|
367
390
|
|
368
|
-
|
391
|
+
* Fix query attribute method on user-defined attribute to be aware of typecasted value.
|
369
392
|
|
370
|
-
|
393
|
+
For example, the following code no longer return false as casted non-empty string:
|
371
394
|
|
372
|
-
|
395
|
+
```
|
396
|
+
class Post < ActiveRecord::Base
|
397
|
+
attribute :user_defined_text, :text
|
398
|
+
end
|
373
399
|
|
374
|
-
|
375
|
-
|
376
|
-
has_many :books, through: :author
|
377
|
-
has_many :subscriptions, through: :books
|
378
|
-
end
|
400
|
+
Post.new(user_defined_text: "false").user_defined_text? # => true
|
401
|
+
```
|
379
402
|
|
380
|
-
|
381
|
-
has_one :post
|
382
|
-
has_many :books
|
383
|
-
has_many :subscriptions, through: :books
|
384
|
-
end
|
403
|
+
*Yuji Kamijima*
|
385
404
|
|
386
|
-
|
387
|
-
belongs_to :author
|
388
|
-
has_many :subscriptions
|
389
|
-
end
|
405
|
+
* Quote empty ranges like other empty enumerables.
|
390
406
|
|
391
|
-
|
392
|
-
belongs_to :book
|
393
|
-
end
|
407
|
+
*Patrick Rebsch*
|
394
408
|
|
395
|
-
|
409
|
+
* Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
|
410
|
+
allowing bulk inserts akin to the bulk updates provided by `update_all` and
|
411
|
+
bulk deletes by `delete_all`.
|
396
412
|
|
397
|
-
|
413
|
+
Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
|
414
|
+
for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
|
415
|
+
for MySQL.
|
398
416
|
|
399
|
-
|
417
|
+
*Bob Lail*
|
400
418
|
|
401
|
-
|
402
|
-
|
419
|
+
* Add `rails db:seed:replant` that truncates tables of each database
|
420
|
+
for current environment and loads the seeds.
|
403
421
|
|
404
|
-
|
422
|
+
*bogdanvlviv*, *DHH*
|
405
423
|
|
406
|
-
|
424
|
+
* Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
|
407
425
|
|
408
|
-
*
|
409
|
-
The `first(n)` finder now respects the `limit()`, making it consistent
|
410
|
-
with `relation.to_a.first(n)`, and also with the behavior of `last(n)`.
|
426
|
+
*bogdanvlviv*
|
411
427
|
|
412
|
-
|
428
|
+
* Deprecate mismatched collation comparison for uniqueness validator.
|
413
429
|
|
414
|
-
|
430
|
+
Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
|
431
|
+
To continue case sensitive comparison on the case insensitive column,
|
432
|
+
pass `case_sensitive: true` option explicitly to the uniqueness validator.
|
415
433
|
|
416
|
-
*
|
417
|
-
SQL queries for association counting.
|
434
|
+
*Ryuta Kamizono*
|
418
435
|
|
419
|
-
|
436
|
+
* Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
|
420
437
|
|
421
|
-
|
438
|
+
Fixes #27340.
|
422
439
|
|
423
|
-
*
|
440
|
+
*Willian Gustavo Veiga*
|
424
441
|
|
425
|
-
*
|
442
|
+
* Add negative scopes for all enum values.
|
426
443
|
|
427
|
-
|
444
|
+
Example:
|
428
445
|
|
429
|
-
|
446
|
+
class Post < ActiveRecord::Base
|
447
|
+
enum status: %i[ drafted active trashed ]
|
448
|
+
end
|
430
449
|
|
431
|
-
|
450
|
+
Post.not_drafted # => where.not(status: :drafted)
|
451
|
+
Post.not_active # => where.not(status: :active)
|
452
|
+
Post.not_trashed # => where.not(status: :trashed)
|
432
453
|
|
433
|
-
*
|
434
|
-
information.
|
454
|
+
*DHH*
|
435
455
|
|
436
|
-
|
456
|
+
* Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
|
437
457
|
|
438
|
-
|
458
|
+
Fixes #35214.
|
439
459
|
|
440
|
-
|
441
|
-
of database queries in the log to facilitate N+1 query resolution
|
442
|
-
and other debugging.
|
460
|
+
*Juani Villarejo*
|
443
461
|
|
444
|
-
Enabled in development only for new and upgraded applications. Not
|
445
|
-
recommended for use in the production environment since it relies
|
446
|
-
on Ruby's `Kernel#caller_locations` which is fairly slow.
|
447
462
|
|
448
|
-
|
463
|
+
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
449
464
|
|
450
|
-
*
|
465
|
+
* No changes.
|
451
466
|
|
452
|
-
```
|
453
|
-
# create_table :posts do |t|
|
454
|
-
# t.integer :comments_count, default: 0
|
455
|
-
# t.integer :lock_version
|
456
|
-
# t.timestamps
|
457
|
-
# end
|
458
|
-
class Post < ApplicationRecord
|
459
|
-
end
|
460
467
|
|
461
|
-
|
462
|
-
# t.belongs_to :post
|
463
|
-
# end
|
464
|
-
class Comment < ApplicationRecord
|
465
|
-
belongs_to :post, touch: true, counter_cache: true
|
466
|
-
end
|
467
|
-
```
|
468
|
+
## Rails 6.0.0.beta2 (February 25, 2019) ##
|
468
469
|
|
469
|
-
|
470
|
-
```
|
471
|
-
post = Post.create!
|
472
|
-
# => begin transaction
|
473
|
-
INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
|
474
|
-
VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
|
475
|
-
commit transaction
|
470
|
+
* Fix prepared statements caching to be enabled even when query caching is enabled.
|
476
471
|
|
477
|
-
|
478
|
-
# => begin transaction
|
479
|
-
INSERT INTO "comments" ("post_id") VALUES (1)
|
472
|
+
*Ryuta Kamizono*
|
480
473
|
|
481
|
-
|
482
|
-
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
474
|
+
* Ensure `update_all` series cares about optimistic locking.
|
483
475
|
|
484
|
-
|
485
|
-
"lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
|
486
|
-
rollback transaction
|
487
|
-
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
476
|
+
*Ryuta Kamizono*
|
488
477
|
|
489
|
-
|
490
|
-
# => begin transaction
|
491
|
-
DELETE FROM "comments" WHERE "comments"."id" = 1
|
478
|
+
* Don't allow `where` with non numeric string matches to 0 values.
|
492
479
|
|
493
|
-
|
494
|
-
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
480
|
+
*Ryuta Kamizono*
|
495
481
|
|
496
|
-
|
497
|
-
"lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
|
498
|
-
rollback transaction
|
499
|
-
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
500
|
-
```
|
482
|
+
* Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
|
501
483
|
|
502
|
-
|
503
|
-
|
504
|
-
post = Post.create!
|
505
|
-
# => begin transaction
|
506
|
-
INSERT INTO "posts" ("created_at", "updated_at", "lock_version")
|
507
|
-
VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
|
508
|
-
commit transaction
|
484
|
+
`destroy_by` allows relation to find all the records matching the condition and perform
|
485
|
+
`destroy_all` on the matched records.
|
509
486
|
|
510
|
-
|
511
|
-
# => begin transaction
|
512
|
-
INSERT INTO "comments" ("post_id") VALUES (1)
|
487
|
+
Example:
|
513
488
|
|
514
|
-
|
515
|
-
|
516
|
-
"updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
|
517
|
-
commit transaction
|
489
|
+
Person.destroy_by(name: 'David')
|
490
|
+
Person.destroy_by(name: 'David', rating: 4)
|
518
491
|
|
519
|
-
|
520
|
-
|
521
|
-
DELETE FROM "comments" WHERE "comments"."id" = 1
|
492
|
+
david = Person.find_by(name: 'David')
|
493
|
+
david.posts.destroy_by(id: [1, 2, 3])
|
522
494
|
|
523
|
-
|
524
|
-
|
525
|
-
"updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
|
526
|
-
commit transaction
|
527
|
-
```
|
495
|
+
`delete_by` allows relation to find all the records matching the condition and perform
|
496
|
+
`delete_all` on the matched records.
|
528
497
|
|
529
|
-
|
498
|
+
Example:
|
530
499
|
|
531
|
-
|
500
|
+
Person.delete_by(name: 'David')
|
501
|
+
Person.delete_by(name: 'David', rating: 4)
|
532
502
|
|
533
|
-
|
503
|
+
david = Person.find_by(name: 'David')
|
504
|
+
david.posts.delete_by(id: [1, 2, 3])
|
534
505
|
|
535
|
-
|
506
|
+
*Abhay Nikam*
|
536
507
|
|
537
|
-
|
508
|
+
* Don't allow `where` with invalid value matches to nil values.
|
538
509
|
|
539
|
-
|
510
|
+
Fixes #33624.
|
540
511
|
|
541
|
-
*
|
512
|
+
*Ryuta Kamizono*
|
542
513
|
|
543
|
-
|
514
|
+
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
|
544
515
|
|
545
|
-
*
|
516
|
+
*Ryuta Kamizono*
|
546
517
|
|
547
|
-
*
|
548
|
-
|
518
|
+
* Deprecate using class level querying methods if the receiver scope
|
519
|
+
regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
|
549
520
|
|
550
521
|
*Ryuta Kamizono*
|
551
522
|
|
552
|
-
*
|
553
|
-
migrating up, e.g. populating a new column.
|
523
|
+
* Allow applications to automatically switch connections.
|
554
524
|
|
555
|
-
|
525
|
+
Adds a middleware and configuration options that can be used in your
|
526
|
+
application to automatically switch between the writing and reading
|
527
|
+
database connections.
|
556
528
|
|
557
|
-
|
558
|
-
|
529
|
+
`GET` and `HEAD` requests will read from the replica unless there was
|
530
|
+
a write in the last 2 seconds, otherwise they will read from the primary.
|
531
|
+
Non-get requests will always write to the primary. The middleware accepts
|
532
|
+
an argument for a Resolver class and an Operations class where you are able
|
533
|
+
to change how the auto-switcher works to be most beneficial for your
|
534
|
+
application.
|
559
535
|
|
560
|
-
|
561
|
-
|
562
|
-
Article.order("LENGTH(title)")
|
563
|
-
```
|
536
|
+
To use the middleware in your application you can use the following
|
537
|
+
configuration options:
|
564
538
|
|
565
|
-
After:
|
566
539
|
```
|
567
|
-
|
540
|
+
config.active_record.database_selector = { delay: 2.seconds }
|
541
|
+
config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
|
542
|
+
config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
|
568
543
|
```
|
569
544
|
|
570
|
-
|
571
|
-
|
572
|
-
mistaken belief that only column names will be accepted.
|
573
|
-
|
574
|
-
Raw SQL strings will now cause a deprecation warning, which will
|
575
|
-
become an UnknownAttributeReference error in Rails 6.0. Applications
|
576
|
-
can opt in to the future behavior by setting `allow_unsafe_raw_sql`
|
577
|
-
to `:disabled`.
|
545
|
+
To change the database selection strategy, pass a custom class to the
|
546
|
+
configuration options:
|
578
547
|
|
579
|
-
Common and judged-safe string values (such as simple column
|
580
|
-
references) are unaffected:
|
581
548
|
```
|
582
|
-
|
549
|
+
config.active_record.database_selector = { delay: 10.seconds }
|
550
|
+
config.active_record.database_resolver = MyResolver
|
551
|
+
config.active_record.database_resolver_context = MyResolver::MyCookies
|
583
552
|
```
|
584
553
|
|
585
|
-
*
|
586
|
-
|
587
|
-
* `update_all` will now pass its values to `Type#cast` before passing them to
|
588
|
-
`Type#serialize`. This means that `update_all(foo: 'true')` will properly
|
589
|
-
persist a boolean.
|
590
|
-
|
591
|
-
*Sean Griffin*
|
554
|
+
*Eileen M. Uchitelle*
|
592
555
|
|
593
|
-
*
|
594
|
-
when statement timeout exceeded.
|
556
|
+
* MySQL: Support `:size` option to change text and blob size.
|
595
557
|
|
596
558
|
*Ryuta Kamizono*
|
597
559
|
|
598
|
-
*
|
599
|
-
`bin/rails db:migrate` with empty VERSION behaves as without `VERSION`.
|
600
|
-
Check a format of `VERSION`: Allow a migration version number
|
601
|
-
or name of a migration file. Raise error if format of `VERSION` is invalid.
|
602
|
-
Raise error if target migration doesn't exist.
|
560
|
+
* Make `t.timestamps` with precision by default.
|
603
561
|
|
604
|
-
*
|
605
|
-
|
606
|
-
* Fixed a bug where column orders for an index weren't written to
|
607
|
-
`db/schema.rb` when using the sqlite adapter.
|
562
|
+
*Ryuta Kamizono*
|
608
563
|
|
609
|
-
Fixes #30902.
|
610
564
|
|
611
|
-
|
565
|
+
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
612
566
|
|
613
|
-
* Remove deprecated
|
567
|
+
* Remove deprecated `#set_state` from the transaction object.
|
614
568
|
|
615
569
|
*Rafael Mendonça França*
|
616
570
|
|
617
|
-
* Remove deprecated
|
571
|
+
* Remove deprecated `#supports_statement_cache?` from the database adapters.
|
618
572
|
|
619
573
|
*Rafael Mendonça França*
|
620
574
|
|
621
|
-
* Remove deprecated
|
575
|
+
* Remove deprecated `#insert_fixtures` from the database adapters.
|
622
576
|
|
623
577
|
*Rafael Mendonça França*
|
624
578
|
|
625
|
-
* Remove deprecated
|
579
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
|
626
580
|
|
627
581
|
*Rafael Mendonça França*
|
628
582
|
|
629
|
-
*
|
583
|
+
* Do not allow passing the column name to `sum` when a block is passed.
|
630
584
|
|
631
585
|
*Rafael Mendonça França*
|
632
586
|
|
633
|
-
*
|
587
|
+
* Do not allow passing the column name to `count` when a block is passed.
|
634
588
|
|
635
589
|
*Rafael Mendonça França*
|
636
590
|
|
637
|
-
* Remove
|
591
|
+
* Remove delegation of missing methods in a relation to arel.
|
638
592
|
|
639
593
|
*Rafael Mendonça França*
|
640
594
|
|
641
|
-
* Remove
|
595
|
+
* Remove delegation of missing methods in a relation to private methods of the class.
|
642
596
|
|
643
597
|
*Rafael Mendonça França*
|
644
598
|
|
645
|
-
*
|
599
|
+
* Deprecate `config.active_record.sqlite3.represent_boolean_as_integer`.
|
646
600
|
|
647
601
|
*Rafael Mendonça França*
|
648
602
|
|
649
|
-
*
|
603
|
+
* Change `SQLite3Adapter` to always represent boolean values as integers.
|
650
604
|
|
651
605
|
*Rafael Mendonça França*
|
652
606
|
|
653
|
-
* Remove
|
607
|
+
* Remove ability to specify a timestamp name for `#cache_key`.
|
654
608
|
|
655
609
|
*Rafael Mendonça França*
|
656
610
|
|
657
|
-
* Remove deprecated
|
611
|
+
* Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
|
658
612
|
|
659
613
|
*Rafael Mendonça França*
|
660
614
|
|
661
|
-
* Remove deprecated
|
615
|
+
* Remove deprecated `expand_hash_conditions_for_aggregates`.
|
662
616
|
|
663
617
|
*Rafael Mendonça França*
|
664
618
|
|
665
|
-
*
|
666
|
-
ar_internal_metadata's data for a test database.
|
619
|
+
* Set polymorphic type column to NULL on `dependent: :nullify` strategy.
|
667
620
|
|
668
|
-
|
669
|
-
```
|
670
|
-
$ RAILS_ENV=test rails dbconsole
|
671
|
-
> SELECT * FROM ar_internal_metadata;
|
672
|
-
key|value|created_at|updated_at
|
673
|
-
environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
|
674
|
-
```
|
621
|
+
On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
|
675
622
|
|
676
|
-
|
677
|
-
```
|
678
|
-
$ RAILS_ENV=test rails dbconsole
|
679
|
-
> SELECT * FROM ar_internal_metadata;
|
680
|
-
key|value|created_at|updated_at
|
681
|
-
environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
|
682
|
-
```
|
623
|
+
*Laerti Papa*
|
683
624
|
|
684
|
-
|
625
|
+
* Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
|
685
626
|
|
686
|
-
*
|
627
|
+
*Gannon McGibbon*
|
628
|
+
|
629
|
+
* Add support for endless ranges introduces in Ruby 2.6.
|
687
630
|
|
688
|
-
*
|
631
|
+
*Greg Navis*
|
689
632
|
|
690
|
-
|
633
|
+
* Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
|
691
634
|
|
692
635
|
*Ryuta Kamizono*
|
693
636
|
|
694
|
-
* MySQL:
|
637
|
+
* MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
|
695
638
|
|
696
|
-
|
639
|
+
Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
|
640
|
+
format for InnoDB tables. The default setting is `DYNAMIC`.
|
641
|
+
The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
|
697
642
|
|
698
643
|
*Ryuta Kamizono*
|
699
644
|
|
700
|
-
* Fix
|
645
|
+
* Fix join table column quoting with SQLite.
|
646
|
+
|
647
|
+
*Gannon McGibbon*
|
701
648
|
|
702
|
-
|
649
|
+
* Allow disabling scopes generated by `ActiveRecord.enum`.
|
650
|
+
|
651
|
+
*Alfred Dominic*
|
652
|
+
|
653
|
+
* Ensure that `delete_all` on collection proxy returns affected count.
|
703
654
|
|
704
655
|
*Ryuta Kamizono*
|
705
656
|
|
706
|
-
*
|
657
|
+
* Reset scope after delete on collection association to clear stale offsets of removed records.
|
707
658
|
|
708
|
-
|
709
|
-
this datatype in Active Record. However, the serialization of
|
710
|
-
`PostgreSQL::OID::Range` was incomplete, because it did not properly
|
711
|
-
cast the bounds that make up the range. This led to subseconds being
|
712
|
-
dropped in SQL commands:
|
659
|
+
*Gannon McGibbon*
|
713
660
|
|
714
|
-
|
661
|
+
* Add the ability to prevent writes to a database for the duration of a block.
|
715
662
|
|
716
|
-
|
717
|
-
|
663
|
+
Allows the application to prevent writes to a database. This can be useful when
|
664
|
+
you're building out multiple databases and want to make sure you're not sending
|
665
|
+
writes when you want a read.
|
718
666
|
|
719
|
-
|
667
|
+
If `while_preventing_writes` is called and the query is considered a write
|
668
|
+
query the database will raise an exception regardless of whether the database
|
669
|
+
user is able to write.
|
720
670
|
|
721
|
-
|
722
|
-
|
671
|
+
This is not meant to be a catch-all for write queries but rather a way to enforce
|
672
|
+
read-only queries without opening a second connection. One purpose of this is to
|
673
|
+
catch accidental writes, not all writes.
|
723
674
|
|
724
|
-
*
|
675
|
+
*Eileen M. Uchitelle*
|
725
676
|
|
726
|
-
*
|
727
|
-
array.
|
677
|
+
* Allow aliased attributes to be used in `#update_columns` and `#update`.
|
728
678
|
|
729
|
-
*
|
679
|
+
*Gannon McGibbon*
|
730
680
|
|
731
|
-
*
|
681
|
+
* Allow spaces in postgres table names.
|
732
682
|
|
733
|
-
Fixes
|
683
|
+
Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
|
734
684
|
|
735
|
-
*
|
685
|
+
*Gannon McGibbon*
|
686
|
+
|
687
|
+
* Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
|
688
|
+
|
689
|
+
PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
|
690
|
+
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
691
|
+
|
692
|
+
```ruby
|
693
|
+
class DeveloperName < ActiveRecord::Type::String
|
694
|
+
def deserialize(value)
|
695
|
+
"Developer: #{value}"
|
696
|
+
end
|
697
|
+
end
|
698
|
+
|
699
|
+
class AttributedDeveloper < ActiveRecord::Base
|
700
|
+
self.table_name = "developers"
|
736
701
|
|
737
|
-
|
738
|
-
more descriptive.
|
702
|
+
attribute :name, DeveloperName.new
|
739
703
|
|
740
|
-
|
704
|
+
self.ignored_columns += ["name"]
|
705
|
+
end
|
741
706
|
|
742
|
-
|
707
|
+
developer = AttributedDeveloper.create
|
708
|
+
developer.update_column :name, "name"
|
743
709
|
|
744
|
-
|
745
|
-
|
710
|
+
loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
|
711
|
+
puts loaded_developer.name # should be "Developer: name" but it's just "name"
|
712
|
+
```
|
746
713
|
|
747
|
-
*
|
714
|
+
*Dmitry Tsepelev*
|
748
715
|
|
749
|
-
*
|
716
|
+
* Make the implicit order column configurable.
|
750
717
|
|
751
|
-
|
718
|
+
When calling ordered finder methods such as `first` or `last` without an
|
719
|
+
explicit order clause, ActiveRecord sorts records by primary key. This can
|
720
|
+
result in unpredictable and surprising behaviour when the primary key is
|
721
|
+
not an auto-incrementing integer, for example when it's a UUID. This change
|
722
|
+
makes it possible to override the column used for implicit ordering such
|
723
|
+
that `first` and `last` will return more predictable results.
|
724
|
+
|
725
|
+
Example:
|
752
726
|
|
753
|
-
|
727
|
+
class Project < ActiveRecord::Base
|
728
|
+
self.implicit_order_column = "created_at"
|
729
|
+
end
|
754
730
|
|
755
|
-
*
|
731
|
+
*Tekin Suleyman*
|
756
732
|
|
757
|
-
*
|
733
|
+
* Bump minimum PostgreSQL version to 9.3.
|
758
734
|
|
759
|
-
|
735
|
+
*Yasuo Honda*
|
760
736
|
|
761
|
-
|
737
|
+
* Values of enum are frozen, raising an error when attempting to modify them.
|
762
738
|
|
763
|
-
*
|
739
|
+
*Emmanuel Byrd*
|
764
740
|
|
765
|
-
|
741
|
+
* Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
|
766
742
|
|
767
|
-
|
743
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
|
768
744
|
|
769
|
-
|
745
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
|
746
|
+
|
747
|
+
Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
|
748
|
+
|
749
|
+
Example:
|
770
750
|
|
771
|
-
|
772
|
-
|
751
|
+
```
|
752
|
+
class MySubclassedError < ActiveRecord::StatementInvalid
|
753
|
+
def initialize(message, sql:, binds:)
|
754
|
+
super(message, sql: sql, binds: binds)
|
755
|
+
end
|
756
|
+
end
|
757
|
+
```
|
758
|
+
|
759
|
+
*Gannon McGibbon*
|
773
760
|
|
774
|
-
|
761
|
+
* Add an `:if_not_exists` option to `create_table`.
|
762
|
+
|
763
|
+
Example:
|
764
|
+
|
765
|
+
create_table :posts, if_not_exists: true do |t|
|
766
|
+
t.string :title
|
767
|
+
end
|
768
|
+
|
769
|
+
That would execute:
|
770
|
+
|
771
|
+
CREATE TABLE IF NOT EXISTS posts (
|
772
|
+
...
|
773
|
+
)
|
774
|
+
|
775
|
+
If the table already exists, `if_not_exists: false` (the default) raises an
|
776
|
+
exception whereas `if_not_exists: true` does nothing.
|
777
|
+
|
778
|
+
*fatkodima*, *Stefan Kanev*
|
779
|
+
|
780
|
+
* Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
|
781
|
+
|
782
|
+
*Christophe Maximin*
|
783
|
+
|
784
|
+
* Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
|
785
|
+
|
786
|
+
*Gannon McGibbon*
|
787
|
+
|
788
|
+
* `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
|
789
|
+
if the attribute does not exist.
|
775
790
|
|
776
791
|
*Sean Griffin*
|
777
792
|
|
778
|
-
*
|
779
|
-
|
793
|
+
* Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
|
794
|
+
|
795
|
+
````
|
796
|
+
User.connected_to(database: { writing: "postgres://foo" }) do
|
797
|
+
User.create!(name: "Gannon")
|
798
|
+
end
|
799
|
+
|
800
|
+
config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
|
801
|
+
User.connected_to(database: { reading: config }) do
|
802
|
+
User.count
|
803
|
+
end
|
804
|
+
````
|
805
|
+
|
806
|
+
*Gannon McGibbon*
|
807
|
+
|
808
|
+
* Support default expression for MySQL.
|
809
|
+
|
810
|
+
MySQL 8.0.13 and higher supports default value to be a function or expression.
|
811
|
+
|
812
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-table.html
|
780
813
|
|
781
|
-
*
|
814
|
+
*Ryuta Kamizono*
|
815
|
+
|
816
|
+
* Support expression indexes for MySQL.
|
782
817
|
|
783
|
-
|
818
|
+
MySQL 8.0.13 and higher supports functional key parts that index
|
819
|
+
expression values rather than column or column prefix values.
|
820
|
+
|
821
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-index.html
|
784
822
|
|
785
823
|
*Ryuta Kamizono*
|
786
824
|
|
787
|
-
*
|
788
|
-
`destroyed_by_association` will now be set to the reflection, matching the
|
789
|
-
behaviour of `has_many` associations.
|
825
|
+
* Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
|
790
826
|
|
791
|
-
|
827
|
+
Fixes #33056.
|
828
|
+
|
829
|
+
*Federico Martinez*
|
792
830
|
|
793
|
-
*
|
831
|
+
* Add basic API for connection switching to support multiple databases.
|
794
832
|
|
795
|
-
|
796
|
-
bind values used by the `or` instead. (possibly other cases too)
|
833
|
+
1) Adds a `connects_to` method for models to connect to multiple databases. Example:
|
797
834
|
|
798
835
|
```
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
836
|
+
class AnimalsModel < ApplicationRecord
|
837
|
+
self.abstract_class = true
|
838
|
+
|
839
|
+
connects_to database: { writing: :animals_primary, reading: :animals_replica }
|
840
|
+
end
|
841
|
+
|
842
|
+
class Dog < AnimalsModel
|
843
|
+
# connected to both the animals_primary db for writing and the animals_replica for reading
|
844
|
+
end
|
804
845
|
```
|
805
846
|
|
806
|
-
|
847
|
+
2) Adds a `connected_to` block method for switching connection roles or connecting to
|
848
|
+
a database that the model didn't connect to. Connecting to the database in this block is
|
849
|
+
useful when you have another defined connection, for example `slow_replica` that you don't
|
850
|
+
want to connect to by default but need in the console, or a specific code block.
|
807
851
|
|
808
|
-
|
809
|
-
|
852
|
+
```
|
853
|
+
ActiveRecord::Base.connected_to(role: :reading) do
|
854
|
+
Dog.first # finds dog from replica connected to AnimalsBase
|
855
|
+
Book.first # doesn't have a reading connection, will raise an error
|
856
|
+
end
|
857
|
+
```
|
810
858
|
|
811
|
-
|
859
|
+
```
|
860
|
+
ActiveRecord::Base.connected_to(database: :slow_replica) do
|
861
|
+
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
|
862
|
+
end
|
863
|
+
```
|
812
864
|
|
813
|
-
*
|
814
|
-
`current_scope`, with the exception of `unscoped`.
|
865
|
+
*Eileen M. Uchitelle*
|
815
866
|
|
816
|
-
|
867
|
+
* Enum raises on invalid definition values
|
817
868
|
|
818
|
-
|
869
|
+
When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
|
870
|
+
commit checks that only valid definition values are provided, those can
|
871
|
+
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
872
|
+
raises an `ArgumentError`.
|
819
873
|
|
820
|
-
|
874
|
+
Fixes #33961
|
821
875
|
|
822
|
-
|
823
|
-
recognize 't' and 'f' as was previously serialized.
|
876
|
+
*Alberto Almagro*
|
824
877
|
|
825
|
-
|
826
|
-
for SQLite databases, so it's implemented behind a configuration flag
|
827
|
-
whose default false value is deprecated.
|
878
|
+
* Reloading associations now clears the Query Cache like `Persistence#reload` does.
|
828
879
|
|
829
|
-
|
880
|
+
```
|
881
|
+
class Post < ActiveRecord::Base
|
882
|
+
has_one :category
|
883
|
+
belongs_to :author
|
884
|
+
has_many :comments
|
885
|
+
end
|
830
886
|
|
831
|
-
|
832
|
-
|
887
|
+
# Each of the following will now clear the query cache.
|
888
|
+
post.reload_category
|
889
|
+
post.reload_author
|
890
|
+
post.comments.reload
|
891
|
+
```
|
833
892
|
|
834
|
-
|
835
|
-
until the end of the request or job.
|
893
|
+
*Christophe Maximin*
|
836
894
|
|
837
|
-
|
895
|
+
* Added `index` option for `change_table` migration helpers.
|
896
|
+
With this change you can create indexes while adding new
|
897
|
+
columns into the existing tables.
|
838
898
|
|
839
|
-
|
840
|
-
`ActiveRecord::StatementInvalid` exceptions.
|
899
|
+
Example:
|
841
900
|
|
842
|
-
|
901
|
+
change_table(:languages) do |t|
|
902
|
+
t.string :country_code, index: true
|
903
|
+
end
|
843
904
|
|
844
|
-
*
|
905
|
+
*Mehmet Emin İNAÇ*
|
906
|
+
|
907
|
+
* Fix `transaction` reverting for migrations.
|
908
|
+
|
909
|
+
Before: Commands inside a `transaction` in a reverted migration ran uninverted.
|
910
|
+
Now: This change fixes that by reverting commands inside `transaction` block.
|
911
|
+
|
912
|
+
*fatkodima*, *David Verhasselt*
|
845
913
|
|
846
|
-
|
914
|
+
* Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
|
915
|
+
|
916
|
+
*Gannon McGibbon*, *Max Albrecht*
|
917
|
+
|
918
|
+
* Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
|
919
|
+
|
920
|
+
*Gannon McGibbon*
|
921
|
+
|
922
|
+
* Don't update counter cache unless the record is actually saved.
|
923
|
+
|
924
|
+
Fixes #31493, #33113, #33117.
|
847
925
|
|
848
926
|
*Ryuta Kamizono*
|
849
927
|
|
850
|
-
*
|
928
|
+
* Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
|
851
929
|
|
852
|
-
|
853
|
-
inner transaction would still be marked as persisted.
|
930
|
+
*Gannon McGibbon*, *Kevin Cheng*
|
854
931
|
|
855
|
-
|
856
|
-
parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted.
|
932
|
+
* SQLite3 adapter supports expression indexes.
|
857
933
|
|
858
|
-
|
934
|
+
```
|
935
|
+
create_table :users do |t|
|
936
|
+
t.string :email
|
937
|
+
end
|
859
938
|
|
860
|
-
|
939
|
+
add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
|
940
|
+
```
|
861
941
|
|
862
|
-
|
863
|
-
state of the transaction you can now use `rollback!`, `commit!` or `nullify!` instead of
|
864
|
-
`set_state(:rolledback)`, `set_state(:committed)`, or `set_state(nil)`.
|
942
|
+
*Gray Kemmey*
|
865
943
|
|
866
|
-
|
944
|
+
* Allow subclasses to redefine autosave callbacks for associated records.
|
945
|
+
|
946
|
+
Fixes #33305.
|
947
|
+
|
948
|
+
*Andrey Subbota*
|
949
|
+
|
950
|
+
* Bump minimum MySQL version to 5.5.8.
|
951
|
+
|
952
|
+
*Yasuo Honda*
|
953
|
+
|
954
|
+
* Use MySQL utf8mb4 character set by default.
|
955
|
+
|
956
|
+
`utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
|
957
|
+
The previous default 3-Byte encoding character set `utf8` is not enough to support them.
|
958
|
+
|
959
|
+
*Yasuo Honda*
|
960
|
+
|
961
|
+
* Fix duplicated record creation when using nested attributes with `create_with`.
|
962
|
+
|
963
|
+
*Darwin Wu*
|
964
|
+
|
965
|
+
* Configuration item `config.filter_parameters` could also filter out
|
966
|
+
sensitive values of database columns when calling `#inspect`.
|
967
|
+
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
968
|
+
specify sensitive attributes to specific model.
|
867
969
|
|
868
|
-
|
970
|
+
```
|
971
|
+
Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
|
972
|
+
Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
|
973
|
+
SecureAccount.filter_attributes += [:name]
|
974
|
+
SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
|
975
|
+
```
|
976
|
+
|
977
|
+
*Zhang Kang*, *Yoshiyuki Kinjo*
|
978
|
+
|
979
|
+
* Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
|
980
|
+
`indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
|
981
|
+
and `joins_per_query` methods in `DatabaseLimits`.
|
869
982
|
|
870
983
|
*Ryuta Kamizono*
|
871
984
|
|
872
|
-
*
|
873
|
-
without being connected.
|
985
|
+
* `ActiveRecord::Base.configurations` now returns an object.
|
874
986
|
|
875
|
-
|
987
|
+
`ActiveRecord::Base.configurations` used to return a hash, but this
|
988
|
+
is an inflexible data model. In order to improve multiple-database
|
989
|
+
handling in Rails, we've changed this to return an object. Some methods
|
990
|
+
are provided to make the object behave hash-like in order to ease the
|
991
|
+
transition process. Since most applications don't manipulate the hash
|
992
|
+
we've decided to add backwards-compatible functionality that will throw
|
993
|
+
a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
|
994
|
+
will use the new version internally and externally.
|
876
995
|
|
877
|
-
|
878
|
-
if the child records were deleted before the parent was saved, they would
|
879
|
-
still be persisted. Now, if child records are deleted before the parent is saved
|
880
|
-
on a `has_many :through` association, the child records will not be persisted.
|
996
|
+
For example, the following `database.yml`:
|
881
997
|
|
882
|
-
|
998
|
+
```
|
999
|
+
development:
|
1000
|
+
adapter: sqlite3
|
1001
|
+
database: db/development.sqlite3
|
1002
|
+
```
|
883
1003
|
|
884
|
-
|
885
|
-
the merged relation into LEFT OUTER JOIN.
|
1004
|
+
Used to become a hash:
|
886
1005
|
|
887
|
-
|
1006
|
+
```
|
1007
|
+
{ "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
|
1008
|
+
```
|
1009
|
+
|
1010
|
+
Is now converted into the following object:
|
1011
|
+
|
1012
|
+
```
|
1013
|
+
#<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
|
1014
|
+
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
1015
|
+
@spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
|
1016
|
+
]
|
1017
|
+
```
|
888
1018
|
|
1019
|
+
Iterating over the database configurations has also changed. Instead of
|
1020
|
+
calling hash methods on the `configurations` hash directly, a new method `configs_for` has
|
1021
|
+
been provided that allows you to select the correct configuration. `env_name` and
|
1022
|
+
`spec_name` arguments are optional. For example, these return an array of
|
1023
|
+
database config objects for the requested environment and a single database config object
|
1024
|
+
will be returned for the requested environment and specification name respectively.
|
1025
|
+
|
1026
|
+
```
|
1027
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development")
|
1028
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
|
889
1029
|
```
|
890
|
-
Author.joins(:posts).merge(Post.joins(:comments))
|
891
|
-
# Before the change:
|
892
|
-
#=> SELECT ... FROM authors INNER JOIN posts ON ... LEFT OUTER JOIN comments ON...
|
893
1030
|
|
894
|
-
|
895
|
-
|
1031
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*
|
1032
|
+
|
1033
|
+
* Add database configuration to disable advisory locks.
|
1034
|
+
|
1035
|
+
```
|
1036
|
+
production:
|
1037
|
+
adapter: postgresql
|
1038
|
+
advisory_locks: false
|
896
1039
|
```
|
897
1040
|
|
898
|
-
*
|
1041
|
+
*Guo Xiang*
|
899
1042
|
|
900
|
-
* `
|
901
|
-
`locking_column`, without default value, is null in the database.
|
1043
|
+
* SQLite3 adapter `alter_table` method restores foreign keys.
|
902
1044
|
|
903
|
-
*
|
1045
|
+
*Yasuo Honda*
|
904
1046
|
|
905
|
-
*
|
906
|
-
`locking_column` is null in the database.
|
1047
|
+
* Allow `:to_table` option to `invert_remove_foreign_key`.
|
907
1048
|
|
908
|
-
|
1049
|
+
Example:
|
909
1050
|
|
910
|
-
|
1051
|
+
remove_foreign_key :accounts, to_table: :owners
|
911
1052
|
|
912
|
-
*
|
1053
|
+
*Nikolay Epifanov*, *Rich Chen*
|
913
1054
|
|
914
|
-
*
|
1055
|
+
* Add environment & load_config dependency to `bin/rake db:seed` to enable
|
1056
|
+
seed load in environments without Rails and custom DB configuration
|
915
1057
|
|
916
|
-
*
|
1058
|
+
*Tobias Bielohlawek*
|
917
1059
|
|
918
|
-
*
|
1060
|
+
* Fix default value for mysql time types with specified precision.
|
1061
|
+
|
1062
|
+
*Nikolay Kondratyev*
|
1063
|
+
|
1064
|
+
* Fix `touch` option to behave consistently with `Persistence#touch` method.
|
919
1065
|
|
920
1066
|
*Ryuta Kamizono*
|
921
1067
|
|
922
|
-
*
|
1068
|
+
* Migrations raise when duplicate column definition.
|
923
1069
|
|
924
|
-
Fixes #
|
1070
|
+
Fixes #33024.
|
925
1071
|
|
926
|
-
*
|
1072
|
+
*Federico Martinez*
|
927
1073
|
|
928
|
-
*
|
929
|
-
in `ActiveSupport::Cache`. This also means that `ActiveRecord::Base#cache_key` will now return a stable key
|
930
|
-
that does not include a timestamp any more.
|
1074
|
+
* Bump minimum SQLite version to 3.8
|
931
1075
|
|
932
|
-
|
933
|
-
until you set `ActiveRecord::Base.cache_versioning = true`. That's the setting for all new apps on Rails 5.2+
|
1076
|
+
*Yasuo Honda*
|
934
1077
|
|
935
|
-
|
1078
|
+
* Fix parent record should not get saved with duplicate children records.
|
936
1079
|
|
937
|
-
|
1080
|
+
Fixes #32940.
|
938
1081
|
|
939
|
-
*
|
1082
|
+
*Santosh Wadghule*
|
940
1083
|
|
941
|
-
*
|
1084
|
+
* Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
|
942
1085
|
|
943
|
-
|
1086
|
+
*Brian Durand*
|
944
1087
|
|
945
|
-
|
1088
|
+
* Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
|
1089
|
+
use loaded association ids if present.
|
946
1090
|
|
947
|
-
*
|
1091
|
+
*Graham Turner*
|
948
1092
|
|
949
|
-
|
1093
|
+
* Add support to preload associations of polymorphic associations when not all the records have the requested associations.
|
950
1094
|
|
951
|
-
*
|
952
|
-
when the current migration does not exist.
|
1095
|
+
*Dana Sherson*
|
953
1096
|
|
954
|
-
|
1097
|
+
* Add `touch_all` method to `ActiveRecord::Relation`.
|
955
1098
|
|
956
|
-
|
1099
|
+
Example:
|
957
1100
|
|
958
|
-
|
1101
|
+
Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
|
959
1102
|
|
960
|
-
*
|
1103
|
+
*fatkodima*, *duggiefresh*
|
961
1104
|
|
962
|
-
|
963
|
-
See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
|
1105
|
+
* Add `ActiveRecord::Base.base_class?` predicate.
|
964
1106
|
|
965
|
-
*
|
1107
|
+
*Bogdan Gusiev*
|
966
1108
|
|
967
|
-
*
|
1109
|
+
* Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
|
968
1110
|
|
969
|
-
*
|
1111
|
+
*Tan Huynh*, *Yukio Mizuta*
|
1112
|
+
|
1113
|
+
* Rails 6 requires Ruby 2.5.0 or newer.
|
1114
|
+
|
1115
|
+
*Jeremy Daer*, *Kasper Timm Hansen*
|
970
1116
|
|
971
|
-
*
|
972
|
-
Previously this method always returned an empty array.
|
1117
|
+
* Deprecate `update_attributes`/`!` in favor of `update`/`!`.
|
973
1118
|
|
974
|
-
*
|
1119
|
+
*Eddie Lebow*
|
1120
|
+
|
1121
|
+
* Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
|
1122
|
+
`ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
|
1123
|
+
|
1124
|
+
*DHH*
|
1125
|
+
|
1126
|
+
* Add `Relation#pick` as short-hand for single-value plucks.
|
1127
|
+
|
1128
|
+
*DHH*
|
975
1129
|
|
976
1130
|
|
977
|
-
Please check [5-
|
1131
|
+
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.
|