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