activerecord 5.2.7 → 6.0.6.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 +987 -584
- data/MIT-LICENSE +3 -1
- data/README.rdoc +5 -3
- data/examples/performance.rb +1 -1
- data/lib/active_record/advisory_lock_base.rb +18 -0
- data/lib/active_record/aggregations.rb +4 -3
- data/lib/active_record/association_relation.rb +10 -8
- data/lib/active_record/associations/alias_tracker.rb +0 -1
- data/lib/active_record/associations/association.rb +55 -19
- data/lib/active_record/associations/association_scope.rb +11 -7
- data/lib/active_record/associations/belongs_to_association.rb +36 -42
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +0 -4
- data/lib/active_record/associations/builder/association.rb +14 -18
- data/lib/active_record/associations/builder/belongs_to.rb +19 -52
- data/lib/active_record/associations/builder/collection_association.rb +3 -13
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -40
- 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 +19 -23
- data/lib/active_record/associations/collection_proxy.rb +14 -17
- data/lib/active_record/associations/foreign_association.rb +7 -0
- data/lib/active_record/associations/has_many_association.rb +2 -11
- data/lib/active_record/associations/has_many_through_association.rb +14 -14
- data/lib/active_record/associations/has_one_association.rb +28 -30
- data/lib/active_record/associations/has_one_through_association.rb +5 -5
- data/lib/active_record/associations/join_dependency/join_association.rb +16 -10
- data/lib/active_record/associations/join_dependency/join_part.rb +4 -4
- data/lib/active_record/associations/join_dependency.rb +47 -30
- data/lib/active_record/associations/preloader/association.rb +61 -41
- data/lib/active_record/associations/preloader/through_association.rb +48 -39
- data/lib/active_record/associations/preloader.rb +44 -33
- data/lib/active_record/associations/singular_association.rb +2 -16
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/associations.rb +21 -16
- data/lib/active_record/attribute_assignment.rb +7 -11
- data/lib/active_record/attribute_decorators.rb +0 -2
- data/lib/active_record/attribute_methods/before_type_cast.rb +4 -2
- data/lib/active_record/attribute_methods/dirty.rb +111 -40
- data/lib/active_record/attribute_methods/primary_key.rb +15 -24
- data/lib/active_record/attribute_methods/query.rb +2 -3
- data/lib/active_record/attribute_methods/read.rb +15 -54
- data/lib/active_record/attribute_methods/serialization.rb +1 -2
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -3
- data/lib/active_record/attribute_methods/write.rb +17 -25
- data/lib/active_record/attribute_methods.rb +28 -100
- data/lib/active_record/attributes.rb +13 -1
- data/lib/active_record/autosave_association.rb +12 -14
- data/lib/active_record/base.rb +2 -3
- data/lib/active_record/callbacks.rb +6 -21
- data/lib/active_record/coders/yaml_column.rb +23 -2
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +109 -18
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +17 -4
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +102 -124
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +18 -9
- data/lib/active_record/connection_adapters/abstract/quoting.rb +77 -17
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +20 -14
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +105 -72
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -3
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +175 -79
- data/lib/active_record/connection_adapters/abstract/transaction.rb +96 -57
- data/lib/active_record/connection_adapters/abstract_adapter.rb +197 -43
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +149 -217
- data/lib/active_record/connection_adapters/column.rb +17 -13
- data/lib/active_record/connection_adapters/connection_specification.rb +54 -45
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +6 -10
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +70 -14
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +0 -1
- data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +4 -6
- 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 +139 -19
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +26 -10
- data/lib/active_record/connection_adapters/postgresql/column.rb +17 -31
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +26 -1
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +8 -0
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +25 -7
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.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 +5 -3
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +14 -3
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -91
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +63 -75
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +24 -27
- data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +168 -75
- 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 +119 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +42 -7
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +43 -12
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +137 -147
- data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
- data/lib/active_record/connection_handling.rb +139 -26
- data/lib/active_record/core.rb +117 -66
- data/lib/active_record/counter_cache.rb +8 -30
- 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 +78 -0
- data/lib/active_record/database_configurations.rb +233 -0
- data/lib/active_record/dynamic_matchers.rb +3 -4
- data/lib/active_record/enum.rb +44 -7
- data/lib/active_record/errors.rb +15 -7
- data/lib/active_record/explain.rb +1 -2
- 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 +152 -0
- data/lib/active_record/fixture_set/table_rows.rb +46 -0
- data/lib/active_record/fixtures.rb +144 -474
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +13 -6
- data/lib/active_record/insert_all.rb +179 -0
- data/lib/active_record/integration.rb +68 -16
- data/lib/active_record/internal_metadata.rb +11 -3
- data/lib/active_record/locking/optimistic.rb +14 -7
- data/lib/active_record/locking/pessimistic.rb +3 -3
- data/lib/active_record/log_subscriber.rb +8 -27
- data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +87 -0
- data/lib/active_record/middleware/database_selector.rb +74 -0
- data/lib/active_record/migration/command_recorder.rb +54 -22
- data/lib/active_record/migration/compatibility.rb +79 -52
- data/lib/active_record/migration/join_table.rb +0 -1
- data/lib/active_record/migration.rb +104 -85
- data/lib/active_record/model_schema.rb +62 -11
- data/lib/active_record/nested_attributes.rb +2 -4
- data/lib/active_record/no_touching.rb +9 -2
- data/lib/active_record/null_relation.rb +0 -1
- data/lib/active_record/persistence.rb +232 -29
- data/lib/active_record/query_cache.rb +11 -4
- data/lib/active_record/querying.rb +33 -21
- 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 +51 -51
- data/lib/active_record/relation/batches.rb +13 -11
- data/lib/active_record/relation/calculations.rb +55 -49
- data/lib/active_record/relation/delegation.rb +35 -50
- data/lib/active_record/relation/finder_methods.rb +23 -28
- data/lib/active_record/relation/from_clause.rb +4 -0
- data/lib/active_record/relation/merger.rb +12 -17
- 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/predicate_builder.rb +5 -11
- data/lib/active_record/relation/query_attribute.rb +13 -8
- data/lib/active_record/relation/query_methods.rb +234 -69
- data/lib/active_record/relation/spawn_methods.rb +1 -2
- data/lib/active_record/relation/where_clause.rb +14 -11
- data/lib/active_record/relation/where_clause_factory.rb +1 -2
- data/lib/active_record/relation.rb +326 -81
- data/lib/active_record/result.rb +30 -12
- 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 +6 -2
- data/lib/active_record/scoping/default.rb +4 -6
- data/lib/active_record/scoping/named.rb +25 -16
- data/lib/active_record/scoping.rb +8 -9
- data/lib/active_record/statement_cache.rb +30 -3
- data/lib/active_record/store.rb +87 -8
- data/lib/active_record/suppressor.rb +2 -2
- data/lib/active_record/table_metadata.rb +23 -15
- data/lib/active_record/tasks/database_tasks.rb +194 -25
- data/lib/active_record/tasks/mysql_database_tasks.rb +5 -6
- data/lib/active_record/tasks/postgresql_database_tasks.rb +5 -8
- data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -9
- data/lib/active_record/test_databases.rb +23 -0
- data/lib/active_record/test_fixtures.rb +243 -0
- data/lib/active_record/timestamp.rb +39 -26
- data/lib/active_record/touch_later.rb +5 -4
- data/lib/active_record/transactions.rb +64 -73
- data/lib/active_record/translation.rb +1 -1
- data/lib/active_record/type/adapter_specific_registry.rb +3 -13
- data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
- data/lib/active_record/type/serialized.rb +0 -1
- data/lib/active_record/type/time.rb +10 -0
- data/lib/active_record/type/type_map.rb +0 -1
- data/lib/active_record/type/unsigned_integer.rb +0 -1
- data/lib/active_record/type.rb +3 -5
- 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/associated.rb +0 -1
- data/lib/active_record/validations/uniqueness.rb +15 -27
- data/lib/active_record/validations.rb +3 -3
- data/lib/active_record.rb +10 -2
- data/lib/arel/alias_predication.rb +9 -0
- data/lib/arel/attributes/attribute.rb +37 -0
- data/lib/arel/attributes.rb +22 -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/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/nodes.rb +68 -0
- data/lib/arel/order_predications.rb +13 -0
- data/lib/arel/predications.rb +256 -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/depth_first.rb +203 -0
- data/lib/arel/visitors/dot.rb +296 -0
- data/lib/arel/visitors/ibm_db.rb +34 -0
- data/lib/arel/visitors/informix.rb +62 -0
- data/lib/arel/visitors/mssql.rb +156 -0
- data/lib/arel/visitors/mysql.rb +83 -0
- data/lib/arel/visitors/oracle.rb +158 -0
- data/lib/arel/visitors/oracle12.rb +65 -0
- data/lib/arel/visitors/postgresql.rb +109 -0
- data/lib/arel/visitors/sqlite.rb +38 -0
- data/lib/arel/visitors/to_sql.rb +888 -0
- data/lib/arel/visitors/visitor.rb +45 -0
- data/lib/arel/visitors/where_sql.rb +22 -0
- data/lib/arel/visitors.rb +20 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/arel.rb +62 -0
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -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/migration.rb +14 -2
- data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
- metadata +116 -29
- data/lib/active_record/collection_cache_key.rb +0 -53
data/CHANGELOG.md
CHANGED
@@ -1,1046 +1,1449 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 6.0.6.1 (January 17, 2023) ##
|
2
2
|
|
3
|
-
*
|
3
|
+
* Make `sanitize_as_sql_comment` more strict
|
4
4
|
|
5
|
+
Though this method was likely never meant to take user input, it was
|
6
|
+
attempting sanitization. That sanitization could be bypassed with
|
7
|
+
carefully crafted input.
|
5
8
|
|
6
|
-
|
9
|
+
This commit makes the sanitization more robust by replacing any
|
10
|
+
occurrances of "/*" or "*/" with "/ *" or "* /". It also performs a
|
11
|
+
first pass to remove one surrounding comment to avoid compatibility
|
12
|
+
issues for users relying on the existing removal.
|
7
13
|
|
8
|
-
|
14
|
+
This also clarifies in the documentation of annotate that it should not
|
15
|
+
be provided user input.
|
9
16
|
|
17
|
+
[CVE-2023-22794]
|
10
18
|
|
11
|
-
## Rails 5.2.6.2 (February 11, 2022) ##
|
12
19
|
|
13
|
-
|
20
|
+
## Rails 6.0.6 (September 09, 2022) ##
|
14
21
|
|
22
|
+
* Symbol is allowed by default for YAML columns
|
15
23
|
|
16
|
-
|
24
|
+
*Étienne Barrié*
|
17
25
|
|
18
|
-
* No changes.
|
19
26
|
|
27
|
+
## Rails 6.0.5.1 (July 12, 2022) ##
|
20
28
|
|
21
|
-
|
29
|
+
* Change ActiveRecord::Coders::YAMLColumn default to safe_load
|
22
30
|
|
23
|
-
|
31
|
+
This adds two new configuration options The configuration options are as
|
32
|
+
follows:
|
33
|
+
|
34
|
+
* `config.active_storage.use_yaml_unsafe_load`
|
35
|
+
|
36
|
+
When set to true, this configuration option tells Rails to use the old
|
37
|
+
"unsafe" YAML loading strategy, maintaining the existing behavior but leaving
|
38
|
+
the possible escalation vulnerability in place. Setting this option to true
|
39
|
+
is *not* recommended, but can aid in upgrading.
|
40
|
+
|
41
|
+
* `config.active_record.yaml_column_permitted_classes`
|
42
|
+
|
43
|
+
The "safe YAML" loading method does not allow all classes to be deserialized
|
44
|
+
by default. This option allows you to specify classes deemed "safe" in your
|
45
|
+
application. For example, if your application uses Symbol and Time in
|
46
|
+
serialized data, you can add Symbol and Time to the allowed list as follows:
|
47
|
+
|
48
|
+
```
|
49
|
+
config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
|
50
|
+
```
|
51
|
+
|
52
|
+
[CVE-2022-32224]
|
24
53
|
|
25
54
|
|
26
|
-
## Rails
|
55
|
+
## Rails 6.0.5 (May 09, 2022) ##
|
27
56
|
|
28
57
|
* No changes.
|
29
58
|
|
30
59
|
|
31
|
-
## Rails
|
60
|
+
## Rails 6.0.4.8 (April 26, 2022) ##
|
32
61
|
|
33
62
|
* No changes.
|
34
63
|
|
35
64
|
|
36
|
-
## Rails
|
65
|
+
## Rails 6.0.4.7 (March 08, 2022) ##
|
37
66
|
|
38
|
-
*
|
67
|
+
* No changes.
|
39
68
|
|
40
|
-
Carefully crafted input can cause a DoS via the regular expressions used
|
41
|
-
for validating the money format in the PostgreSQL adapter. This patch
|
42
|
-
fixes the regexp.
|
43
69
|
|
44
|
-
|
70
|
+
## Rails 6.0.4.6 (February 11, 2022) ##
|
45
71
|
|
46
|
-
|
72
|
+
* No changes.
|
47
73
|
|
48
|
-
|
74
|
+
|
75
|
+
## Rails 6.0.4.5 (February 11, 2022) ##
|
76
|
+
|
77
|
+
* No changes.
|
49
78
|
|
50
79
|
|
51
|
-
## Rails
|
80
|
+
## Rails 6.0.4.4 (December 15, 2021) ##
|
52
81
|
|
53
82
|
* No changes.
|
54
83
|
|
55
84
|
|
56
|
-
## Rails
|
85
|
+
## Rails 6.0.4.3 (December 14, 2021) ##
|
57
86
|
|
58
87
|
* No changes.
|
59
88
|
|
60
|
-
|
89
|
+
|
90
|
+
## Rails 6.0.4.2 (December 14, 2021) ##
|
61
91
|
|
62
92
|
* No changes.
|
63
93
|
|
64
94
|
|
65
|
-
## Rails
|
95
|
+
## Rails 6.0.4.1 (August 19, 2021) ##
|
66
96
|
|
67
97
|
* No changes.
|
68
98
|
|
69
99
|
|
70
|
-
## Rails
|
100
|
+
## Rails 6.0.4 (June 15, 2021) ##
|
71
101
|
|
72
|
-
*
|
102
|
+
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
73
103
|
|
74
|
-
|
75
|
-
associations, the callback for a `has_many` association was run while
|
76
|
-
another instance of the same callback on the same association hadn't
|
77
|
-
finished running. When control returned to the first instance of the
|
78
|
-
callback, the instance variable had changed, and subsequent associated
|
79
|
-
records weren't saved correctly. Specifically, the ID field for the
|
80
|
-
`belongs_to` corresponding to the `has_many` was `nil`.
|
104
|
+
Fixes #39065.
|
81
105
|
|
82
|
-
|
106
|
+
*Alex Ghiculescu*
|
83
107
|
|
84
|
-
|
108
|
+
* Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
|
85
109
|
|
86
|
-
|
110
|
+
Fixes #34255.
|
87
111
|
|
88
|
-
|
112
|
+
*Steven Weber*
|
113
|
+
|
114
|
+
* Reset statement cache for association if `table_name` is changed.
|
115
|
+
|
116
|
+
Fixes #36453.
|
89
117
|
|
90
118
|
*Ryuta Kamizono*
|
91
119
|
|
92
|
-
*
|
120
|
+
* Type cast extra select for eager loading.
|
93
121
|
|
94
|
-
*
|
122
|
+
*Ryuta Kamizono*
|
95
123
|
|
96
|
-
*
|
124
|
+
* Prevent collection associations from being autosaved multiple times.
|
97
125
|
|
98
|
-
Fixes #
|
126
|
+
Fixes #39173.
|
99
127
|
|
100
|
-
*
|
128
|
+
*Eugene Kenny*
|
101
129
|
|
102
|
-
*
|
103
|
-
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
130
|
+
* Resolve issue with insert_all unique_by option when used with expression index.
|
104
131
|
|
105
|
-
|
132
|
+
When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
|
133
|
+
`ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
|
134
|
+
was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
|
106
135
|
|
107
|
-
|
136
|
+
Usage:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
create_table :books, id: :integer, force: true do |t|
|
140
|
+
t.column :name, :string
|
141
|
+
t.index "lower(name)", unique: true
|
142
|
+
end
|
108
143
|
|
144
|
+
Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
|
145
|
+
```
|
109
146
|
|
110
|
-
|
147
|
+
Fixes #39516.
|
111
148
|
|
112
|
-
*
|
149
|
+
*Austen Madden*
|
113
150
|
|
114
|
-
|
151
|
+
* Fix preloading for polymorphic association with custom scope.
|
115
152
|
|
116
|
-
*
|
153
|
+
*Ryuta Kamizono*
|
117
154
|
|
118
|
-
*
|
155
|
+
* Allow relations with different SQL comments in the `or` method.
|
156
|
+
|
157
|
+
*Takumi Shotoku*
|
158
|
+
|
159
|
+
* Resolve conflict between counter cache and optimistic locking.
|
160
|
+
|
161
|
+
Bump an Active Record instance's lock version after updating its counter
|
162
|
+
cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
|
163
|
+
upon subsequent transactions by maintaining parity with the corresponding
|
164
|
+
database record's `lock_version` column.
|
165
|
+
|
166
|
+
Fixes #16449.
|
167
|
+
|
168
|
+
*Aaron Lipman*
|
169
|
+
|
170
|
+
* Fix through association with source/through scope which has joins.
|
119
171
|
|
120
172
|
*Ryuta Kamizono*
|
121
173
|
|
122
|
-
*
|
174
|
+
* Fix through association to respect source scope for includes/preload.
|
123
175
|
|
124
|
-
|
176
|
+
*Ryuta Kamizono*
|
177
|
+
|
178
|
+
* Fix eager load with Arel joins to maintain the original joins order.
|
125
179
|
|
126
180
|
*Ryuta Kamizono*
|
127
181
|
|
128
|
-
*
|
182
|
+
* Fix group by count with eager loading + order + limit/offset.
|
183
|
+
|
184
|
+
*Ryuta Kamizono*
|
129
185
|
|
130
|
-
|
186
|
+
* Fix left joins order when merging multiple left joins from different associations.
|
131
187
|
|
132
188
|
*Ryuta Kamizono*
|
133
189
|
|
134
|
-
* Fix
|
190
|
+
* Fix index creation to preserve index comment in bulk change table on MySQL.
|
135
191
|
|
136
|
-
*
|
192
|
+
*Ryuta Kamizono*
|
137
193
|
|
138
|
-
*
|
194
|
+
* Change `remove_foreign_key` to not check `:validate` option if database
|
195
|
+
doesn't support the feature.
|
139
196
|
|
140
197
|
*Ryuta Kamizono*
|
141
198
|
|
142
|
-
*
|
199
|
+
* Fix the result of aggregations to maintain duplicated "group by" fields.
|
143
200
|
|
144
|
-
*
|
201
|
+
*Ryuta Kamizono*
|
202
|
+
|
203
|
+
* Do not return duplicated records when using preload.
|
204
|
+
|
205
|
+
*Bogdan Gusiev*
|
145
206
|
|
146
207
|
|
147
|
-
## Rails
|
208
|
+
## Rails 6.0.3.7 (May 05, 2021) ##
|
148
209
|
|
149
210
|
* No changes.
|
150
211
|
|
151
212
|
|
152
|
-
## Rails
|
213
|
+
## Rails 6.0.3.6 (March 26, 2021) ##
|
153
214
|
|
154
|
-
*
|
215
|
+
* No changes.
|
155
216
|
|
156
|
-
*Ryuta Kamizono*
|
157
217
|
|
158
|
-
|
218
|
+
## Rails 6.0.3.5 (February 10, 2021) ##
|
159
219
|
|
160
|
-
|
220
|
+
* Fix possible DoS vector in PostgreSQL money type
|
161
221
|
|
162
|
-
|
222
|
+
Carefully crafted input can cause a DoS via the regular expressions used
|
223
|
+
for validating the money format in the PostgreSQL adapter. This patch
|
224
|
+
fixes the regexp.
|
163
225
|
|
164
|
-
|
165
|
-
adapter.
|
226
|
+
Thanks to @dee-see from Hackerone for this patch!
|
166
227
|
|
167
|
-
|
228
|
+
[CVE-2021-22880]
|
168
229
|
|
169
|
-
*
|
230
|
+
*Aaron Patterson*
|
170
231
|
|
171
|
-
PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
|
172
|
-
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
173
232
|
|
174
|
-
|
175
|
-
class DeveloperName < ActiveRecord::Type::String
|
176
|
-
def deserialize(value)
|
177
|
-
"Developer: #{value}"
|
178
|
-
end
|
179
|
-
end
|
233
|
+
## Rails 6.0.3.4 (October 07, 2020) ##
|
180
234
|
|
181
|
-
|
182
|
-
self.table_name = "developers"
|
235
|
+
* No changes.
|
183
236
|
|
184
|
-
attribute :name, DeveloperName.new
|
185
237
|
|
186
|
-
|
187
|
-
end
|
238
|
+
## Rails 6.0.3.3 (September 09, 2020) ##
|
188
239
|
|
189
|
-
|
190
|
-
developer.update_column :name, "name"
|
240
|
+
* No changes.
|
191
241
|
|
192
|
-
loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
|
193
|
-
puts loaded_developer.name # should be "Developer: name" but it's just "name"
|
194
|
-
```
|
195
242
|
|
196
|
-
|
243
|
+
## Rails 6.0.3.2 (June 17, 2020) ##
|
197
244
|
|
198
|
-
*
|
245
|
+
* No changes.
|
199
246
|
|
200
|
-
*Emmanuel Byrd*
|
201
247
|
|
202
|
-
|
203
|
-
if the attribute does not exist.
|
248
|
+
## Rails 6.0.3.1 (May 18, 2020) ##
|
204
249
|
|
205
|
-
|
250
|
+
* No changes.
|
206
251
|
|
207
|
-
* Do not use prepared statement in queries that have a large number of binds.
|
208
252
|
|
209
|
-
|
253
|
+
## Rails 6.0.3 (May 06, 2020) ##
|
210
254
|
|
211
|
-
*
|
255
|
+
* Recommend applications don't use the `database` kwarg in `connected_to`
|
256
|
+
|
257
|
+
The database kwarg in `connected_to` was meant to be used for one-off scripts but is often used in requests. This is really dangerous because it re-establishes a connection every time. It's deprecated in 6.1 and will be removed in 6.2 without replacement. This change soft deprecates it in 6.0 by removing documentation.
|
212
258
|
|
213
259
|
*Eileen M. Uchitelle*
|
214
260
|
|
215
|
-
* Fix
|
261
|
+
* Fix support for PostgreSQL 11+ partitioned indexes.
|
216
262
|
|
217
|
-
|
263
|
+
*Sebastián Palma*
|
218
264
|
|
219
|
-
|
265
|
+
* Add support for beginless ranges, introduced in Ruby 2.7.
|
220
266
|
|
221
|
-
*
|
267
|
+
*Josh Goodall*
|
222
268
|
|
223
|
-
|
269
|
+
* Fix insert_all with enum values
|
224
270
|
|
225
|
-
|
271
|
+
Fixes #38716.
|
226
272
|
|
227
|
-
*
|
273
|
+
*Joel Blum*
|
228
274
|
|
229
|
-
*
|
275
|
+
* Regexp-escape table name for MS SQL
|
230
276
|
|
231
|
-
|
277
|
+
Add `Regexp.escape` to one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods like `pluck` and `select` fail in certain cases when used with the MS SQL Server adapter.
|
232
278
|
|
233
|
-
*
|
279
|
+
*Larry Reid*
|
234
280
|
|
235
|
-
|
281
|
+
* Store advisory locks on their own named connection.
|
236
282
|
|
237
|
-
|
283
|
+
Previously advisory locks were taken out against a connection when a migration started. This works fine in single database applications but doesn't work well when migrations need to open new connections which results in the lock getting dropped.
|
238
284
|
|
239
|
-
|
285
|
+
In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
|
240
286
|
|
241
|
-
*
|
287
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
242
288
|
|
243
|
-
|
289
|
+
* Ensure `:reading` connections always raise if a write is attempted.
|
244
290
|
|
245
|
-
|
291
|
+
Now Rails will raise an `ActiveRecord::ReadOnlyError` if any connection on the reading handler attempts to make a write. If your reading role needs to write you should name the role something other than `:reading`.
|
246
292
|
|
247
|
-
*
|
293
|
+
*Eileen M. Uchitelle*
|
248
294
|
|
249
|
-
*
|
295
|
+
* Enforce fresh ETag header after a collection's contents change by adding
|
296
|
+
ActiveRecord::Relation#cache_key_with_version. This method will be used by
|
297
|
+
ActionController::ConditionalGet to ensure that when collection cache versioning
|
298
|
+
is enabled, requests using ConditionalGet don't return the same ETag header
|
299
|
+
after a collection is modified. Fixes #38078.
|
250
300
|
|
251
|
-
*
|
301
|
+
*Aaron Lipman*
|
252
302
|
|
303
|
+
* A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgresSQL `options`.
|
253
304
|
|
254
|
-
|
305
|
+
*Joshua Flanagan*
|
255
306
|
|
256
|
-
*
|
307
|
+
* Retain explicit selections on the base model after applying `includes` and `joins`.
|
257
308
|
|
309
|
+
Resolves #34889.
|
258
310
|
|
259
|
-
|
311
|
+
*Patrick Rebsch*
|
260
312
|
|
261
|
-
* PostgreSQL: Support new relkind for partitioned tables.
|
262
313
|
|
263
|
-
|
314
|
+
## Rails 6.0.2.2 (March 19, 2020) ##
|
264
315
|
|
265
|
-
|
316
|
+
* No changes.
|
266
317
|
|
267
|
-
* Rollback parent transaction when children fails to update.
|
268
318
|
|
269
|
-
|
319
|
+
## Rails 6.0.2.1 (December 18, 2019) ##
|
270
320
|
|
271
|
-
*
|
321
|
+
* No changes.
|
272
322
|
|
273
|
-
*Nikolay Kondratyev*
|
274
323
|
|
275
|
-
|
324
|
+
## Rails 6.0.2 (December 13, 2019) ##
|
276
325
|
|
277
|
-
|
326
|
+
* Share the same connection pool for primary and replica databases in the
|
327
|
+
transactional tests for the same database.
|
278
328
|
|
279
|
-
*
|
329
|
+
*Edouard Chin*
|
280
330
|
|
281
|
-
|
331
|
+
* Fix the preloader when one record is fetched using `after_initialize`
|
332
|
+
but not the entire collection.
|
282
333
|
|
283
|
-
*
|
334
|
+
*Bradley Price*
|
284
335
|
|
285
|
-
* Fix
|
336
|
+
* Fix collection callbacks not terminating when `:abort` is thrown.
|
286
337
|
|
287
|
-
*
|
338
|
+
*Edouard Chin*, *Ryuta Kamizono*
|
288
339
|
|
289
|
-
*
|
340
|
+
* Correctly deprecate `where.not` working as NOR for relations.
|
290
341
|
|
291
|
-
|
342
|
+
12a9664 deprecated where.not working as NOR, however
|
343
|
+
doing a relation query like `where.not(relation: { ... })`
|
344
|
+
wouldn't be properly deprecated and `where.not` would work as
|
345
|
+
NAND instead.
|
292
346
|
|
293
|
-
*
|
347
|
+
*Edouard Chin*
|
348
|
+
|
349
|
+
* Fix `db:migrate` task with multiple databases to restore the connection
|
350
|
+
to the previous database.
|
351
|
+
|
352
|
+
The migrate task iterates and establish a connection over each db
|
353
|
+
resulting in the last one to be used by subsequent rake tasks.
|
354
|
+
We should reestablish a connection to the connection that was
|
355
|
+
established before the migrate tasks was run
|
294
356
|
|
295
|
-
*
|
357
|
+
*Edouard Chin*
|
296
358
|
|
297
|
-
|
359
|
+
* Fix multi-threaded issue for `AcceptanceValidator`.
|
298
360
|
|
299
361
|
*Ryuta Kamizono*
|
300
362
|
|
301
|
-
* `becomes` should clear the mutation tracker which is created in `after_initialize`.
|
302
363
|
|
303
|
-
|
364
|
+
## Rails 6.0.1 (November 5, 2019) ##
|
304
365
|
|
305
|
-
|
366
|
+
* Common Table Expressions are allowed on read-only connections.
|
306
367
|
|
307
|
-
*
|
368
|
+
*Chris Morris*
|
308
369
|
|
309
|
-
|
370
|
+
* New record instantiation respects `unscope`.
|
310
371
|
|
311
|
-
*
|
312
|
-
wrongly persists through record.
|
372
|
+
*Ryuta Kamizono*
|
313
373
|
|
314
|
-
|
374
|
+
* Fixed a case where `find_in_batches` could halt too early.
|
315
375
|
|
316
|
-
|
376
|
+
*Takayuki Nakata*
|
317
377
|
|
318
|
-
*
|
319
|
-
|
378
|
+
* Autosaved associations always perform validations when a custom validation
|
379
|
+
context is used.
|
320
380
|
|
321
|
-
|
381
|
+
*Tekin Suleyman*
|
322
382
|
|
383
|
+
* `sql.active_record` notifications now include the `:connection` in
|
384
|
+
their payloads.
|
323
385
|
|
324
|
-
|
386
|
+
*Eugene Kenny*
|
325
387
|
|
326
|
-
*
|
388
|
+
* A rollback encountered in an `after_commit` callback does not reset
|
389
|
+
previously-committed record state.
|
327
390
|
|
328
|
-
|
391
|
+
*Ryuta Kamizono*
|
329
392
|
|
330
|
-
*
|
393
|
+
* Fixed that join order was lost when eager-loading.
|
331
394
|
|
332
|
-
|
333
|
-
have a specified precision then on assignment the value is rounded to
|
334
|
-
that precision. This behavior is now applied to time columns as well.
|
395
|
+
*Ryuta Kamizono*
|
335
396
|
|
336
|
-
|
397
|
+
* `DESCRIBE` queries are allowed on read-only connections.
|
337
398
|
|
338
|
-
*
|
399
|
+
*Dylan Thacker-Smith*
|
339
400
|
|
340
|
-
*
|
401
|
+
* Fixed that records that had been `inspect`ed could not be marshaled.
|
341
402
|
|
342
|
-
|
343
|
-
because until #24542 the quoting for time columns didn't remove the date
|
344
|
-
component. To ensure that values are consistent we now normalize the
|
345
|
-
date component to 2001-01-01 on reading and writing.
|
403
|
+
*Eugene Kenny*
|
346
404
|
|
347
|
-
|
405
|
+
* The connection pool reaper thread is respawned in forked processes. This
|
406
|
+
fixes that idle connections in forked processes wouldn't be reaped.
|
348
407
|
|
349
|
-
*
|
408
|
+
*John Hawthorn*
|
350
409
|
|
351
|
-
|
352
|
-
|
353
|
-
|
410
|
+
* The memoized result of `ActiveRecord::Relation#take` is properly cleared
|
411
|
+
when `ActiveRecord::Relation#reset` or `ActiveRecord::Relation#reload`
|
412
|
+
is called.
|
354
413
|
|
355
|
-
*
|
414
|
+
*Anmol Arora*
|
356
415
|
|
357
|
-
*
|
358
|
-
the parent class was getting deleted when the child was not.
|
416
|
+
* Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
|
359
417
|
|
360
|
-
|
418
|
+
*Hiroyuki Ishii*
|
361
419
|
|
362
|
-
|
420
|
+
* `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
|
363
421
|
|
364
|
-
*
|
422
|
+
*Eugene Kenny*
|
365
423
|
|
366
|
-
|
424
|
+
* Call `while_preventing_writes` directly from `connected_to`.
|
367
425
|
|
368
|
-
|
426
|
+
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)`.
|
369
427
|
|
370
|
-
|
428
|
+
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.
|
371
429
|
|
372
|
-
*
|
373
|
-
|
374
|
-
|
430
|
+
*Eileen M. Uchitelle*
|
431
|
+
|
432
|
+
* Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
|
433
|
+
|
434
|
+
*Kir Shatrov*
|
375
435
|
|
376
|
-
Fixes #28364.
|
377
436
|
|
378
|
-
|
437
|
+
## Rails 6.0.0 (August 16, 2019) ##
|
379
438
|
|
380
|
-
*
|
439
|
+
* Preserve user supplied joins order as much as possible.
|
381
440
|
|
382
|
-
Fixes #
|
441
|
+
Fixes #36761, #34328, #24281, #12953.
|
383
442
|
|
384
443
|
*Ryuta Kamizono*
|
385
444
|
|
386
|
-
*
|
445
|
+
* Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
|
387
446
|
|
388
|
-
*
|
447
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
389
448
|
|
390
|
-
*
|
391
|
-
Using a `Relation` for performing queries is the prefered API.
|
449
|
+
* Add a warning for enum elements with 'not_' prefix.
|
392
450
|
|
393
|
-
|
451
|
+
class Foo
|
452
|
+
enum status: [:sent, :not_sent]
|
453
|
+
end
|
394
454
|
|
395
|
-
*
|
455
|
+
*Edu Depetris*
|
396
456
|
|
397
|
-
|
398
|
-
david_balance = customers(:david).balance
|
399
|
-
Customer.where(balance: [david_balance]).to_sql
|
457
|
+
* Make currency symbols optional for money column type in PostgreSQL
|
400
458
|
|
401
|
-
|
402
|
-
# After : WHERE `customers`.`balance` = 50
|
403
|
-
```
|
459
|
+
*Joel Schneider*
|
404
460
|
|
405
|
-
Fixes #31723.
|
406
461
|
|
407
|
-
|
462
|
+
## Rails 6.0.0.rc2 (July 22, 2019) ##
|
408
463
|
|
409
|
-
*
|
464
|
+
* Add database_exists? method to connection adapters to check if a database exists.
|
410
465
|
|
411
|
-
|
466
|
+
*Guilherme Mansur*
|
467
|
+
|
468
|
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
469
|
+
|
470
|
+
Fixes #36022.
|
412
471
|
|
413
472
|
*Ryuta Kamizono*
|
414
473
|
|
415
|
-
*
|
474
|
+
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
416
475
|
|
417
|
-
Fixes #
|
476
|
+
Fixes #36465.
|
418
477
|
|
419
|
-
*
|
478
|
+
*Jeff Doering*
|
420
479
|
|
421
|
-
*
|
480
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
422
481
|
|
423
|
-
*
|
482
|
+
*Martin R. Schuster*
|
424
483
|
|
425
|
-
* Fix
|
484
|
+
* Fix invalid schema when primary key column has a comment.
|
426
485
|
|
427
|
-
|
486
|
+
Fixes #29966.
|
428
487
|
|
429
|
-
*
|
488
|
+
*Guilherme Goettems Schneider*
|
430
489
|
|
431
|
-
|
490
|
+
* Fix table comment also being applied to the primary key column.
|
432
491
|
|
433
|
-
*
|
492
|
+
*Guilherme Goettems Schneider*
|
434
493
|
|
435
|
-
|
494
|
+
* Fix merging left_joins to maintain its own `join_type` context.
|
436
495
|
|
437
|
-
|
496
|
+
Fixes #36103.
|
438
497
|
|
439
|
-
*
|
498
|
+
*Ryuta Kamizono*
|
440
499
|
|
441
|
-
For example, if you have
|
442
500
|
|
443
|
-
|
444
|
-
belongs_to :author
|
445
|
-
has_many :books, through: :author
|
446
|
-
has_many :subscriptions, through: :books
|
447
|
-
end
|
501
|
+
## Rails 6.0.0.rc1 (April 24, 2019) ##
|
448
502
|
|
449
|
-
|
450
|
-
has_one :post
|
451
|
-
has_many :books
|
452
|
-
has_many :subscriptions, through: :books
|
453
|
-
end
|
503
|
+
* Add `touch` option to `has_one` association.
|
454
504
|
|
455
|
-
|
456
|
-
belongs_to :author
|
457
|
-
has_many :subscriptions
|
458
|
-
end
|
505
|
+
*Abhay Nikam*
|
459
506
|
|
460
|
-
|
461
|
-
belongs_to :book
|
462
|
-
end
|
507
|
+
* Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
|
463
508
|
|
464
|
-
|
509
|
+
```ruby
|
510
|
+
all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
|
511
|
+
assert_equal all, PriceEstimate.all.map(&:estimate_of)
|
512
|
+
```
|
465
513
|
|
466
|
-
|
514
|
+
In Rails 6.0:
|
467
515
|
|
468
|
-
|
516
|
+
```ruby
|
517
|
+
sapphire = treasures(:sapphire)
|
518
|
+
|
519
|
+
nor = all.reject { |e|
|
520
|
+
e.estimate_of_type == sapphire.class.polymorphic_name
|
521
|
+
}.reject { |e|
|
522
|
+
e.estimate_of_id == sapphire.id
|
523
|
+
}
|
524
|
+
assert_equal [cars(:honda)], nor
|
525
|
+
|
526
|
+
without_sapphire = PriceEstimate.where.not(
|
527
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
528
|
+
)
|
529
|
+
assert_equal nor, without_sapphire.map(&:estimate_of)
|
530
|
+
```
|
469
531
|
|
470
|
-
|
471
|
-
just like it would if `post` were persisted.
|
532
|
+
In Rails 6.1:
|
472
533
|
|
473
|
-
|
534
|
+
```ruby
|
535
|
+
sapphire = treasures(:sapphire)
|
474
536
|
|
475
|
-
|
537
|
+
nand = all - [sapphire]
|
538
|
+
assert_equal [treasures(:diamond), cars(:honda)], nand
|
476
539
|
|
477
|
-
|
478
|
-
|
479
|
-
|
540
|
+
without_sapphire = PriceEstimate.where.not(
|
541
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
542
|
+
)
|
543
|
+
assert_equal nand, without_sapphire.map(&:estimate_of)
|
544
|
+
```
|
480
545
|
|
481
|
-
|
546
|
+
*Ryuta Kamizono*
|
482
547
|
|
483
|
-
|
548
|
+
* Fix dirty tracking after rollback.
|
484
549
|
|
485
|
-
|
486
|
-
SQL queries for association counting.
|
550
|
+
Fixes #15018, #30167, #33868.
|
487
551
|
|
488
|
-
*
|
552
|
+
*Ryuta Kamizono*
|
489
553
|
|
490
|
-
*
|
554
|
+
* Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
|
555
|
+
the versioned entries in `ActiveSupport::Cache`. This also means that
|
556
|
+
`ActiveRecord::Relation#cache_key` will now return a stable key that does not
|
557
|
+
include the max timestamp or count any more.
|
491
558
|
|
492
|
-
|
559
|
+
NOTE: This feature is turned off by default, and `cache_key` will still return
|
560
|
+
cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
|
561
|
+
That's the setting for all new apps on Rails 6.0+
|
493
562
|
|
494
|
-
*
|
563
|
+
*Lachlan Sylvester*
|
495
564
|
|
496
|
-
|
565
|
+
* Fix dirty tracking for `touch` to track saved changes.
|
497
566
|
|
498
|
-
|
567
|
+
Fixes #33429.
|
499
568
|
|
500
|
-
*Ryuta
|
569
|
+
*Ryuta Kamzono*
|
570
|
+
|
571
|
+
* `change_column_comment` and `change_table_comment` are invertible only if
|
572
|
+
`to` and `from` options are specified.
|
501
573
|
|
502
|
-
*
|
503
|
-
information.
|
574
|
+
*Yoshiyuki Kinjo*
|
504
575
|
|
505
|
-
|
576
|
+
* Don't call commit/rollback callbacks when a record isn't saved.
|
506
577
|
|
507
|
-
|
578
|
+
Fixes #29747.
|
508
579
|
|
509
|
-
|
510
|
-
of database queries in the log to facilitate N+1 query resolution
|
511
|
-
and other debugging.
|
580
|
+
*Ryuta Kamizono*
|
512
581
|
|
513
|
-
|
514
|
-
recommended for use in the production environment since it relies
|
515
|
-
on Ruby's `Kernel#caller_locations` which is fairly slow.
|
582
|
+
* Fix circular `autosave: true` causes invalid records to be saved.
|
516
583
|
|
517
|
-
|
584
|
+
Prior to the fix, when there was a circular series of `autosave: true`
|
585
|
+
associations, the callback for a `has_many` association was run while
|
586
|
+
another instance of the same callback on the same association hadn't
|
587
|
+
finished running. When control returned to the first instance of the
|
588
|
+
callback, the instance variable had changed, and subsequent associated
|
589
|
+
records weren't saved correctly. Specifically, the ID field for the
|
590
|
+
`belongs_to` corresponding to the `has_many` was `nil`.
|
518
591
|
|
519
|
-
|
592
|
+
Fixes #28080.
|
520
593
|
|
521
|
-
|
522
|
-
# create_table :posts do |t|
|
523
|
-
# t.integer :comments_count, default: 0
|
524
|
-
# t.integer :lock_version
|
525
|
-
# t.timestamps
|
526
|
-
# end
|
527
|
-
class Post < ApplicationRecord
|
528
|
-
end
|
594
|
+
*Larry Reid*
|
529
595
|
|
530
|
-
|
531
|
-
# t.belongs_to :post
|
532
|
-
# end
|
533
|
-
class Comment < ApplicationRecord
|
534
|
-
belongs_to :post, touch: true, counter_cache: true
|
535
|
-
end
|
536
|
-
```
|
596
|
+
* Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
|
537
597
|
|
538
598
|
Before:
|
539
|
-
|
540
|
-
|
541
|
-
# =>
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
comment = Comment.create!(post: post)
|
547
|
-
# => begin transaction
|
548
|
-
INSERT INTO "comments" ("post_id") VALUES (1)
|
549
|
-
|
550
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
|
551
|
-
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
552
|
-
|
553
|
-
UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330',
|
554
|
-
"lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
|
555
|
-
rollback transaction
|
556
|
-
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
557
|
-
|
558
|
-
Comment.take.destroy!
|
559
|
-
# => begin transaction
|
560
|
-
DELETE FROM "comments" WHERE "comments"."id" = 1
|
561
|
-
|
562
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
|
563
|
-
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
564
|
-
|
565
|
-
UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901',
|
566
|
-
"lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
|
567
|
-
rollback transaction
|
568
|
-
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
599
|
+
|
600
|
+
```ruby
|
601
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
602
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
603
|
+
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
|
604
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
|
569
605
|
```
|
570
606
|
|
571
607
|
After:
|
572
|
-
|
573
|
-
|
574
|
-
# =>
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
comment = Comment.create!(post: post)
|
580
|
-
# => begin transaction
|
581
|
-
INSERT INTO "comments" ("post_id") VALUES (1)
|
582
|
-
|
583
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
|
584
|
-
"lock_version" = COALESCE("lock_version", 0) + 1,
|
585
|
-
"updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
|
586
|
-
commit transaction
|
587
|
-
|
588
|
-
comment.destroy!
|
589
|
-
# => begin transaction
|
590
|
-
DELETE FROM "comments" WHERE "comments"."id" = 1
|
591
|
-
|
592
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
|
593
|
-
"lock_version" = COALESCE("lock_version", 0) + 1,
|
594
|
-
"updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
|
595
|
-
commit transaction
|
608
|
+
|
609
|
+
```ruby
|
610
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
611
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
612
|
+
add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
|
613
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
|
596
614
|
```
|
597
615
|
|
598
|
-
|
616
|
+
*Ryuta Kamizono*
|
599
617
|
|
600
|
-
|
618
|
+
* Association loading isn't to be affected by scoping consistently
|
619
|
+
whether preloaded / eager loaded or not, with the exception of `unscoped`.
|
601
620
|
|
602
|
-
|
621
|
+
Before:
|
603
622
|
|
604
|
-
|
623
|
+
```ruby
|
624
|
+
Post.where("1=0").scoping do
|
625
|
+
Comment.find(1).post # => nil
|
626
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
627
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
628
|
+
end
|
629
|
+
```
|
630
|
+
|
631
|
+
After:
|
632
|
+
|
633
|
+
```ruby
|
634
|
+
Post.where("1=0").scoping do
|
635
|
+
Comment.find(1).post # => #<Post id: 1, ...>
|
636
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
637
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
638
|
+
end
|
639
|
+
```
|
605
640
|
|
606
|
-
|
641
|
+
Fixes #34638, #35398.
|
607
642
|
|
608
|
-
*
|
643
|
+
*Ryuta Kamizono*
|
609
644
|
|
610
|
-
*
|
645
|
+
* Add `rails db:prepare` to migrate or setup a database.
|
611
646
|
|
612
|
-
|
647
|
+
Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
|
613
648
|
|
614
|
-
*
|
649
|
+
*Roberto Miranda*
|
615
650
|
|
616
|
-
* Add
|
617
|
-
when canceling statement due to user request.
|
651
|
+
* Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
|
618
652
|
|
619
|
-
*
|
653
|
+
*DHH*
|
620
654
|
|
621
|
-
*
|
622
|
-
|
655
|
+
* Assign all attributes before calling `build` to ensure the child record is visible in
|
656
|
+
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
623
657
|
|
624
|
-
|
658
|
+
Fixes #33249.
|
625
659
|
|
626
|
-
*
|
627
|
-
relation query methods.
|
660
|
+
*Ryan H. Kerr*
|
628
661
|
|
629
|
-
|
630
|
-
```
|
631
|
-
Article.order("LENGTH(title)")
|
632
|
-
```
|
662
|
+
* Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
|
633
663
|
|
634
|
-
After:
|
635
664
|
```
|
636
|
-
|
665
|
+
account.memberships.extract_associated(:user)
|
666
|
+
# => Returns collection of User records
|
637
667
|
```
|
638
668
|
|
639
|
-
|
640
|
-
|
641
|
-
|
669
|
+
*DHH*
|
670
|
+
|
671
|
+
* Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
|
642
672
|
|
643
|
-
|
644
|
-
become an UnknownAttributeReference error in Rails 6.0. Applications
|
645
|
-
can opt in to the future behavior by setting `allow_unsafe_raw_sql`
|
646
|
-
to `:disabled`.
|
673
|
+
For example:
|
647
674
|
|
648
|
-
Common and judged-safe string values (such as simple column
|
649
|
-
references) are unaffected:
|
650
675
|
```
|
651
|
-
|
676
|
+
Post.where(id: 123).annotate("this is a comment").to_sql
|
677
|
+
# SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
|
652
678
|
```
|
653
679
|
|
654
|
-
|
680
|
+
This can be useful in instrumentation or other analysis of issued queries.
|
655
681
|
|
656
|
-
*
|
657
|
-
`Type#serialize`. This means that `update_all(foo: 'true')` will properly
|
658
|
-
persist a boolean.
|
682
|
+
*Matt Yoho*
|
659
683
|
|
660
|
-
|
684
|
+
* Support Optimizer Hints.
|
661
685
|
|
662
|
-
|
663
|
-
|
686
|
+
In most databases, a way to control the optimizer is by using optimizer hints,
|
687
|
+
which can be specified within individual statements.
|
664
688
|
|
665
|
-
|
689
|
+
Example (for MySQL):
|
666
690
|
|
667
|
-
|
668
|
-
|
669
|
-
Check a format of `VERSION`: Allow a migration version number
|
670
|
-
or name of a migration file. Raise error if format of `VERSION` is invalid.
|
671
|
-
Raise error if target migration doesn't exist.
|
691
|
+
Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
|
692
|
+
# SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
|
672
693
|
|
673
|
-
|
694
|
+
Example (for PostgreSQL with pg_hint_plan):
|
674
695
|
|
675
|
-
|
676
|
-
|
696
|
+
Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
|
697
|
+
# SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
|
677
698
|
|
678
|
-
|
699
|
+
See also:
|
679
700
|
|
680
|
-
*
|
701
|
+
* https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
|
702
|
+
* https://pghintplan.osdn.jp/pg_hint_plan.html
|
703
|
+
* https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
|
704
|
+
* https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
|
705
|
+
* https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
|
681
706
|
|
682
|
-
*
|
707
|
+
*Ryuta Kamizono*
|
683
708
|
|
684
|
-
|
709
|
+
* Fix query attribute method on user-defined attribute to be aware of typecasted value.
|
685
710
|
|
686
|
-
|
711
|
+
For example, the following code no longer return false as casted non-empty string:
|
687
712
|
|
688
|
-
|
713
|
+
```
|
714
|
+
class Post < ActiveRecord::Base
|
715
|
+
attribute :user_defined_text, :text
|
716
|
+
end
|
689
717
|
|
690
|
-
|
718
|
+
Post.new(user_defined_text: "false").user_defined_text? # => true
|
719
|
+
```
|
691
720
|
|
692
|
-
*
|
721
|
+
*Yuji Kamijima*
|
693
722
|
|
694
|
-
*
|
723
|
+
* Quote empty ranges like other empty enumerables.
|
695
724
|
|
696
|
-
*
|
725
|
+
*Patrick Rebsch*
|
697
726
|
|
698
|
-
*
|
727
|
+
* Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
|
728
|
+
allowing bulk inserts akin to the bulk updates provided by `update_all` and
|
729
|
+
bulk deletes by `delete_all`.
|
699
730
|
|
700
|
-
|
731
|
+
Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
|
732
|
+
for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
|
733
|
+
for MySQL.
|
701
734
|
|
702
|
-
*
|
735
|
+
*Bob Lail*
|
703
736
|
|
704
|
-
|
737
|
+
* Add `rails db:seed:replant` that truncates tables of each database
|
738
|
+
for current environment and loads the seeds.
|
705
739
|
|
706
|
-
*
|
740
|
+
*bogdanvlviv*, *DHH*
|
707
741
|
|
708
|
-
|
742
|
+
* Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
|
709
743
|
|
710
|
-
*
|
744
|
+
*bogdanvlviv*
|
711
745
|
|
712
|
-
|
746
|
+
* Deprecate mismatched collation comparison for uniqueness validator.
|
713
747
|
|
714
|
-
|
748
|
+
Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
|
749
|
+
To continue case sensitive comparison on the case insensitive column,
|
750
|
+
pass `case_sensitive: true` option explicitly to the uniqueness validator.
|
715
751
|
|
716
|
-
*
|
752
|
+
*Ryuta Kamizono*
|
717
753
|
|
718
|
-
*
|
754
|
+
* Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
|
719
755
|
|
720
|
-
|
756
|
+
Fixes #27340.
|
721
757
|
|
722
|
-
*
|
758
|
+
*Willian Gustavo Veiga*
|
723
759
|
|
724
|
-
|
760
|
+
* Add negative scopes for all enum values.
|
725
761
|
|
726
|
-
|
762
|
+
Example:
|
727
763
|
|
728
|
-
|
764
|
+
class Post < ActiveRecord::Base
|
765
|
+
enum status: %i[ drafted active trashed ]
|
766
|
+
end
|
729
767
|
|
730
|
-
|
768
|
+
Post.not_drafted # => where.not(status: :drafted)
|
769
|
+
Post.not_active # => where.not(status: :active)
|
770
|
+
Post.not_trashed # => where.not(status: :trashed)
|
731
771
|
|
732
|
-
*
|
772
|
+
*DHH*
|
733
773
|
|
734
|
-
* Fix
|
735
|
-
|
774
|
+
* Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
|
775
|
+
|
776
|
+
Fixes #35214.
|
777
|
+
|
778
|
+
*Juani Villarejo*
|
779
|
+
|
780
|
+
|
781
|
+
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
782
|
+
|
783
|
+
* No changes.
|
784
|
+
|
785
|
+
|
786
|
+
## Rails 6.0.0.beta2 (February 25, 2019) ##
|
787
|
+
|
788
|
+
* Fix prepared statements caching to be enabled even when query caching is enabled.
|
789
|
+
|
790
|
+
*Ryuta Kamizono*
|
791
|
+
|
792
|
+
* Ensure `update_all` series cares about optimistic locking.
|
793
|
+
|
794
|
+
*Ryuta Kamizono*
|
795
|
+
|
796
|
+
* Don't allow `where` with non numeric string matches to 0 values.
|
797
|
+
|
798
|
+
*Ryuta Kamizono*
|
799
|
+
|
800
|
+
* Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
|
801
|
+
|
802
|
+
`destroy_by` allows relation to find all the records matching the condition and perform
|
803
|
+
`destroy_all` on the matched records.
|
804
|
+
|
805
|
+
Example:
|
806
|
+
|
807
|
+
Person.destroy_by(name: 'David')
|
808
|
+
Person.destroy_by(name: 'David', rating: 4)
|
809
|
+
|
810
|
+
david = Person.find_by(name: 'David')
|
811
|
+
david.posts.destroy_by(id: [1, 2, 3])
|
812
|
+
|
813
|
+
`delete_by` allows relation to find all the records matching the condition and perform
|
814
|
+
`delete_all` on the matched records.
|
815
|
+
|
816
|
+
Example:
|
817
|
+
|
818
|
+
Person.delete_by(name: 'David')
|
819
|
+
Person.delete_by(name: 'David', rating: 4)
|
820
|
+
|
821
|
+
david = Person.find_by(name: 'David')
|
822
|
+
david.posts.delete_by(id: [1, 2, 3])
|
823
|
+
|
824
|
+
*Abhay Nikam*
|
825
|
+
|
826
|
+
* Don't allow `where` with invalid value matches to nil values.
|
827
|
+
|
828
|
+
Fixes #33624.
|
829
|
+
|
830
|
+
*Ryuta Kamizono*
|
831
|
+
|
832
|
+
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
|
833
|
+
|
834
|
+
*Ryuta Kamizono*
|
835
|
+
|
836
|
+
* Deprecate using class level querying methods if the receiver scope
|
837
|
+
regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
|
838
|
+
|
839
|
+
*Ryuta Kamizono*
|
840
|
+
|
841
|
+
* Allow applications to automatically switch connections.
|
842
|
+
|
843
|
+
Adds a middleware and configuration options that can be used in your
|
844
|
+
application to automatically switch between the writing and reading
|
845
|
+
database connections.
|
846
|
+
|
847
|
+
`GET` and `HEAD` requests will read from the replica unless there was
|
848
|
+
a write in the last 2 seconds, otherwise they will read from the primary.
|
849
|
+
Non-get requests will always write to the primary. The middleware accepts
|
850
|
+
an argument for a Resolver class and an Operations class where you are able
|
851
|
+
to change how the auto-switcher works to be most beneficial for your
|
852
|
+
application.
|
853
|
+
|
854
|
+
To use the middleware in your application you can use the following
|
855
|
+
configuration options:
|
736
856
|
|
737
|
-
Before:
|
738
857
|
```
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
|
858
|
+
config.active_record.database_selector = { delay: 2.seconds }
|
859
|
+
config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
|
860
|
+
config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
|
743
861
|
```
|
744
862
|
|
745
|
-
|
863
|
+
To change the database selection strategy, pass a custom class to the
|
864
|
+
configuration options:
|
865
|
+
|
746
866
|
```
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
|
867
|
+
config.active_record.database_selector = { delay: 10.seconds }
|
868
|
+
config.active_record.database_resolver = MyResolver
|
869
|
+
config.active_record.database_resolver_context = MyResolver::MyCookies
|
751
870
|
```
|
752
871
|
|
753
|
-
|
872
|
+
*Eileen M. Uchitelle*
|
754
873
|
|
755
|
-
|
874
|
+
* MySQL: Support `:size` option to change text and blob size.
|
756
875
|
|
757
|
-
*
|
876
|
+
*Ryuta Kamizono*
|
758
877
|
|
759
|
-
|
878
|
+
* Make `t.timestamps` with precision by default.
|
760
879
|
|
761
880
|
*Ryuta Kamizono*
|
762
881
|
|
763
|
-
* MySQL: Don't lose `auto_increment: true` in the `db/schema.rb`.
|
764
882
|
|
765
|
-
|
883
|
+
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
884
|
+
|
885
|
+
* Remove deprecated `#set_state` from the transaction object.
|
886
|
+
|
887
|
+
*Rafael Mendonça França*
|
888
|
+
|
889
|
+
* Remove deprecated `#supports_statement_cache?` from the database adapters.
|
890
|
+
|
891
|
+
*Rafael Mendonça França*
|
892
|
+
|
893
|
+
* Remove deprecated `#insert_fixtures` from the database adapters.
|
894
|
+
|
895
|
+
*Rafael Mendonça França*
|
896
|
+
|
897
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
|
898
|
+
|
899
|
+
*Rafael Mendonça França*
|
900
|
+
|
901
|
+
* Do not allow passing the column name to `sum` when a block is passed.
|
902
|
+
|
903
|
+
*Rafael Mendonça França*
|
904
|
+
|
905
|
+
* Do not allow passing the column name to `count` when a block is passed.
|
906
|
+
|
907
|
+
*Rafael Mendonça França*
|
908
|
+
|
909
|
+
* Remove delegation of missing methods in a relation to arel.
|
910
|
+
|
911
|
+
*Rafael Mendonça França*
|
912
|
+
|
913
|
+
* Remove delegation of missing methods in a relation to private methods of the class.
|
914
|
+
|
915
|
+
*Rafael Mendonça França*
|
916
|
+
|
917
|
+
* Deprecate `config.active_record.sqlite3.represent_boolean_as_integer`.
|
918
|
+
|
919
|
+
*Rafael Mendonça França*
|
920
|
+
|
921
|
+
* Change `SQLite3Adapter` to always represent boolean values as integers.
|
922
|
+
|
923
|
+
*Rafael Mendonça França*
|
924
|
+
|
925
|
+
* Remove ability to specify a timestamp name for `#cache_key`.
|
926
|
+
|
927
|
+
*Rafael Mendonça França*
|
928
|
+
|
929
|
+
* Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
|
930
|
+
|
931
|
+
*Rafael Mendonça França*
|
932
|
+
|
933
|
+
* Remove deprecated `expand_hash_conditions_for_aggregates`.
|
934
|
+
|
935
|
+
*Rafael Mendonça França*
|
936
|
+
|
937
|
+
* Set polymorphic type column to NULL on `dependent: :nullify` strategy.
|
938
|
+
|
939
|
+
On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
|
940
|
+
|
941
|
+
*Laerti Papa*
|
942
|
+
|
943
|
+
* Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
|
944
|
+
|
945
|
+
*Gannon McGibbon*
|
946
|
+
|
947
|
+
* Add support for endless ranges introduces in Ruby 2.6.
|
948
|
+
|
949
|
+
*Greg Navis*
|
950
|
+
|
951
|
+
* Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
|
766
952
|
|
767
953
|
*Ryuta Kamizono*
|
768
954
|
|
769
|
-
*
|
955
|
+
* MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
|
770
956
|
|
771
|
-
|
957
|
+
Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
|
958
|
+
format for InnoDB tables. The default setting is `DYNAMIC`.
|
959
|
+
The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
|
772
960
|
|
773
961
|
*Ryuta Kamizono*
|
774
962
|
|
775
|
-
*
|
963
|
+
* Fix join table column quoting with SQLite.
|
776
964
|
|
777
|
-
|
778
|
-
this datatype in Active Record. However, the serialization of
|
779
|
-
`PostgreSQL::OID::Range` was incomplete, because it did not properly
|
780
|
-
cast the bounds that make up the range. This led to subseconds being
|
781
|
-
dropped in SQL commands:
|
965
|
+
*Gannon McGibbon*
|
782
966
|
|
783
|
-
|
967
|
+
* Allow disabling scopes generated by `ActiveRecord.enum`.
|
784
968
|
|
785
|
-
|
786
|
-
# => "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)"
|
969
|
+
*Alfred Dominic*
|
787
970
|
|
788
|
-
|
971
|
+
* Ensure that `delete_all` on collection proxy returns affected count.
|
789
972
|
|
790
|
-
|
791
|
-
# => "[2010-01-01 13:30:00.670277,2011-02-02 19:30:00.745125)"
|
973
|
+
*Ryuta Kamizono*
|
792
974
|
|
793
|
-
|
975
|
+
* Reset scope after delete on collection association to clear stale offsets of removed records.
|
794
976
|
|
795
|
-
*
|
796
|
-
array.
|
977
|
+
*Gannon McGibbon*
|
797
978
|
|
798
|
-
|
979
|
+
* Add the ability to prevent writes to a database for the duration of a block.
|
799
980
|
|
800
|
-
|
981
|
+
Allows the application to prevent writes to a database. This can be useful when
|
982
|
+
you're building out multiple databases and want to make sure you're not sending
|
983
|
+
writes when you want a read.
|
801
984
|
|
802
|
-
|
985
|
+
If `while_preventing_writes` is called and the query is considered a write
|
986
|
+
query the database will raise an exception regardless of whether the database
|
987
|
+
user is able to write.
|
803
988
|
|
804
|
-
|
989
|
+
This is not meant to be a catch-all for write queries but rather a way to enforce
|
990
|
+
read-only queries without opening a second connection. One purpose of this is to
|
991
|
+
catch accidental writes, not all writes.
|
805
992
|
|
806
|
-
*
|
807
|
-
more descriptive.
|
993
|
+
*Eileen M. Uchitelle*
|
808
994
|
|
809
|
-
|
995
|
+
* Allow aliased attributes to be used in `#update_columns` and `#update`.
|
810
996
|
|
811
|
-
*
|
997
|
+
*Gannon McGibbon*
|
812
998
|
|
813
|
-
*
|
814
|
-
when lock wait timeout exceeded.
|
999
|
+
* Allow spaces in postgres table names.
|
815
1000
|
|
816
|
-
|
1001
|
+
Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
|
817
1002
|
|
818
|
-
*
|
1003
|
+
*Gannon McGibbon*
|
819
1004
|
|
820
|
-
|
1005
|
+
* Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
|
821
1006
|
|
822
|
-
|
1007
|
+
PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
|
1008
|
+
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
823
1009
|
|
824
|
-
|
1010
|
+
```ruby
|
1011
|
+
class DeveloperName < ActiveRecord::Type::String
|
1012
|
+
def deserialize(value)
|
1013
|
+
"Developer: #{value}"
|
1014
|
+
end
|
1015
|
+
end
|
825
1016
|
|
826
|
-
|
1017
|
+
class AttributedDeveloper < ActiveRecord::Base
|
1018
|
+
self.table_name = "developers"
|
827
1019
|
|
828
|
-
|
1020
|
+
attribute :name, DeveloperName.new
|
829
1021
|
|
830
|
-
|
1022
|
+
self.ignored_columns += ["name"]
|
1023
|
+
end
|
831
1024
|
|
832
|
-
|
1025
|
+
developer = AttributedDeveloper.create
|
1026
|
+
developer.update_column :name, "name"
|
833
1027
|
|
834
|
-
|
1028
|
+
loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
|
1029
|
+
puts loaded_developer.name # should be "Developer: name" but it's just "name"
|
1030
|
+
```
|
835
1031
|
|
836
|
-
*
|
1032
|
+
*Dmitry Tsepelev*
|
837
1033
|
|
838
|
-
|
1034
|
+
* Make the implicit order column configurable.
|
839
1035
|
|
840
|
-
|
841
|
-
|
1036
|
+
When calling ordered finder methods such as `first` or `last` without an
|
1037
|
+
explicit order clause, ActiveRecord sorts records by primary key. This can
|
1038
|
+
result in unpredictable and surprising behaviour when the primary key is
|
1039
|
+
not an auto-incrementing integer, for example when it's a UUID. This change
|
1040
|
+
makes it possible to override the column used for implicit ordering such
|
1041
|
+
that `first` and `last` will return more predictable results.
|
842
1042
|
|
843
|
-
|
1043
|
+
Example:
|
844
1044
|
|
845
|
-
|
1045
|
+
class Project < ActiveRecord::Base
|
1046
|
+
self.implicit_order_column = "created_at"
|
1047
|
+
end
|
846
1048
|
|
847
|
-
*
|
848
|
-
need to generate it, it can be created with `rails g application_record`.
|
1049
|
+
*Tekin Suleyman*
|
849
1050
|
|
850
|
-
|
1051
|
+
* Bump minimum PostgreSQL version to 9.3.
|
851
1052
|
|
852
|
-
*
|
1053
|
+
*Yasuo Honda*
|
853
1054
|
|
854
|
-
|
1055
|
+
* Values of enum are frozen, raising an error when attempting to modify them.
|
1056
|
+
|
1057
|
+
*Emmanuel Byrd*
|
855
1058
|
|
856
|
-
*
|
857
|
-
`destroyed_by_association` will now be set to the reflection, matching the
|
858
|
-
behaviour of `has_many` associations.
|
1059
|
+
* Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
|
859
1060
|
|
860
|
-
|
1061
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
|
861
1062
|
|
862
|
-
|
1063
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
|
863
1064
|
|
864
|
-
|
865
|
-
|
1065
|
+
Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
|
1066
|
+
|
1067
|
+
Example:
|
866
1068
|
|
867
1069
|
```
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
1070
|
+
class MySubclassedError < ActiveRecord::StatementInvalid
|
1071
|
+
def initialize(message, sql:, binds:)
|
1072
|
+
super(message, sql: sql, binds: binds)
|
1073
|
+
end
|
1074
|
+
end
|
873
1075
|
```
|
874
1076
|
|
875
|
-
*
|
1077
|
+
*Gannon McGibbon*
|
876
1078
|
|
877
|
-
*
|
878
|
-
post-type-cast value for rendering in single-field form inputs.
|
1079
|
+
* Add an `:if_not_exists` option to `create_table`.
|
879
1080
|
|
880
|
-
|
1081
|
+
Example:
|
881
1082
|
|
882
|
-
|
883
|
-
|
1083
|
+
create_table :posts, if_not_exists: true do |t|
|
1084
|
+
t.string :title
|
1085
|
+
end
|
1086
|
+
|
1087
|
+
That would execute:
|
1088
|
+
|
1089
|
+
CREATE TABLE IF NOT EXISTS posts (
|
1090
|
+
...
|
1091
|
+
)
|
1092
|
+
|
1093
|
+
If the table already exists, `if_not_exists: false` (the default) raises an
|
1094
|
+
exception whereas `if_not_exists: true` does nothing.
|
1095
|
+
|
1096
|
+
*fatkodima*, *Stefan Kanev*
|
884
1097
|
|
885
|
-
|
1098
|
+
* Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
|
1099
|
+
|
1100
|
+
*Christophe Maximin*
|
1101
|
+
|
1102
|
+
* Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
|
1103
|
+
|
1104
|
+
*Gannon McGibbon*
|
1105
|
+
|
1106
|
+
* `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
|
1107
|
+
if the attribute does not exist.
|
886
1108
|
|
887
1109
|
*Sean Griffin*
|
888
1110
|
|
889
|
-
*
|
1111
|
+
* Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
|
890
1112
|
|
891
|
-
|
892
|
-
|
1113
|
+
````
|
1114
|
+
User.connected_to(database: { writing: "postgres://foo" }) do
|
1115
|
+
User.create!(name: "Gannon")
|
1116
|
+
end
|
893
1117
|
|
894
|
-
|
895
|
-
|
896
|
-
|
1118
|
+
config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
|
1119
|
+
User.connected_to(database: { reading: config }) do
|
1120
|
+
User.count
|
1121
|
+
end
|
1122
|
+
````
|
897
1123
|
|
898
|
-
*
|
1124
|
+
*Gannon McGibbon*
|
899
1125
|
|
900
|
-
*
|
901
|
-
`in_batches`).
|
1126
|
+
* Support default expression for MySQL.
|
902
1127
|
|
903
|
-
|
904
|
-
until the end of the request or job.
|
1128
|
+
MySQL 8.0.13 and higher supports default value to be a function or expression.
|
905
1129
|
|
906
|
-
|
1130
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-table.html
|
907
1131
|
|
908
|
-
*
|
909
|
-
`ActiveRecord::StatementInvalid` exceptions.
|
1132
|
+
*Ryuta Kamizono*
|
910
1133
|
|
911
|
-
|
1134
|
+
* Support expression indexes for MySQL.
|
912
1135
|
|
913
|
-
|
1136
|
+
MySQL 8.0.13 and higher supports functional key parts that index
|
1137
|
+
expression values rather than column or column prefix values.
|
914
1138
|
|
915
|
-
|
1139
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-index.html
|
916
1140
|
|
917
1141
|
*Ryuta Kamizono*
|
918
1142
|
|
919
|
-
* Fix
|
1143
|
+
* Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
|
920
1144
|
|
921
|
-
|
922
|
-
inner transaction would still be marked as persisted.
|
1145
|
+
Fixes #33056.
|
923
1146
|
|
924
|
-
|
925
|
-
parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted.
|
1147
|
+
*Federico Martinez*
|
926
1148
|
|
927
|
-
|
1149
|
+
* Add basic API for connection switching to support multiple databases.
|
928
1150
|
|
929
|
-
|
1151
|
+
1) Adds a `connects_to` method for models to connect to multiple databases. Example:
|
930
1152
|
|
931
|
-
|
932
|
-
|
933
|
-
|
1153
|
+
```
|
1154
|
+
class AnimalsModel < ApplicationRecord
|
1155
|
+
self.abstract_class = true
|
934
1156
|
|
935
|
-
|
1157
|
+
connects_to database: { writing: :animals_primary, reading: :animals_replica }
|
1158
|
+
end
|
936
1159
|
|
937
|
-
|
1160
|
+
class Dog < AnimalsModel
|
1161
|
+
# connected to both the animals_primary db for writing and the animals_replica for reading
|
1162
|
+
end
|
1163
|
+
```
|
938
1164
|
|
939
|
-
|
1165
|
+
2) Adds a `connected_to` block method for switching connection roles or connecting to
|
1166
|
+
a database that the model didn't connect to. Connecting to the database in this block is
|
1167
|
+
useful when you have another defined connection, for example `slow_replica` that you don't
|
1168
|
+
want to connect to by default but need in the console, or a specific code block.
|
940
1169
|
|
941
|
-
|
942
|
-
|
1170
|
+
```
|
1171
|
+
ActiveRecord::Base.connected_to(role: :reading) do
|
1172
|
+
Dog.first # finds dog from replica connected to AnimalsBase
|
1173
|
+
Book.first # doesn't have a reading connection, will raise an error
|
1174
|
+
end
|
1175
|
+
```
|
1176
|
+
|
1177
|
+
```
|
1178
|
+
ActiveRecord::Base.connected_to(database: :slow_replica) do
|
1179
|
+
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
|
1180
|
+
end
|
1181
|
+
```
|
943
1182
|
|
944
|
-
*
|
1183
|
+
*Eileen M. Uchitelle*
|
945
1184
|
|
946
|
-
*
|
947
|
-
if the child records were deleted before the parent was saved, they would
|
948
|
-
still be persisted. Now, if child records are deleted before the parent is saved
|
949
|
-
on a `has_many :through` association, the child records will not be persisted.
|
1185
|
+
* Enum raises on invalid definition values
|
950
1186
|
|
951
|
-
|
1187
|
+
When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
|
1188
|
+
commit checks that only valid definition values are provided, those can
|
1189
|
+
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
1190
|
+
raises an `ArgumentError`.
|
952
1191
|
|
953
|
-
|
954
|
-
the merged relation into LEFT OUTER JOIN.
|
1192
|
+
Fixes #33961
|
955
1193
|
|
956
|
-
|
1194
|
+
*Alberto Almagro*
|
1195
|
+
|
1196
|
+
* Reloading associations now clears the Query Cache like `Persistence#reload` does.
|
957
1197
|
|
958
1198
|
```
|
959
|
-
|
960
|
-
|
961
|
-
|
1199
|
+
class Post < ActiveRecord::Base
|
1200
|
+
has_one :category
|
1201
|
+
belongs_to :author
|
1202
|
+
has_many :comments
|
1203
|
+
end
|
962
1204
|
|
963
|
-
#
|
964
|
-
|
1205
|
+
# Each of the following will now clear the query cache.
|
1206
|
+
post.reload_category
|
1207
|
+
post.reload_author
|
1208
|
+
post.comments.reload
|
965
1209
|
```
|
966
1210
|
|
967
|
-
*
|
1211
|
+
*Christophe Maximin*
|
968
1212
|
|
969
|
-
* `
|
970
|
-
|
1213
|
+
* Added `index` option for `change_table` migration helpers.
|
1214
|
+
With this change you can create indexes while adding new
|
1215
|
+
columns into the existing tables.
|
971
1216
|
|
972
|
-
|
1217
|
+
Example:
|
973
1218
|
|
974
|
-
|
975
|
-
|
1219
|
+
change_table(:languages) do |t|
|
1220
|
+
t.string :country_code, index: true
|
1221
|
+
end
|
976
1222
|
|
977
|
-
*
|
1223
|
+
*Mehmet Emin İNAÇ*
|
978
1224
|
|
979
|
-
*
|
1225
|
+
* Fix `transaction` reverting for migrations.
|
980
1226
|
|
981
|
-
|
1227
|
+
Before: Commands inside a `transaction` in a reverted migration ran uninverted.
|
1228
|
+
Now: This change fixes that by reverting commands inside `transaction` block.
|
982
1229
|
|
983
|
-
*
|
1230
|
+
*fatkodima*, *David Verhasselt*
|
984
1231
|
|
985
|
-
|
1232
|
+
* Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
|
1233
|
+
|
1234
|
+
*Gannon McGibbon*, *Max Albrecht*
|
986
1235
|
|
987
|
-
*
|
1236
|
+
* Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
|
1237
|
+
|
1238
|
+
*Gannon McGibbon*
|
1239
|
+
|
1240
|
+
* Don't update counter cache unless the record is actually saved.
|
1241
|
+
|
1242
|
+
Fixes #31493, #33113, #33117.
|
988
1243
|
|
989
1244
|
*Ryuta Kamizono*
|
990
1245
|
|
991
|
-
*
|
1246
|
+
* Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
|
992
1247
|
|
993
|
-
|
1248
|
+
*Gannon McGibbon*, *Kevin Cheng*
|
994
1249
|
|
995
|
-
|
1250
|
+
* SQLite3 adapter supports expression indexes.
|
996
1251
|
|
997
|
-
|
998
|
-
|
999
|
-
|
1252
|
+
```
|
1253
|
+
create_table :users do |t|
|
1254
|
+
t.string :email
|
1255
|
+
end
|
1256
|
+
|
1257
|
+
add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
|
1258
|
+
```
|
1000
1259
|
|
1001
|
-
|
1002
|
-
until you set `ActiveRecord::Base.cache_versioning = true`. That's the setting for all new apps on Rails 5.2+
|
1260
|
+
*Gray Kemmey*
|
1003
1261
|
|
1004
|
-
|
1262
|
+
* Allow subclasses to redefine autosave callbacks for associated records.
|
1005
1263
|
|
1006
|
-
|
1264
|
+
Fixes #33305.
|
1007
1265
|
|
1008
|
-
*
|
1266
|
+
*Andrey Subbota*
|
1009
1267
|
|
1010
|
-
*
|
1268
|
+
* Bump minimum MySQL version to 5.5.8.
|
1011
1269
|
|
1012
|
-
|
1270
|
+
*Yasuo Honda*
|
1013
1271
|
|
1014
|
-
|
1272
|
+
* Use MySQL utf8mb4 character set by default.
|
1015
1273
|
|
1016
|
-
|
1274
|
+
`utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
|
1275
|
+
The previous default 3-Byte encoding character set `utf8` is not enough to support them.
|
1276
|
+
|
1277
|
+
*Yasuo Honda*
|
1278
|
+
|
1279
|
+
* Fix duplicated record creation when using nested attributes with `create_with`.
|
1280
|
+
|
1281
|
+
*Darwin Wu*
|
1282
|
+
|
1283
|
+
* Configuration item `config.filter_parameters` could also filter out
|
1284
|
+
sensitive values of database columns when calling `#inspect`.
|
1285
|
+
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
1286
|
+
specify sensitive attributes to specific model.
|
1287
|
+
|
1288
|
+
```
|
1289
|
+
Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
|
1290
|
+
Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
|
1291
|
+
SecureAccount.filter_attributes += [:name]
|
1292
|
+
SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
|
1293
|
+
```
|
1294
|
+
|
1295
|
+
*Zhang Kang*, *Yoshiyuki Kinjo*
|
1296
|
+
|
1297
|
+
* Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
|
1298
|
+
`indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
|
1299
|
+
and `joins_per_query` methods in `DatabaseLimits`.
|
1017
1300
|
|
1018
1301
|
*Ryuta Kamizono*
|
1019
1302
|
|
1020
|
-
*
|
1021
|
-
when the current migration does not exist.
|
1303
|
+
* `ActiveRecord::Base.configurations` now returns an object.
|
1022
1304
|
|
1023
|
-
|
1305
|
+
`ActiveRecord::Base.configurations` used to return a hash, but this
|
1306
|
+
is an inflexible data model. In order to improve multiple-database
|
1307
|
+
handling in Rails, we've changed this to return an object. Some methods
|
1308
|
+
are provided to make the object behave hash-like in order to ease the
|
1309
|
+
transition process. Since most applications don't manipulate the hash
|
1310
|
+
we've decided to add backwards-compatible functionality that will throw
|
1311
|
+
a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
|
1312
|
+
will use the new version internally and externally.
|
1024
1313
|
|
1025
|
-
|
1314
|
+
For example, the following `database.yml`:
|
1026
1315
|
|
1027
|
-
|
1316
|
+
```
|
1317
|
+
development:
|
1318
|
+
adapter: sqlite3
|
1319
|
+
database: db/development.sqlite3
|
1320
|
+
```
|
1321
|
+
|
1322
|
+
Used to become a hash:
|
1323
|
+
|
1324
|
+
```
|
1325
|
+
{ "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
|
1326
|
+
```
|
1028
1327
|
|
1029
|
-
|
1328
|
+
Is now converted into the following object:
|
1329
|
+
|
1330
|
+
```
|
1331
|
+
#<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
|
1332
|
+
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
1333
|
+
@spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
|
1334
|
+
]
|
1335
|
+
```
|
1336
|
+
|
1337
|
+
Iterating over the database configurations has also changed. Instead of
|
1338
|
+
calling hash methods on the `configurations` hash directly, a new method `configs_for` has
|
1339
|
+
been provided that allows you to select the correct configuration. `env_name` and
|
1340
|
+
`spec_name` arguments are optional. For example, these return an array of
|
1341
|
+
database config objects for the requested environment and a single database config object
|
1342
|
+
will be returned for the requested environment and specification name respectively.
|
1343
|
+
|
1344
|
+
```
|
1345
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development")
|
1346
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
|
1347
|
+
```
|
1348
|
+
|
1349
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*
|
1030
1350
|
|
1031
|
-
|
1032
|
-
|
1351
|
+
* Add database configuration to disable advisory locks.
|
1352
|
+
|
1353
|
+
```
|
1354
|
+
production:
|
1355
|
+
adapter: postgresql
|
1356
|
+
advisory_locks: false
|
1357
|
+
```
|
1358
|
+
|
1359
|
+
*Guo Xiang*
|
1360
|
+
|
1361
|
+
* SQLite3 adapter `alter_table` method restores foreign keys.
|
1362
|
+
|
1363
|
+
*Yasuo Honda*
|
1364
|
+
|
1365
|
+
* Allow `:to_table` option to `invert_remove_foreign_key`.
|
1366
|
+
|
1367
|
+
Example:
|
1368
|
+
|
1369
|
+
remove_foreign_key :accounts, to_table: :owners
|
1370
|
+
|
1371
|
+
*Nikolay Epifanov*, *Rich Chen*
|
1372
|
+
|
1373
|
+
* Add environment & load_config dependency to `bin/rake db:seed` to enable
|
1374
|
+
seed load in environments without Rails and custom DB configuration
|
1375
|
+
|
1376
|
+
*Tobias Bielohlawek*
|
1377
|
+
|
1378
|
+
* Fix default value for mysql time types with specified precision.
|
1379
|
+
|
1380
|
+
*Nikolay Kondratyev*
|
1381
|
+
|
1382
|
+
* Fix `touch` option to behave consistently with `Persistence#touch` method.
|
1033
1383
|
|
1034
1384
|
*Ryuta Kamizono*
|
1035
1385
|
|
1036
|
-
*
|
1386
|
+
* Migrations raise when duplicate column definition.
|
1037
1387
|
|
1038
|
-
|
1388
|
+
Fixes #33024.
|
1389
|
+
|
1390
|
+
*Federico Martinez*
|
1391
|
+
|
1392
|
+
* Bump minimum SQLite version to 3.8
|
1393
|
+
|
1394
|
+
*Yasuo Honda*
|
1395
|
+
|
1396
|
+
* Fix parent record should not get saved with duplicate children records.
|
1397
|
+
|
1398
|
+
Fixes #32940.
|
1399
|
+
|
1400
|
+
*Santosh Wadghule*
|
1401
|
+
|
1402
|
+
* Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
|
1403
|
+
|
1404
|
+
*Brian Durand*
|
1405
|
+
|
1406
|
+
* Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
|
1407
|
+
use loaded association ids if present.
|
1408
|
+
|
1409
|
+
*Graham Turner*
|
1410
|
+
|
1411
|
+
* Add support to preload associations of polymorphic associations when not all the records have the requested associations.
|
1039
1412
|
|
1040
|
-
*
|
1041
|
-
Previously this method always returned an empty array.
|
1413
|
+
*Dana Sherson*
|
1042
1414
|
|
1043
|
-
|
1415
|
+
* Add `touch_all` method to `ActiveRecord::Relation`.
|
1416
|
+
|
1417
|
+
Example:
|
1418
|
+
|
1419
|
+
Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
|
1420
|
+
|
1421
|
+
*fatkodima*, *duggiefresh*
|
1422
|
+
|
1423
|
+
* Add `ActiveRecord::Base.base_class?` predicate.
|
1424
|
+
|
1425
|
+
*Bogdan Gusiev*
|
1426
|
+
|
1427
|
+
* Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
|
1428
|
+
|
1429
|
+
*Tan Huynh*, *Yukio Mizuta*
|
1430
|
+
|
1431
|
+
* Rails 6 requires Ruby 2.5.0 or newer.
|
1432
|
+
|
1433
|
+
*Jeremy Daer*, *Kasper Timm Hansen*
|
1434
|
+
|
1435
|
+
* Deprecate `update_attributes`/`!` in favor of `update`/`!`.
|
1436
|
+
|
1437
|
+
*Eddie Lebow*
|
1438
|
+
|
1439
|
+
* Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
|
1440
|
+
`ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
|
1441
|
+
|
1442
|
+
*DHH*
|
1443
|
+
|
1444
|
+
* Add `Relation#pick` as short-hand for single-value plucks.
|
1445
|
+
|
1446
|
+
*DHH*
|
1044
1447
|
|
1045
1448
|
|
1046
|
-
Please check [5-
|
1449
|
+
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.
|