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