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