activerecord 6.0.0 → 6.1.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 +1178 -600
- data/MIT-LICENSE +1 -1
- data/README.rdoc +4 -4
- data/lib/active_record/aggregations.rb +5 -6
- data/lib/active_record/association_relation.rb +30 -10
- data/lib/active_record/associations/alias_tracker.rb +19 -16
- data/lib/active_record/associations/association.rb +55 -29
- data/lib/active_record/associations/association_scope.rb +19 -15
- data/lib/active_record/associations/belongs_to_association.rb +23 -10
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -3
- data/lib/active_record/associations/builder/association.rb +32 -5
- data/lib/active_record/associations/builder/belongs_to.rb +10 -7
- data/lib/active_record/associations/builder/collection_association.rb +5 -4
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +0 -3
- data/lib/active_record/associations/builder/has_many.rb +6 -2
- data/lib/active_record/associations/builder/has_one.rb +11 -14
- data/lib/active_record/associations/builder/singular_association.rb +1 -1
- data/lib/active_record/associations/collection_association.rb +25 -8
- data/lib/active_record/associations/collection_proxy.rb +14 -7
- data/lib/active_record/associations/foreign_association.rb +13 -0
- data/lib/active_record/associations/has_many_association.rb +24 -3
- data/lib/active_record/associations/has_many_through_association.rb +10 -4
- data/lib/active_record/associations/has_one_association.rb +15 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +39 -16
- data/lib/active_record/associations/join_dependency/join_part.rb +3 -3
- data/lib/active_record/associations/join_dependency.rb +77 -42
- data/lib/active_record/associations/preloader/association.rb +51 -25
- data/lib/active_record/associations/preloader/through_association.rb +2 -2
- data/lib/active_record/associations/preloader.rb +13 -8
- data/lib/active_record/associations/singular_association.rb +1 -1
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/associations.rb +120 -13
- data/lib/active_record/attribute_assignment.rb +10 -9
- data/lib/active_record/attribute_methods/before_type_cast.rb +13 -10
- data/lib/active_record/attribute_methods/dirty.rb +3 -13
- data/lib/active_record/attribute_methods/primary_key.rb +6 -4
- data/lib/active_record/attribute_methods/query.rb +3 -6
- data/lib/active_record/attribute_methods/read.rb +8 -12
- data/lib/active_record/attribute_methods/serialization.rb +11 -6
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +12 -15
- data/lib/active_record/attribute_methods/write.rb +12 -21
- data/lib/active_record/attribute_methods.rb +64 -54
- data/lib/active_record/attributes.rb +33 -9
- data/lib/active_record/autosave_association.rb +63 -44
- data/lib/active_record/base.rb +2 -14
- data/lib/active_record/callbacks.rb +153 -24
- data/lib/active_record/coders/yaml_column.rb +12 -3
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +202 -138
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +2 -44
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +87 -38
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +5 -10
- data/lib/active_record/connection_adapters/abstract/quoting.rb +34 -34
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +3 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +152 -116
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +141 -52
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +3 -3
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +267 -105
- data/lib/active_record/connection_adapters/abstract/transaction.rb +94 -36
- data/lib/active_record/connection_adapters/abstract_adapter.rb +76 -79
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +149 -115
- data/lib/active_record/connection_adapters/column.rb +15 -1
- data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
- data/lib/active_record/connection_adapters/legacy_pool_manager.rb +35 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +30 -36
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +1 -2
- data/lib/active_record/connection_adapters/mysql/quoting.rb +18 -3
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +32 -7
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +8 -0
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +5 -2
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +17 -13
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +10 -1
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +31 -13
- data/lib/active_record/connection_adapters/pool_config.rb +73 -0
- data/lib/active_record/connection_adapters/pool_manager.rb +47 -0
- data/lib/active_record/connection_adapters/postgresql/column.rb +24 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +21 -56
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -5
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +10 -2
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +2 -3
- data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
- 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 +2 -3
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +24 -6
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +11 -2
- data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +4 -4
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +7 -3
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +72 -54
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +8 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +83 -65
- data/lib/active_record/connection_adapters/schema_cache.rb +106 -15
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +8 -0
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +38 -12
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +1 -2
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +5 -1
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +38 -5
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +61 -57
- data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
- data/lib/active_record/connection_adapters.rb +52 -0
- data/lib/active_record/connection_handling.rb +219 -81
- data/lib/active_record/core.rb +268 -71
- data/lib/active_record/counter_cache.rb +4 -1
- data/lib/active_record/database_configurations/connection_url_resolver.rb +98 -0
- data/lib/active_record/database_configurations/database_config.rb +52 -9
- data/lib/active_record/database_configurations/hash_config.rb +54 -8
- data/lib/active_record/database_configurations/url_config.rb +15 -41
- data/lib/active_record/database_configurations.rb +124 -85
- data/lib/active_record/delegated_type.rb +209 -0
- data/lib/active_record/destroy_association_async_job.rb +36 -0
- data/lib/active_record/dynamic_matchers.rb +2 -3
- data/lib/active_record/enum.rb +80 -38
- data/lib/active_record/errors.rb +47 -12
- data/lib/active_record/explain.rb +9 -5
- data/lib/active_record/explain_subscriber.rb +1 -1
- data/lib/active_record/fixture_set/file.rb +10 -17
- data/lib/active_record/fixture_set/model_metadata.rb +1 -2
- data/lib/active_record/fixture_set/render_context.rb +1 -1
- data/lib/active_record/fixture_set/table_row.rb +2 -3
- data/lib/active_record/fixture_set/table_rows.rb +0 -1
- data/lib/active_record/fixtures.rb +58 -12
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/inheritance.rb +40 -21
- data/lib/active_record/insert_all.rb +43 -10
- data/lib/active_record/integration.rb +3 -5
- data/lib/active_record/internal_metadata.rb +16 -7
- data/lib/active_record/legacy_yaml_adapter.rb +7 -3
- data/lib/active_record/locking/optimistic.rb +33 -18
- data/lib/active_record/locking/pessimistic.rb +6 -2
- data/lib/active_record/log_subscriber.rb +28 -9
- data/lib/active_record/middleware/database_selector/resolver/session.rb +3 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +14 -14
- data/lib/active_record/middleware/database_selector.rb +4 -2
- data/lib/active_record/migration/command_recorder.rb +53 -45
- data/lib/active_record/migration/compatibility.rb +71 -20
- data/lib/active_record/migration/join_table.rb +0 -1
- data/lib/active_record/migration.rb +115 -85
- data/lib/active_record/model_schema.rb +120 -15
- data/lib/active_record/nested_attributes.rb +2 -5
- data/lib/active_record/no_touching.rb +1 -1
- data/lib/active_record/null_relation.rb +0 -1
- data/lib/active_record/persistence.rb +50 -46
- data/lib/active_record/query_cache.rb +15 -5
- data/lib/active_record/querying.rb +12 -7
- data/lib/active_record/railtie.rb +65 -45
- data/lib/active_record/railties/console_sandbox.rb +2 -4
- data/lib/active_record/railties/databases.rake +280 -99
- data/lib/active_record/readonly_attributes.rb +4 -0
- data/lib/active_record/reflection.rb +77 -63
- data/lib/active_record/relation/batches/batch_enumerator.rb +25 -9
- data/lib/active_record/relation/batches.rb +38 -32
- data/lib/active_record/relation/calculations.rb +106 -45
- data/lib/active_record/relation/delegation.rb +9 -7
- data/lib/active_record/relation/finder_methods.rb +55 -17
- data/lib/active_record/relation/from_clause.rb +5 -1
- data/lib/active_record/relation/merger.rb +27 -26
- data/lib/active_record/relation/predicate_builder/array_handler.rb +8 -9
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +4 -5
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +10 -6
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
- data/lib/active_record/relation/predicate_builder.rb +59 -40
- data/lib/active_record/relation/query_methods.rb +344 -181
- data/lib/active_record/relation/record_fetch_warning.rb +3 -3
- data/lib/active_record/relation/spawn_methods.rb +8 -8
- data/lib/active_record/relation/where_clause.rb +111 -62
- data/lib/active_record/relation.rb +116 -82
- data/lib/active_record/result.rb +41 -34
- data/lib/active_record/runtime_registry.rb +2 -2
- data/lib/active_record/sanitization.rb +6 -17
- data/lib/active_record/schema_dumper.rb +34 -4
- data/lib/active_record/schema_migration.rb +2 -8
- data/lib/active_record/scoping/default.rb +1 -4
- data/lib/active_record/scoping/named.rb +7 -18
- data/lib/active_record/scoping.rb +0 -1
- data/lib/active_record/secure_token.rb +16 -8
- data/lib/active_record/serialization.rb +5 -3
- data/lib/active_record/signed_id.rb +116 -0
- data/lib/active_record/statement_cache.rb +20 -4
- data/lib/active_record/store.rb +3 -3
- data/lib/active_record/suppressor.rb +2 -2
- data/lib/active_record/table_metadata.rb +42 -36
- data/lib/active_record/tasks/database_tasks.rb +140 -113
- data/lib/active_record/tasks/mysql_database_tasks.rb +34 -36
- data/lib/active_record/tasks/postgresql_database_tasks.rb +24 -27
- data/lib/active_record/tasks/sqlite_database_tasks.rb +13 -10
- data/lib/active_record/test_databases.rb +5 -4
- data/lib/active_record/test_fixtures.rb +79 -16
- data/lib/active_record/timestamp.rb +4 -7
- data/lib/active_record/touch_later.rb +20 -21
- data/lib/active_record/transactions.rb +26 -73
- data/lib/active_record/type/adapter_specific_registry.rb +2 -5
- data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
- data/lib/active_record/type/serialized.rb +6 -3
- 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 +8 -2
- data/lib/active_record/type_caster/connection.rb +0 -1
- data/lib/active_record/type_caster/map.rb +8 -5
- data/lib/active_record/validations/associated.rb +1 -2
- data/lib/active_record/validations/numericality.rb +35 -0
- data/lib/active_record/validations/uniqueness.rb +24 -4
- data/lib/active_record/validations.rb +3 -3
- data/lib/active_record.rb +7 -13
- data/lib/arel/attributes/attribute.rb +4 -0
- data/lib/arel/collectors/bind.rb +5 -0
- data/lib/arel/collectors/composite.rb +8 -0
- data/lib/arel/collectors/sql_string.rb +7 -0
- data/lib/arel/collectors/substitute_binds.rb +7 -0
- data/lib/arel/nodes/binary.rb +82 -8
- data/lib/arel/nodes/bind_param.rb +8 -0
- data/lib/arel/nodes/casted.rb +21 -9
- data/lib/arel/nodes/equality.rb +6 -9
- data/lib/arel/nodes/grouping.rb +3 -0
- data/lib/arel/nodes/homogeneous_in.rb +76 -0
- data/lib/arel/nodes/in.rb +8 -1
- data/lib/arel/nodes/infix_operation.rb +13 -1
- data/lib/arel/nodes/join_source.rb +1 -1
- data/lib/arel/nodes/node.rb +7 -6
- data/lib/arel/nodes/ordering.rb +27 -0
- data/lib/arel/nodes/sql_literal.rb +3 -0
- data/lib/arel/nodes/table_alias.rb +7 -3
- data/lib/arel/nodes/unary.rb +0 -1
- data/lib/arel/nodes.rb +3 -1
- data/lib/arel/predications.rb +17 -24
- data/lib/arel/select_manager.rb +1 -2
- data/lib/arel/table.rb +13 -5
- data/lib/arel/visitors/dot.rb +14 -3
- data/lib/arel/visitors/mysql.rb +11 -1
- data/lib/arel/visitors/postgresql.rb +15 -5
- data/lib/arel/visitors/sqlite.rb +0 -1
- data/lib/arel/visitors/to_sql.rb +89 -79
- data/lib/arel/visitors/visitor.rb +0 -1
- data/lib/arel/visitors.rb +0 -7
- data/lib/arel.rb +15 -12
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
- data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -0
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +2 -0
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -4
- data/lib/rails/generators/active_record/migration.rb +6 -2
- data/lib/rails/generators/active_record/model/model_generator.rb +38 -2
- data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +7 -0
- metadata +27 -24
- data/lib/active_record/attribute_decorators.rb +0 -90
- data/lib/active_record/connection_adapters/connection_specification.rb +0 -297
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -29
- data/lib/active_record/define_callbacks.rb +0 -22
- data/lib/active_record/railties/collection_cache_association_loading.rb +0 -34
- data/lib/active_record/relation/predicate_builder/base_handler.rb +0 -18
- data/lib/active_record/relation/where_clause_factory.rb +0 -33
- data/lib/arel/attributes.rb +0 -22
- data/lib/arel/visitors/depth_first.rb +0 -204
- data/lib/arel/visitors/ibm_db.rb +0 -34
- data/lib/arel/visitors/informix.rb +0 -62
- data/lib/arel/visitors/mssql.rb +0 -157
- data/lib/arel/visitors/oracle.rb +0 -159
- data/lib/arel/visitors/oracle12.rb +0 -66
- data/lib/arel/visitors/where_sql.rb +0 -23
data/CHANGELOG.md
CHANGED
@@ -1,1013 +1,1591 @@
|
|
1
|
-
## Rails 6.
|
1
|
+
## Rails 6.1.4 (June 24, 2021) ##
|
2
2
|
|
3
|
-
*
|
4
|
-
|
5
|
-
Fixes #36761, #34328, #24281, #12953.
|
6
|
-
|
7
|
-
*Ryuta Kamizono*
|
3
|
+
* Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError`.
|
8
4
|
|
9
|
-
*
|
5
|
+
*Jamie McCarthy*
|
10
6
|
|
11
|
-
|
7
|
+
* Raise an error if `pool_config` is `nil` in `set_pool_config`.
|
12
8
|
|
13
|
-
*
|
9
|
+
*Eileen M. Uchitelle*
|
14
10
|
|
15
|
-
|
16
|
-
enum status: [:sent, :not_sent]
|
17
|
-
end
|
11
|
+
* Fix compatibility with `psych >= 4`.
|
18
12
|
|
19
|
-
|
13
|
+
Starting in Psych 4.0.0 `YAML.load` behaves like `YAML.safe_load`. To preserve compatibility
|
14
|
+
Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
|
20
15
|
|
21
|
-
*
|
16
|
+
*Jean Boussier*
|
22
17
|
|
23
|
-
|
18
|
+
* Support using replicas when using `rails dbconsole`.
|
24
19
|
|
20
|
+
*Christopher Thornton*
|
25
21
|
|
26
|
-
|
22
|
+
* Restore connection pools after transactional tests.
|
27
23
|
|
28
|
-
*
|
24
|
+
*Eugene Kenny*
|
29
25
|
|
30
|
-
|
26
|
+
* Change `upsert_all` to fails cleanly for MySQL when `:unique_by` is used.
|
31
27
|
|
32
|
-
*
|
28
|
+
*Bastian Bartmann*
|
33
29
|
|
34
|
-
|
30
|
+
* Fix user-defined `self.default_scope` to respect table alias.
|
35
31
|
|
36
32
|
*Ryuta Kamizono*
|
37
33
|
|
38
|
-
*
|
39
|
-
|
40
|
-
Fixes #36465.
|
41
|
-
|
42
|
-
*Jeff Doering*
|
43
|
-
|
44
|
-
* Fix sqlite3 collation parsing when using decimal columns.
|
45
|
-
|
46
|
-
*Martin R. Schuster*
|
47
|
-
|
48
|
-
* Fix invalid schema when primary key column has a comment.
|
49
|
-
|
50
|
-
Fixes #29966.
|
51
|
-
|
52
|
-
*Guilherme Goettems Schneider*
|
34
|
+
* Clear `@cache_keys` cache after `update_all`, `delete_all`, `destroy_all`.
|
53
35
|
|
54
|
-
*
|
36
|
+
*Ryuta Kamizono*
|
55
37
|
|
56
|
-
|
38
|
+
* Changed Arel predications `contains` and `overlaps` to use
|
39
|
+
`quoted_node` so that PostgreSQL arrays are quoted properly.
|
57
40
|
|
58
|
-
*
|
41
|
+
*Bradley Priest*
|
59
42
|
|
60
|
-
|
43
|
+
* Fix `merge` when the `where` clauses have string contents.
|
61
44
|
|
62
45
|
*Ryuta Kamizono*
|
63
46
|
|
47
|
+
* Fix rollback of parent destruction with nested `dependent: :destroy`.
|
64
48
|
|
65
|
-
|
66
|
-
|
67
|
-
* Add `touch` option to `has_one` association.
|
49
|
+
*Jacopo Beschi*
|
68
50
|
|
69
|
-
|
70
|
-
|
71
|
-
* Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
|
72
|
-
|
73
|
-
```ruby
|
74
|
-
all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
|
75
|
-
assert_equal all, PriceEstimate.all.map(&:estimate_of)
|
76
|
-
```
|
51
|
+
* Fix binds logging for `"WHERE ... IN ..."` statements.
|
77
52
|
|
78
|
-
|
53
|
+
*Ricardo Díaz*
|
79
54
|
|
80
|
-
|
81
|
-
sapphire = treasures(:sapphire)
|
55
|
+
* Handle `false` in relation strict loading checks.
|
82
56
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
e.estimate_of_id == sapphire.id
|
87
|
-
}
|
88
|
-
assert_equal [cars(:honda)], nor
|
57
|
+
Previously when a model had strict loading set to true and then had a
|
58
|
+
relation set `strict_loading` to false the false wasn't considered when
|
59
|
+
deciding whether to raise/warn about strict loading.
|
89
60
|
|
90
|
-
without_sapphire = PriceEstimate.where.not(
|
91
|
-
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
92
|
-
)
|
93
|
-
assert_equal nor, without_sapphire.map(&:estimate_of)
|
94
61
|
```
|
62
|
+
class Dog < ActiveRecord::Base
|
63
|
+
self.strict_loading_by_default = true
|
95
64
|
|
96
|
-
|
65
|
+
has_many :treats, strict_loading: false
|
66
|
+
end
|
67
|
+
```
|
97
68
|
|
98
|
-
|
99
|
-
|
69
|
+
In the example, `dog.treats` would still raise even though
|
70
|
+
`strict_loading` was set to false. This is a bug effecting more than
|
71
|
+
Active Storage which is why I made this PR superceeding #41461. We need
|
72
|
+
to fix this for all applications since the behavior is a little
|
73
|
+
surprising. I took the test from ##41461 and the code suggestion from #41453
|
74
|
+
with some additions.
|
100
75
|
|
101
|
-
|
102
|
-
assert_equal [treasures(:diamond), cars(:honda)], nand
|
76
|
+
*Eileen M. Uchitelle*, *Radamés Roriz*
|
103
77
|
|
104
|
-
|
105
|
-
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
106
|
-
)
|
107
|
-
assert_equal nand, without_sapphire.map(&:estimate_of)
|
108
|
-
```
|
78
|
+
* Fix numericality validator without precision.
|
109
79
|
|
110
80
|
*Ryuta Kamizono*
|
111
81
|
|
112
|
-
* Fix
|
113
|
-
|
114
|
-
Fixes #15018, #30167, #33868.
|
82
|
+
* Fix aggregate attribute on Enum types.
|
115
83
|
|
116
84
|
*Ryuta Kamizono*
|
117
85
|
|
118
|
-
*
|
119
|
-
the versioned entries in `ActiveSupport::Cache`. This also means that
|
120
|
-
`ActiveRecord::Relation#cache_key` will now return a stable key that does not
|
121
|
-
include the max timestamp or count any more.
|
86
|
+
* Fix `CREATE INDEX` statement generation for PostgreSQL.
|
122
87
|
|
123
|
-
|
124
|
-
cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
|
125
|
-
That's the setting for all new apps on Rails 6.0+
|
88
|
+
*eltongo*
|
126
89
|
|
127
|
-
|
90
|
+
* Fix where clause on enum attribute when providing array of strings.
|
128
91
|
|
129
|
-
*
|
130
|
-
|
131
|
-
Fixes #33429.
|
92
|
+
*Ryuta Kamizono*
|
132
93
|
|
133
|
-
|
94
|
+
* Fix `unprepared_statement` to work it when nesting.
|
134
95
|
|
135
|
-
*
|
136
|
-
`to` and `from` options are specified.
|
96
|
+
*Ryuta Kamizono*
|
137
97
|
|
138
|
-
*Yoshiyuki Kinjo*
|
139
98
|
|
140
|
-
|
99
|
+
## Rails 6.1.3.2 (May 05, 2021) ##
|
141
100
|
|
142
|
-
|
101
|
+
* No changes.
|
143
102
|
|
144
|
-
*Ryuta Kamizono*
|
145
103
|
|
146
|
-
|
104
|
+
## Rails 6.1.3.1 (March 26, 2021) ##
|
147
105
|
|
148
|
-
|
149
|
-
associations, the callback for a `has_many` association was run while
|
150
|
-
another instance of the same callback on the same association hadn't
|
151
|
-
finished running. When control returned to the first instance of the
|
152
|
-
callback, the instance variable had changed, and subsequent associated
|
153
|
-
records weren't saved correctly. Specifically, the ID field for the
|
154
|
-
`belongs_to` corresponding to the `has_many` was `nil`.
|
106
|
+
* No changes.
|
155
107
|
|
156
|
-
Fixes #28080.
|
157
108
|
|
158
|
-
|
109
|
+
## Rails 6.1.3 (February 17, 2021) ##
|
159
110
|
|
160
|
-
*
|
111
|
+
* Fix the MySQL adapter to always set the right collation and charset
|
112
|
+
to the connection session.
|
161
113
|
|
162
|
-
|
114
|
+
*Rafael Mendonça França*
|
163
115
|
|
164
|
-
|
165
|
-
|
166
|
-
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
167
|
-
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
|
168
|
-
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
|
169
|
-
```
|
116
|
+
* Fix MySQL adapter handling of time objects when prepared statements
|
117
|
+
are enabled.
|
170
118
|
|
171
|
-
|
119
|
+
*Rafael Mendonça França*
|
172
120
|
|
173
|
-
|
174
|
-
|
175
|
-
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
176
|
-
add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
|
177
|
-
add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
|
178
|
-
```
|
121
|
+
* Fix scoping in enum fields using conditions that would generate
|
122
|
+
an `IN` clause.
|
179
123
|
|
180
124
|
*Ryuta Kamizono*
|
181
125
|
|
182
|
-
*
|
183
|
-
|
126
|
+
* Skip optimised #exist? query when #include? is called on a relation
|
127
|
+
with a having clause
|
184
128
|
|
185
|
-
|
129
|
+
Relations that have aliased select values AND a having clause that
|
130
|
+
references an aliased select value would generate an error when
|
131
|
+
#include? was called, due to an optimisation that would generate
|
132
|
+
call #exists? on the relation instead, which effectively alters
|
133
|
+
the select values of the query (and thus removes the aliased select
|
134
|
+
values), but leaves the having clause intact. Because the having
|
135
|
+
clause is then referencing an aliased column that is no longer
|
136
|
+
present in the simplified query, an ActiveRecord::InvalidStatement
|
137
|
+
error was raised.
|
138
|
+
|
139
|
+
An sample query affected by this problem:
|
186
140
|
|
187
141
|
```ruby
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
142
|
+
Author.select('COUNT(*) as total_posts', 'authors.*')
|
143
|
+
.joins(:posts)
|
144
|
+
.group(:id)
|
145
|
+
.having('total_posts > 2')
|
146
|
+
.include?(Author.first)
|
193
147
|
```
|
194
148
|
|
195
|
-
|
149
|
+
This change adds an addition check to the condition that skips the
|
150
|
+
simplified #exists? query, which simply checks for the presence of
|
151
|
+
a having clause.
|
196
152
|
|
197
|
-
|
198
|
-
Post.where("1=0").scoping do
|
199
|
-
Comment.find(1).post # => #<Post id: 1, ...>
|
200
|
-
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
201
|
-
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
202
|
-
end
|
203
|
-
```
|
153
|
+
Fixes #41417
|
204
154
|
|
205
|
-
|
155
|
+
*Michael Smart*
|
206
156
|
|
207
|
-
|
157
|
+
* Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
|
158
|
+
without Rails knowledge (e.g., if app gets kill -9d during long-running query or due to Rack::Timeout), app won't end
|
159
|
+
up in perpetual crash state for being inconsistent with Postgres.
|
208
160
|
|
209
|
-
*
|
161
|
+
*wbharding*, *Martin Tepper*
|
210
162
|
|
211
|
-
Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
|
212
163
|
|
213
|
-
|
164
|
+
## Rails 6.1.2.1 (February 10, 2021) ##
|
214
165
|
|
215
|
-
*
|
166
|
+
* Fix possible DoS vector in PostgreSQL money type
|
216
167
|
|
217
|
-
|
168
|
+
Carefully crafted input can cause a DoS via the regular expressions used
|
169
|
+
for validating the money format in the PostgreSQL adapter. This patch
|
170
|
+
fixes the regexp.
|
218
171
|
|
219
|
-
|
220
|
-
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
172
|
+
Thanks to @dee-see from Hackerone for this patch!
|
221
173
|
|
222
|
-
|
174
|
+
[CVE-2021-22880]
|
223
175
|
|
224
|
-
*
|
176
|
+
*Aaron Patterson*
|
225
177
|
|
226
|
-
* Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
|
227
178
|
|
228
|
-
|
229
|
-
account.memberships.extract_associated(:user)
|
230
|
-
# => Returns collection of User records
|
231
|
-
```
|
179
|
+
## Rails 6.1.2 (February 09, 2021) ##
|
232
180
|
|
233
|
-
|
181
|
+
* Fix timestamp type for sqlite3.
|
234
182
|
|
235
|
-
*
|
183
|
+
*Eileen M. Uchitelle*
|
236
184
|
|
237
|
-
|
185
|
+
* Make destroy async transactional.
|
238
186
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
```
|
187
|
+
An active record rollback could occur while enqueuing a job. In this
|
188
|
+
case the job would enqueue even though the database deletion
|
189
|
+
rolledback putting things in a funky state.
|
243
190
|
|
244
|
-
|
191
|
+
Now the jobs are only enqueued until after the db transaction has been committed.
|
245
192
|
|
246
|
-
*
|
193
|
+
*Cory Gwin*
|
247
194
|
|
248
|
-
*
|
195
|
+
* Fix malformed packet error in MySQL statement for connection configuration.
|
249
196
|
|
250
|
-
|
251
|
-
which can be specified within individual statements.
|
197
|
+
*robinroestenburg*
|
252
198
|
|
253
|
-
|
199
|
+
* Connection specification now passes the "url" key as a configuration for the
|
200
|
+
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
|
201
|
+
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
|
202
|
+
are assumed to be adapter specification urls.
|
254
203
|
|
255
|
-
|
256
|
-
# SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
|
204
|
+
Fixes #41137.
|
257
205
|
|
258
|
-
|
206
|
+
*Jonathan Bracy*
|
259
207
|
|
260
|
-
|
261
|
-
# SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
|
208
|
+
* Fix granular connection swapping when there are multiple abstract classes.
|
262
209
|
|
263
|
-
|
210
|
+
*Eileen M. Uchitelle*
|
264
211
|
|
265
|
-
|
266
|
-
* https://pghintplan.osdn.jp/pg_hint_plan.html
|
267
|
-
* https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
|
268
|
-
* https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
|
269
|
-
* https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
|
212
|
+
* Fix `find_by` with custom primary key for belongs_to association.
|
270
213
|
|
271
214
|
*Ryuta Kamizono*
|
272
215
|
|
273
|
-
*
|
216
|
+
* Add support for `rails console --sandbox` for multiple database applications.
|
274
217
|
|
275
|
-
|
276
|
-
|
277
|
-
```
|
278
|
-
class Post < ActiveRecord::Base
|
279
|
-
attribute :user_defined_text, :text
|
280
|
-
end
|
218
|
+
*alpaca-tc*
|
281
219
|
|
282
|
-
|
283
|
-
```
|
220
|
+
* Fix `where` on polymorphic association with empty array.
|
284
221
|
|
285
|
-
*
|
222
|
+
*Ryuta Kamizono*
|
286
223
|
|
287
|
-
*
|
224
|
+
* Fix preventing writes for `ApplicationRecord`.
|
288
225
|
|
289
|
-
*
|
226
|
+
*Eileen M. Uchitelle*
|
290
227
|
|
291
|
-
* Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
|
292
|
-
allowing bulk inserts akin to the bulk updates provided by `update_all` and
|
293
|
-
bulk deletes by `delete_all`.
|
294
228
|
|
295
|
-
|
296
|
-
for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
|
297
|
-
for MySQL.
|
229
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
298
230
|
|
299
|
-
|
231
|
+
* Fix fixtures loading when strict loading is enabled for the association.
|
300
232
|
|
301
|
-
*
|
302
|
-
for current environment and loads the seeds.
|
233
|
+
*Alex Ghiculescu*
|
303
234
|
|
304
|
-
|
235
|
+
* Fix `where` with custom primary key for belongs_to association.
|
305
236
|
|
306
|
-
*
|
237
|
+
*Ryuta Kamizono*
|
307
238
|
|
308
|
-
|
239
|
+
* Fix `where` with aliased associations.
|
309
240
|
|
310
|
-
*
|
241
|
+
*Ryuta Kamizono*
|
311
242
|
|
312
|
-
|
313
|
-
To continue case sensitive comparison on the case insensitive column,
|
314
|
-
pass `case_sensitive: true` option explicitly to the uniqueness validator.
|
243
|
+
* Fix `composed_of` with symbol mapping.
|
315
244
|
|
316
245
|
*Ryuta Kamizono*
|
317
246
|
|
318
|
-
*
|
247
|
+
* Don't skip money's type cast for pluck and calculations.
|
319
248
|
|
320
|
-
|
249
|
+
*Ryuta Kamizono*
|
321
250
|
|
322
|
-
|
251
|
+
* Fix `where` on polymorphic association with non Active Record object.
|
323
252
|
|
324
|
-
*
|
253
|
+
*Ryuta Kamizono*
|
325
254
|
|
326
|
-
|
255
|
+
* Make sure `db:prepare` works even the schema file doesn't exist.
|
327
256
|
|
328
|
-
|
329
|
-
enum status: %i[ drafted active trashed ]
|
330
|
-
end
|
257
|
+
*Rafael Mendonça França*
|
331
258
|
|
332
|
-
|
333
|
-
Post.not_active # => where.not(status: :active)
|
334
|
-
Post.not_trashed # => where.not(status: :trashed)
|
259
|
+
* Fix complicated `has_many :through` with nested where condition.
|
335
260
|
|
336
|
-
*
|
261
|
+
*Ryuta Kamizono*
|
337
262
|
|
338
|
-
*
|
263
|
+
* Handle STI models for `has_many dependent: :destroy_async`.
|
339
264
|
|
340
|
-
|
265
|
+
*Muhammad Usman*
|
341
266
|
|
342
|
-
|
267
|
+
* Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
|
343
268
|
|
269
|
+
Previously, passing `false` would trigger the option validation logic
|
270
|
+
to throw an error saying :polymorphic would not be a valid option.
|
344
271
|
|
345
|
-
|
272
|
+
*glaszig*
|
346
273
|
|
347
|
-
*
|
274
|
+
* Allow adding nonnamed expression indexes to be revertible.
|
348
275
|
|
276
|
+
Fixes #40732.
|
349
277
|
|
350
|
-
|
278
|
+
Previously, the following code would raise an error, when executed while rolling back,
|
279
|
+
and the index name should be specified explicitly. Now, the index name is inferred
|
280
|
+
automatically.
|
351
281
|
|
352
|
-
|
282
|
+
```ruby
|
283
|
+
add_index(:items, "to_tsvector('english', description)")
|
284
|
+
```
|
353
285
|
|
354
|
-
*
|
286
|
+
*fatkodima*
|
355
287
|
|
356
|
-
* Ensure `update_all` series cares about optimistic locking.
|
357
288
|
|
358
|
-
|
289
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
359
290
|
|
360
|
-
*
|
291
|
+
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
361
292
|
|
362
|
-
|
293
|
+
Fixes #39065.
|
363
294
|
|
364
|
-
*
|
295
|
+
*Alex Ghiculescu*
|
365
296
|
|
366
|
-
|
367
|
-
`destroy_all` on the matched records.
|
297
|
+
* Change `attribute_for_inspect` to take `filter_attributes` in consideration.
|
368
298
|
|
369
|
-
|
299
|
+
*Rafael Mendonça França*
|
370
300
|
|
371
|
-
|
372
|
-
Person.destroy_by(name: 'David', rating: 4)
|
301
|
+
* Fix odd behavior of inverse_of with multiple belongs_to to same class.
|
373
302
|
|
374
|
-
|
375
|
-
david.posts.destroy_by(id: [1, 2, 3])
|
303
|
+
Fixes #35204.
|
376
304
|
|
377
|
-
|
378
|
-
`delete_all` on the matched records.
|
305
|
+
*Tomoyuki Kai*
|
379
306
|
|
380
|
-
|
307
|
+
* Build predicate conditions with objects that delegate `#id` and primary key:
|
381
308
|
|
382
|
-
|
383
|
-
|
309
|
+
```ruby
|
310
|
+
class AdminAuthor
|
311
|
+
delegate_missing_to :@author
|
384
312
|
|
385
|
-
|
386
|
-
|
313
|
+
def initialize(author)
|
314
|
+
@author = author
|
315
|
+
end
|
316
|
+
end
|
387
317
|
|
388
|
-
|
318
|
+
Post.where(author: AdminAuthor.new(author))
|
319
|
+
```
|
389
320
|
|
390
|
-
*
|
321
|
+
*Sean Doyle*
|
391
322
|
|
392
|
-
|
323
|
+
* Add `connected_to_many` API.
|
393
324
|
|
394
|
-
|
325
|
+
This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
|
395
326
|
|
396
|
-
|
327
|
+
Before:
|
397
328
|
|
398
|
-
|
329
|
+
AnimalsRecord.connected_to(role: :reading) do
|
330
|
+
MealsRecord.connected_to(role: :reading) do
|
331
|
+
Dog.first # read from animals replica
|
332
|
+
Dinner.first # read from meals replica
|
333
|
+
Person.first # read from primary writer
|
334
|
+
end
|
335
|
+
end
|
399
336
|
|
400
|
-
|
401
|
-
regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
|
337
|
+
After:
|
402
338
|
|
403
|
-
|
339
|
+
ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
|
340
|
+
Dog.first # read from animals replica
|
341
|
+
Dinner.first # read from meals replica
|
342
|
+
Person.first # read from primary writer
|
343
|
+
end
|
404
344
|
|
405
|
-
*
|
345
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
406
346
|
|
407
|
-
|
408
|
-
application to automatically switch between the writing and reading
|
409
|
-
database connections.
|
347
|
+
* Add option to raise or log for `ActiveRecord::StrictLoadingViolationError`.
|
410
348
|
|
411
|
-
|
412
|
-
a write in the last 2 seconds, otherwise they will read from the primary.
|
413
|
-
Non-get requests will always write to the primary. The middleware accepts
|
414
|
-
an argument for a Resolver class and an Operations class where you are able
|
415
|
-
to change how the auto-switcher works to be most beneficial for your
|
416
|
-
application.
|
349
|
+
Some applications may not want to raise an error in production if using `strict_loading`. This would allow an application to set strict loading to log for the production environment while still raising in development and test environments.
|
417
350
|
|
418
|
-
|
419
|
-
configuration options:
|
351
|
+
Set `config.active_record.action_on_strict_loading_violation` to `:log` errors instead of raising.
|
420
352
|
|
421
|
-
|
422
|
-
config.active_record.database_selector = { delay: 2.seconds }
|
423
|
-
config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
|
424
|
-
config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
|
425
|
-
```
|
353
|
+
*Eileen M. Uchitelle*
|
426
354
|
|
427
|
-
|
428
|
-
configuration options:
|
355
|
+
* Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
|
429
356
|
|
430
|
-
|
431
|
-
config.active_record.database_selector = { delay: 10.seconds }
|
432
|
-
config.active_record.database_resolver = MyResolver
|
433
|
-
config.active_record.database_resolver_context = MyResolver::MyCookies
|
434
|
-
```
|
357
|
+
Fixes #34255.
|
435
358
|
|
436
|
-
*
|
359
|
+
*Steven Weber*
|
437
360
|
|
438
|
-
*
|
361
|
+
* Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
|
439
362
|
|
440
|
-
|
363
|
+
Because the default behaviour when adding an index with multiple columns is to use all column names in the index name, this could frequently lead to overly long index names for polymorphic references which would fail the migration if it exceeded the database limit.
|
441
364
|
|
442
|
-
|
365
|
+
This change reduces the chance of that happening by using the reference name, e.g. `index_my_table_on_my_reference`.
|
443
366
|
|
444
|
-
|
367
|
+
Fixes #38655.
|
445
368
|
|
369
|
+
*Luke Redpath*
|
446
370
|
|
447
|
-
|
371
|
+
* MySQL: Uniqueness validator now respects default database collation,
|
372
|
+
no longer enforce case sensitive comparison by default.
|
448
373
|
|
449
|
-
*
|
374
|
+
*Ryuta Kamizono*
|
450
375
|
|
451
|
-
|
376
|
+
* Remove deprecated methods from `ActiveRecord::ConnectionAdapters::DatabaseLimits`.
|
452
377
|
|
453
|
-
|
378
|
+
`column_name_length`
|
379
|
+
`table_name_length`
|
380
|
+
`columns_per_table`
|
381
|
+
`indexes_per_table`
|
382
|
+
`columns_per_multicolumn_index`
|
383
|
+
`sql_query_length`
|
384
|
+
`joins_per_query`
|
454
385
|
|
455
386
|
*Rafael Mendonça França*
|
456
387
|
|
457
|
-
* Remove deprecated
|
388
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?`.
|
458
389
|
|
459
390
|
*Rafael Mendonça França*
|
460
391
|
|
461
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::
|
392
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?`.
|
462
393
|
|
463
394
|
*Rafael Mendonça França*
|
464
395
|
|
465
|
-
*
|
396
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?`.
|
466
397
|
|
467
398
|
*Rafael Mendonça França*
|
468
399
|
|
469
|
-
*
|
400
|
+
* Remove deprecated `ActiveRecord::Base#update_attributes` and `ActiveRecord::Base#update_attributes!`.
|
470
401
|
|
471
402
|
*Rafael Mendonça França*
|
472
403
|
|
473
|
-
* Remove
|
404
|
+
* Remove deprecated `migrations_path` argument in `ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version`.
|
474
405
|
|
475
406
|
*Rafael Mendonça França*
|
476
407
|
|
477
|
-
* Remove
|
408
|
+
* Remove deprecated `config.active_record.sqlite3.represent_boolean_as_integer`.
|
478
409
|
|
479
410
|
*Rafael Mendonça França*
|
480
411
|
|
481
|
-
*
|
412
|
+
* `relation.create` does no longer leak scope to class level querying methods
|
413
|
+
in initialization block and callbacks.
|
482
414
|
|
483
|
-
|
415
|
+
Before:
|
484
416
|
|
485
|
-
|
417
|
+
User.where(name: "John").create do |john|
|
418
|
+
User.find_by(name: "David") # => nil
|
419
|
+
end
|
486
420
|
|
487
|
-
|
421
|
+
After:
|
488
422
|
|
489
|
-
|
423
|
+
User.where(name: "John").create do |john|
|
424
|
+
User.find_by(name: "David") # => #<User name: "David", ...>
|
425
|
+
end
|
490
426
|
|
491
|
-
*
|
427
|
+
*Ryuta Kamizono*
|
492
428
|
|
493
|
-
*
|
429
|
+
* Named scope chain does no longer leak scope to class level querying methods.
|
494
430
|
|
495
|
-
|
431
|
+
class User < ActiveRecord::Base
|
432
|
+
scope :david, -> { User.where(name: "David") }
|
433
|
+
end
|
496
434
|
|
497
|
-
|
435
|
+
Before:
|
498
436
|
|
499
|
-
|
437
|
+
User.where(name: "John").david
|
438
|
+
# SELECT * FROM users WHERE name = 'John' AND name = 'David'
|
500
439
|
|
501
|
-
|
440
|
+
After:
|
502
441
|
|
503
|
-
|
442
|
+
User.where(name: "John").david
|
443
|
+
# SELECT * FROM users WHERE name = 'David'
|
504
444
|
|
505
|
-
*
|
445
|
+
*Ryuta Kamizono*
|
506
446
|
|
507
|
-
*
|
447
|
+
* Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`.
|
508
448
|
|
509
|
-
|
449
|
+
`fetch`
|
450
|
+
`each`
|
451
|
+
`first`
|
452
|
+
`values`
|
453
|
+
`[]=`
|
510
454
|
|
511
|
-
*
|
455
|
+
*Rafael Mendonça França*
|
512
456
|
|
513
|
-
|
457
|
+
* `where.not` now generates NAND predicates instead of NOR.
|
514
458
|
|
515
|
-
|
459
|
+
Before:
|
516
460
|
|
517
|
-
|
461
|
+
User.where.not(name: "Jon", role: "admin")
|
462
|
+
# SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
|
518
463
|
|
519
|
-
|
464
|
+
After:
|
520
465
|
|
521
|
-
|
522
|
-
|
523
|
-
The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
|
466
|
+
User.where.not(name: "Jon", role: "admin")
|
467
|
+
# SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
|
524
468
|
|
525
|
-
*
|
469
|
+
*Rafael Mendonça França*
|
526
470
|
|
527
|
-
*
|
471
|
+
* Remove deprecated `ActiveRecord::Result#to_hash` method.
|
528
472
|
|
529
|
-
*
|
473
|
+
*Rafael Mendonça França*
|
530
474
|
|
531
|
-
*
|
475
|
+
* Deprecate `ActiveRecord::Base.allow_unsafe_raw_sql`.
|
532
476
|
|
533
|
-
*
|
477
|
+
*Rafael Mendonça França*
|
534
478
|
|
535
|
-
*
|
479
|
+
* Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.
|
536
480
|
|
537
|
-
*
|
481
|
+
*Rafael Mendonça França*
|
538
482
|
|
539
|
-
*
|
483
|
+
* Allow users to silence the "Rails couldn't infer whether you are using multiple databases..."
|
484
|
+
message using `config.active_record.suppress_multiple_database_warning`.
|
540
485
|
|
541
|
-
*
|
486
|
+
*Omri Gabay*
|
542
487
|
|
543
|
-
*
|
488
|
+
* Connections can be granularly switched for abstract classes when `connected_to` is called.
|
544
489
|
|
545
|
-
|
546
|
-
you're building out multiple databases and want to make sure you're not sending
|
547
|
-
writes when you want a read.
|
490
|
+
This change allows `connected_to` to switch a `role` and/or `shard` for a single abstract class instead of all classes globally. Applications that want to use the new feature need to set `config.active_record.legacy_connection_handling` to `false` in their application configuration.
|
548
491
|
|
549
|
-
|
550
|
-
query the database will raise an exception regardless of whether the database
|
551
|
-
user is able to write.
|
492
|
+
Example usage:
|
552
493
|
|
553
|
-
|
554
|
-
read-only queries without opening a second connection. One purpose of this is to
|
555
|
-
catch accidental writes, not all writes.
|
494
|
+
Given an application we have a `User` model that inherits from `ApplicationRecord` and a `Dog` model that inherits from `AnimalsRecord`. `AnimalsRecord` and `ApplicationRecord` have writing and reading connections as well as shard `default`, `one`, and `two`.
|
556
495
|
|
557
|
-
|
496
|
+
```ruby
|
497
|
+
ActiveRecord::Base.connected_to(role: :reading) do
|
498
|
+
User.first # reads from default replica
|
499
|
+
Dog.first # reads from default replica
|
558
500
|
|
559
|
-
|
501
|
+
AnimalsRecord.connected_to(role: :writing, shard: :one) do
|
502
|
+
User.first # reads from default replica
|
503
|
+
Dog.first # reads from shard one primary
|
504
|
+
end
|
560
505
|
|
561
|
-
|
506
|
+
User.first # reads from default replica
|
507
|
+
Dog.first # reads from default replica
|
562
508
|
|
563
|
-
|
509
|
+
ApplicationRecord.connected_to(role: :writing, shard: :two) do
|
510
|
+
User.first # reads from shard two primary
|
511
|
+
Dog.first # reads from default replica
|
512
|
+
end
|
513
|
+
end
|
514
|
+
```
|
564
515
|
|
565
|
-
|
516
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
566
517
|
|
567
|
-
|
518
|
+
* Allow double-dash comment syntax when querying read-only databases
|
568
519
|
|
569
|
-
*
|
520
|
+
*James Adam*
|
570
521
|
|
571
|
-
|
572
|
-
|
522
|
+
* Add `values_at` method.
|
523
|
+
|
524
|
+
Returns an array containing the values associated with the given methods.
|
573
525
|
|
574
526
|
```ruby
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
end
|
527
|
+
topic = Topic.first
|
528
|
+
topic.values_at(:title, :author_name)
|
529
|
+
# => ["Budget", "Jason"]
|
530
|
+
```
|
580
531
|
|
581
|
-
|
582
|
-
self.table_name = "developers"
|
532
|
+
Similar to `Hash#values_at` but on an Active Record instance.
|
583
533
|
|
584
|
-
|
534
|
+
*Guillaume Briday*
|
585
535
|
|
586
|
-
|
587
|
-
|
536
|
+
* Fix `read_attribute_before_type_cast` to consider attribute aliases.
|
537
|
+
|
538
|
+
*Marcelo Lauxen*
|
588
539
|
|
589
|
-
|
590
|
-
developer.update_column :name, "name"
|
540
|
+
* Support passing record to uniqueness validator `:conditions` callable:
|
591
541
|
|
592
|
-
|
593
|
-
|
542
|
+
```ruby
|
543
|
+
class Article < ApplicationRecord
|
544
|
+
validates_uniqueness_of :title, conditions: ->(article) {
|
545
|
+
published_at = article.published_at
|
546
|
+
where(published_at: published_at.beginning_of_year..published_at.end_of_year)
|
547
|
+
}
|
548
|
+
end
|
594
549
|
```
|
595
550
|
|
596
|
-
*
|
551
|
+
*Eliot Sykes*
|
597
552
|
|
598
|
-
*
|
553
|
+
* `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
|
554
|
+
total number of rows affected, just like their non-batched counterparts.
|
599
555
|
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
makes it possible to override the column used for implicit ordering such
|
605
|
-
that `first` and `last` will return more predictable results.
|
556
|
+
```ruby
|
557
|
+
Person.in_batches.update_all("first_name = 'Eugene'") # => 42
|
558
|
+
Person.in_batches.delete_all # => 42
|
559
|
+
```
|
606
560
|
|
607
|
-
|
561
|
+
Fixes #40287.
|
608
562
|
|
609
|
-
|
610
|
-
self.implicit_order_column = "created_at"
|
611
|
-
end
|
563
|
+
*Eugene Kenny*
|
612
564
|
|
613
|
-
|
565
|
+
* Add support for PostgreSQL `interval` data type with conversion to
|
566
|
+
`ActiveSupport::Duration` when loading records from database and
|
567
|
+
serialization to ISO 8601 formatted duration string on save.
|
568
|
+
Add support to define a column in migrations and get it in a schema dump.
|
569
|
+
Optional column precision is supported.
|
614
570
|
|
615
|
-
|
571
|
+
To use this in 6.1, you need to place the next string to your model file:
|
616
572
|
|
617
|
-
|
573
|
+
attribute :duration, :interval
|
618
574
|
|
619
|
-
|
575
|
+
To keep old behavior until 6.2 is released:
|
620
576
|
|
621
|
-
|
577
|
+
attribute :duration, :string
|
622
578
|
|
623
|
-
|
579
|
+
Example:
|
624
580
|
|
625
|
-
|
581
|
+
create_table :events do |t|
|
582
|
+
t.string :name
|
583
|
+
t.interval :duration
|
584
|
+
end
|
626
585
|
|
627
|
-
|
586
|
+
class Event < ApplicationRecord
|
587
|
+
attribute :duration, :interval
|
588
|
+
end
|
628
589
|
|
629
|
-
|
590
|
+
Event.create!(name: 'Rock Fest', duration: 2.days)
|
591
|
+
Event.last.duration # => 2 days
|
592
|
+
Event.last.duration.iso8601 # => "P2D"
|
593
|
+
Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
|
594
|
+
Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
|
630
595
|
|
631
|
-
|
596
|
+
*Andrey Novikov*
|
632
597
|
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
598
|
+
* Allow associations supporting the `dependent:` key to take `dependent: :destroy_async`.
|
599
|
+
|
600
|
+
```ruby
|
601
|
+
class Account < ActiveRecord::Base
|
602
|
+
belongs_to :supplier, dependent: :destroy_async
|
638
603
|
end
|
639
604
|
```
|
640
605
|
|
641
|
-
|
606
|
+
`:destroy_async` will enqueue a job to destroy associated records in the background.
|
642
607
|
|
643
|
-
*
|
608
|
+
*DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
|
644
609
|
|
645
|
-
|
610
|
+
* Add `SKIP_TEST_DATABASE` environment variable to disable modifying the test database when `rails db:create` and `rails db:drop` are called.
|
646
611
|
|
647
|
-
|
648
|
-
t.string :title
|
649
|
-
end
|
612
|
+
*Jason Schweier*
|
650
613
|
|
651
|
-
|
614
|
+
* `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
|
652
615
|
|
653
|
-
|
654
|
-
...
|
655
|
-
)
|
616
|
+
Ensure that `connects_to` can only be called from `ActiveRecord::Base` or abstract classes. This protects the application from opening duplicate or too many connections.
|
656
617
|
|
657
|
-
|
658
|
-
exception whereas `if_not_exists: true` does nothing.
|
618
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
659
619
|
|
660
|
-
|
620
|
+
* All connection adapters `execute` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
621
|
+
`ActiveRecord::StatementInvalid` when they encounter a connection error.
|
661
622
|
|
662
|
-
*
|
623
|
+
*Jean Boussier*
|
663
624
|
|
664
|
-
|
625
|
+
* `Mysql2Adapter#quote_string` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
626
|
+
`ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
|
665
627
|
|
666
|
-
*
|
628
|
+
*Jean Boussier*
|
667
629
|
|
668
|
-
|
630
|
+
* Add support for check constraints that are `NOT VALID` via `validate: false` (PostgreSQL-only).
|
669
631
|
|
670
|
-
*
|
671
|
-
if the attribute does not exist.
|
632
|
+
*Alex Robbin*
|
672
633
|
|
673
|
-
|
634
|
+
* Ensure the default configuration is considered primary or first for an environment
|
674
635
|
|
675
|
-
|
636
|
+
If a multiple database application provides a configuration named primary, that will be treated as default. In applications that do not have a primary entry, the default database configuration will be the first configuration for an environment.
|
676
637
|
|
677
|
-
|
678
|
-
User.connected_to(database: { writing: "postgres://foo" }) do
|
679
|
-
User.create!(name: "Gannon")
|
680
|
-
end
|
638
|
+
*Eileen M. Uchitelle*
|
681
639
|
|
682
|
-
|
683
|
-
|
684
|
-
|
640
|
+
* Allow `where` references association names as joined table name aliases.
|
641
|
+
|
642
|
+
```ruby
|
643
|
+
class Comment < ActiveRecord::Base
|
644
|
+
enum label: [:default, :child]
|
645
|
+
has_many :children, class_name: "Comment", foreign_key: :parent_id
|
685
646
|
end
|
686
|
-
````
|
687
647
|
|
688
|
-
|
648
|
+
# ... FROM comments LEFT OUTER JOIN comments children ON ... WHERE children.label = 1
|
649
|
+
Comment.includes(:children).where("children.label": "child")
|
650
|
+
```
|
651
|
+
|
652
|
+
*Ryuta Kamizono*
|
689
653
|
|
690
|
-
* Support
|
654
|
+
* Support storing demodulized class name for polymorphic type.
|
691
655
|
|
692
|
-
|
656
|
+
Before Rails 6.1, storing demodulized class name is supported only for STI type
|
657
|
+
by `store_full_sti_class` class attribute.
|
693
658
|
|
694
|
-
|
659
|
+
Now `store_full_class_name` class attribute can handle both STI and polymorphic types.
|
695
660
|
|
696
661
|
*Ryuta Kamizono*
|
697
662
|
|
698
|
-
*
|
663
|
+
* Deprecate `rails db:structure:{load, dump}` tasks and extend
|
664
|
+
`rails db:schema:{load, dump}` tasks to work with either `:ruby` or `:sql` format,
|
665
|
+
depending on `config.active_record.schema_format` configuration value.
|
699
666
|
|
700
|
-
|
701
|
-
expression values rather than column or column prefix values.
|
667
|
+
*fatkodima*
|
702
668
|
|
703
|
-
|
669
|
+
* Respect the `select` values for eager loading.
|
670
|
+
|
671
|
+
```ruby
|
672
|
+
post = Post.select("UPPER(title) AS title").first
|
673
|
+
post.title # => "WELCOME TO THE WEBLOG"
|
674
|
+
post.body # => ActiveModel::MissingAttributeError
|
675
|
+
|
676
|
+
# Rails 6.0 (ignore the `select` values)
|
677
|
+
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
678
|
+
post.title # => "Welcome to the weblog"
|
679
|
+
post.body # => "Such a lovely day"
|
680
|
+
|
681
|
+
# Rails 6.1 (respect the `select` values)
|
682
|
+
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
683
|
+
post.title # => "WELCOME TO THE WEBLOG"
|
684
|
+
post.body # => ActiveModel::MissingAttributeError
|
685
|
+
```
|
704
686
|
|
705
687
|
*Ryuta Kamizono*
|
706
688
|
|
707
|
-
*
|
689
|
+
* Allow attribute's default to be configured but keeping its own type.
|
708
690
|
|
709
|
-
|
691
|
+
```ruby
|
692
|
+
class Post < ActiveRecord::Base
|
693
|
+
attribute :written_at, default: -> { Time.now.utc }
|
694
|
+
end
|
710
695
|
|
711
|
-
|
696
|
+
# Rails 6.0
|
697
|
+
Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
|
712
698
|
|
713
|
-
|
699
|
+
# Rails 6.1
|
700
|
+
Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>
|
701
|
+
```
|
714
702
|
|
715
|
-
|
703
|
+
*Ryuta Kamizono*
|
716
704
|
|
717
|
-
|
718
|
-
class AnimalsModel < ApplicationRecord
|
719
|
-
self.abstract_class = true
|
705
|
+
* Allow default to be configured for Enum.
|
720
706
|
|
721
|
-
|
707
|
+
```ruby
|
708
|
+
class Book < ActiveRecord::Base
|
709
|
+
enum status: [:proposed, :written, :published], _default: :published
|
722
710
|
end
|
723
711
|
|
724
|
-
|
725
|
-
# connected to both the animals_primary db for writing and the animals_replica for reading
|
726
|
-
end
|
712
|
+
Book.new.status # => "published"
|
727
713
|
```
|
728
714
|
|
729
|
-
|
730
|
-
a database that the model didn't connect to. Connecting to the database in this block is
|
731
|
-
useful when you have another defined connection, for example `slow_replica` that you don't
|
732
|
-
want to connect to by default but need in the console, or a specific code block.
|
715
|
+
*Ryuta Kamizono*
|
733
716
|
|
734
|
-
|
735
|
-
ActiveRecord::Base.connected_to(role: :reading) do
|
736
|
-
Dog.first # finds dog from replica connected to AnimalsBase
|
737
|
-
Book.first # doesn't have a reading connection, will raise an error
|
738
|
-
end
|
739
|
-
```
|
717
|
+
* Deprecate YAML loading from legacy format older than Rails 5.0.
|
740
718
|
|
741
|
-
|
742
|
-
ActiveRecord::Base.connected_to(database: :slow_replica) do
|
743
|
-
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
|
744
|
-
end
|
745
|
-
```
|
719
|
+
*Ryuta Kamizono*
|
746
720
|
|
747
|
-
|
721
|
+
* Added the setting `ActiveRecord::Base.immutable_strings_by_default`, which
|
722
|
+
allows you to specify that all string columns should be frozen unless
|
723
|
+
otherwise specified. This will reduce memory pressure for applications which
|
724
|
+
do not generally mutate string properties of Active Record objects.
|
748
725
|
|
749
|
-
*
|
726
|
+
*Sean Griffin*, *Ryuta Kamizono*
|
750
727
|
|
751
|
-
|
752
|
-
commit checks that only valid definition values are provided, those can
|
753
|
-
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
754
|
-
raises an `ArgumentError`.
|
728
|
+
* Deprecate `map!` and `collect!` on `ActiveRecord::Result`.
|
755
729
|
|
756
|
-
|
730
|
+
*Ryuta Kamizono*
|
757
731
|
|
758
|
-
|
732
|
+
* Support `relation.and` for intersection as Set theory.
|
759
733
|
|
760
|
-
|
734
|
+
```ruby
|
735
|
+
david_and_mary = Author.where(id: [david, mary])
|
736
|
+
mary_and_bob = Author.where(id: [mary, bob])
|
761
737
|
|
762
|
-
|
763
|
-
class Post < ActiveRecord::Base
|
764
|
-
has_one :category
|
765
|
-
belongs_to :author
|
766
|
-
has_many :comments
|
767
|
-
end
|
738
|
+
david_and_mary.merge(mary_and_bob) # => [mary, bob]
|
768
739
|
|
769
|
-
#
|
770
|
-
|
771
|
-
post.reload_author
|
772
|
-
post.comments.reload
|
740
|
+
david_and_mary.and(mary_and_bob) # => [mary]
|
741
|
+
david_and_mary.or(mary_and_bob) # => [david, mary, bob]
|
773
742
|
```
|
774
743
|
|
775
|
-
*
|
776
|
-
|
777
|
-
* Added `index` option for `change_table` migration helpers.
|
778
|
-
With this change you can create indexes while adding new
|
779
|
-
columns into the existing tables.
|
744
|
+
*Ryuta Kamizono*
|
780
745
|
|
781
|
-
|
746
|
+
* Merging conditions on the same column no longer maintain both conditions,
|
747
|
+
and will be consistently replaced by the latter condition in Rails 6.2.
|
748
|
+
To migrate to Rails 6.2's behavior, use `relation.merge(other, rewhere: true)`.
|
782
749
|
|
783
|
-
|
784
|
-
|
785
|
-
|
750
|
+
```ruby
|
751
|
+
# Rails 6.1 (IN clause is replaced by merger side equality condition)
|
752
|
+
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
786
753
|
|
787
|
-
|
754
|
+
# Rails 6.1 (both conflict conditions exists, deprecated)
|
755
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
|
788
756
|
|
789
|
-
|
757
|
+
# Rails 6.1 with rewhere to migrate to Rails 6.2's behavior
|
758
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
|
790
759
|
|
791
|
-
|
792
|
-
|
760
|
+
# Rails 6.2 (same behavior with IN clause, mergee side condition is consistently replaced)
|
761
|
+
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
762
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
|
763
|
+
```
|
793
764
|
|
794
|
-
*
|
765
|
+
*Ryuta Kamizono*
|
795
766
|
|
796
|
-
*
|
767
|
+
* Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
|
797
768
|
|
798
|
-
*
|
769
|
+
*Peter Fry*
|
799
770
|
|
800
|
-
*
|
771
|
+
* Resolve issue with insert_all unique_by option when used with expression index.
|
801
772
|
|
802
|
-
|
773
|
+
When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
|
774
|
+
`ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
|
775
|
+
was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
|
803
776
|
|
804
|
-
|
777
|
+
Usage:
|
805
778
|
|
806
|
-
|
779
|
+
```ruby
|
780
|
+
create_table :books, id: :integer, force: true do |t|
|
781
|
+
t.column :name, :string
|
782
|
+
t.index "lower(name)", unique: true
|
783
|
+
end
|
807
784
|
|
808
|
-
|
785
|
+
Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
|
786
|
+
```
|
809
787
|
|
810
|
-
|
788
|
+
Fixes #39516.
|
811
789
|
|
812
|
-
*
|
790
|
+
*Austen Madden*
|
813
791
|
|
814
|
-
*
|
792
|
+
* Add basic support for CHECK constraints to database migrations.
|
815
793
|
|
816
|
-
|
817
|
-
create_table :users do |t|
|
818
|
-
t.string :email
|
819
|
-
end
|
794
|
+
Usage:
|
820
795
|
|
821
|
-
|
796
|
+
```ruby
|
797
|
+
add_check_constraint :products, "price > 0", name: "price_check"
|
798
|
+
remove_check_constraint :products, name: "price_check"
|
822
799
|
```
|
823
800
|
|
824
|
-
*
|
801
|
+
*fatkodima*
|
825
802
|
|
826
|
-
*
|
803
|
+
* Add `ActiveRecord::Base.strict_loading_by_default` and `ActiveRecord::Base.strict_loading_by_default=`
|
804
|
+
to enable/disable strict_loading mode by default for a model. The configuration's value is
|
805
|
+
inheritable by subclasses, but they can override that value and it will not impact parent class.
|
827
806
|
|
828
|
-
|
807
|
+
Usage:
|
829
808
|
|
830
|
-
|
831
|
-
|
832
|
-
|
809
|
+
```ruby
|
810
|
+
class Developer < ApplicationRecord
|
811
|
+
self.strict_loading_by_default = true
|
833
812
|
|
834
|
-
|
813
|
+
has_many :projects
|
814
|
+
end
|
835
815
|
|
836
|
-
|
816
|
+
dev = Developer.first
|
817
|
+
dev.projects.first
|
818
|
+
# => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.
|
819
|
+
```
|
837
820
|
|
838
|
-
|
839
|
-
The previous default 3-Byte encoding character set `utf8` is not enough to support them.
|
821
|
+
*bogdanvlviv*
|
840
822
|
|
841
|
-
|
823
|
+
* Deprecate passing an Active Record object to `quote`/`type_cast` directly.
|
842
824
|
|
843
|
-
*
|
825
|
+
*Ryuta Kamizono*
|
844
826
|
|
845
|
-
|
827
|
+
* Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic.
|
846
828
|
|
847
|
-
|
848
|
-
sensitive values of database columns when calling `#inspect`.
|
849
|
-
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
850
|
-
specify sensitive attributes to specific model.
|
829
|
+
Before:
|
851
830
|
|
852
|
-
```
|
853
|
-
|
854
|
-
|
855
|
-
SecureAccount.filter_attributes += [:name]
|
856
|
-
SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
|
831
|
+
```ruby
|
832
|
+
create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
|
833
|
+
end
|
857
834
|
```
|
858
835
|
|
859
|
-
|
836
|
+
After:
|
860
837
|
|
861
|
-
|
862
|
-
|
863
|
-
|
838
|
+
```ruby
|
839
|
+
create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
840
|
+
end
|
841
|
+
```
|
864
842
|
|
865
843
|
*Ryuta Kamizono*
|
866
844
|
|
867
|
-
*
|
845
|
+
* Added delegated type as an alternative to single-table inheritance for representing class hierarchies.
|
846
|
+
See ActiveRecord::DelegatedType for the full description.
|
868
847
|
|
869
|
-
|
870
|
-
is an inflexible data model. In order to improve multiple-database
|
871
|
-
handling in Rails, we've changed this to return an object. Some methods
|
872
|
-
are provided to make the object behave hash-like in order to ease the
|
873
|
-
transition process. Since most applications don't manipulate the hash
|
874
|
-
we've decided to add backwards-compatible functionality that will throw
|
875
|
-
a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
|
876
|
-
will use the new version internally and externally.
|
848
|
+
*DHH*
|
877
849
|
|
878
|
-
|
850
|
+
* Deprecate aggregations with group by duplicated fields.
|
879
851
|
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
852
|
+
To migrate to Rails 6.2's behavior, use `uniq!(:group)` to deduplicate group fields.
|
853
|
+
|
854
|
+
```ruby
|
855
|
+
accounts = Account.group(:firm_id)
|
856
|
+
|
857
|
+
# duplicated group fields, deprecated.
|
858
|
+
accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
|
859
|
+
# => {
|
860
|
+
# [1, 1] => 50,
|
861
|
+
# [2, 2] => 60
|
862
|
+
# }
|
863
|
+
|
864
|
+
# use `uniq!(:group)` to deduplicate group fields.
|
865
|
+
accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
|
866
|
+
# => {
|
867
|
+
# 1 => 50,
|
868
|
+
# 2 => 60
|
869
|
+
# }
|
884
870
|
```
|
885
871
|
|
886
|
-
|
872
|
+
*Ryuta Kamizono*
|
887
873
|
|
888
|
-
|
889
|
-
{ "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
|
890
|
-
```
|
874
|
+
* Deprecate duplicated query annotations.
|
891
875
|
|
892
|
-
|
876
|
+
To migrate to Rails 6.2's behavior, use `uniq!(:annotate)` to deduplicate query annotations.
|
893
877
|
|
878
|
+
```ruby
|
879
|
+
accounts = Account.where(id: [1, 2]).annotate("david and mary")
|
880
|
+
|
881
|
+
# duplicated annotations, deprecated.
|
882
|
+
accounts.merge(accounts.rewhere(id: 3))
|
883
|
+
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
|
884
|
+
|
885
|
+
# use `uniq!(:annotate)` to deduplicate annotations.
|
886
|
+
accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
|
887
|
+
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
|
894
888
|
```
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
889
|
+
|
890
|
+
*Ryuta Kamizono*
|
891
|
+
|
892
|
+
* Resolve conflict between counter cache and optimistic locking.
|
893
|
+
|
894
|
+
Bump an Active Record instance's lock version after updating its counter
|
895
|
+
cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
|
896
|
+
upon subsequent transactions by maintaining parity with the corresponding
|
897
|
+
database record's `lock_version` column.
|
898
|
+
|
899
|
+
Fixes #16449.
|
900
|
+
|
901
|
+
*Aaron Lipman*
|
902
|
+
|
903
|
+
* Support merging option `:rewhere` to allow mergee side condition to be replaced exactly.
|
904
|
+
|
905
|
+
```ruby
|
906
|
+
david_and_mary = Author.where(id: david.id..mary.id)
|
907
|
+
|
908
|
+
# both conflict conditions exists
|
909
|
+
david_and_mary.merge(Author.where(id: bob)) # => []
|
910
|
+
|
911
|
+
# mergee side condition is replaced by rewhere
|
912
|
+
david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
|
913
|
+
|
914
|
+
# mergee side condition is replaced by rewhere option
|
915
|
+
david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]
|
899
916
|
```
|
900
917
|
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
918
|
+
*Ryuta Kamizono*
|
919
|
+
|
920
|
+
* Add support for finding records based on signed ids, which are tamper-proof, verified ids that can be
|
921
|
+
set to expire and scoped with a purpose. This is particularly useful for things like password reset
|
922
|
+
or email verification, where you want the bearer of the signed id to be able to interact with the
|
923
|
+
underlying record, but usually only within a certain time period.
|
924
|
+
|
925
|
+
```ruby
|
926
|
+
signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
|
927
|
+
|
928
|
+
User.find_signed signed_id # => nil, since the purpose does not match
|
929
|
+
|
930
|
+
travel 16.minutes
|
931
|
+
User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
|
932
|
+
|
933
|
+
travel_back
|
934
|
+
User.find_signed signed_id, purpose: :password_reset # => User.first
|
907
935
|
|
936
|
+
User.find_signed! "bad data" # => ActiveSupport::MessageVerifier::InvalidSignature
|
908
937
|
```
|
909
|
-
|
910
|
-
|
938
|
+
|
939
|
+
*DHH*
|
940
|
+
|
941
|
+
* Support `ALGORITHM = INSTANT` DDL option for index operations on MySQL.
|
942
|
+
|
943
|
+
*Ryuta Kamizono*
|
944
|
+
|
945
|
+
* Fix index creation to preserve index comment in bulk change table on MySQL.
|
946
|
+
|
947
|
+
*Ryuta Kamizono*
|
948
|
+
|
949
|
+
* Allow `unscope` to be aware of table name qualified values.
|
950
|
+
|
951
|
+
It is possible to unscope only the column in the specified table.
|
952
|
+
|
953
|
+
```ruby
|
954
|
+
posts = Post.joins(:comments).group(:"posts.hidden")
|
955
|
+
posts = posts.where("posts.hidden": false, "comments.hidden": false)
|
956
|
+
|
957
|
+
posts.count
|
958
|
+
# => { false => 10 }
|
959
|
+
|
960
|
+
# unscope both hidden columns
|
961
|
+
posts.unscope(where: :hidden).count
|
962
|
+
# => { false => 11, true => 1 }
|
963
|
+
|
964
|
+
# unscope only comments.hidden column
|
965
|
+
posts.unscope(where: :"comments.hidden").count
|
966
|
+
# => { false => 11 }
|
911
967
|
```
|
912
968
|
|
913
|
-
*
|
969
|
+
*Ryuta Kamizono*, *Slava Korolev*
|
970
|
+
|
971
|
+
* Fix `rewhere` to truly overwrite collided where clause by new where clause.
|
972
|
+
|
973
|
+
```ruby
|
974
|
+
steve = Person.find_by(name: "Steve")
|
975
|
+
david = Author.find_by(name: "David")
|
976
|
+
|
977
|
+
relation = Essay.where(writer: steve)
|
978
|
+
|
979
|
+
# Before
|
980
|
+
relation.rewhere(writer: david).to_a # => []
|
914
981
|
|
915
|
-
|
982
|
+
# After
|
983
|
+
relation.rewhere(writer: david).to_a # => [david]
|
984
|
+
```
|
985
|
+
|
986
|
+
*Ryuta Kamizono*
|
987
|
+
|
988
|
+
* Inspect time attributes with subsec and time zone offset.
|
989
|
+
|
990
|
+
```ruby
|
991
|
+
p Knot.create
|
992
|
+
=> #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
|
993
|
+
```
|
994
|
+
|
995
|
+
*akinomaeni*, *Jonathan Hefner*
|
996
|
+
|
997
|
+
* Deprecate passing a column to `type_cast`.
|
998
|
+
|
999
|
+
*Ryuta Kamizono*
|
1000
|
+
|
1001
|
+
* Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.
|
1002
|
+
|
1003
|
+
*Ryuta Kamizono*
|
1004
|
+
|
1005
|
+
* Support bulk insert/upsert on relation to preserve scope values.
|
1006
|
+
|
1007
|
+
*Josef Šimánek*, *Ryuta Kamizono*
|
1008
|
+
|
1009
|
+
* Preserve column comment value on changing column name on MySQL.
|
1010
|
+
|
1011
|
+
*Islam Taha*
|
1012
|
+
|
1013
|
+
* Add support for `if_exists` option for removing an index.
|
1014
|
+
|
1015
|
+
The `remove_index` method can take an `if_exists` option. If this is set to true an error won't be raised if the index doesn't exist.
|
1016
|
+
|
1017
|
+
*Eileen M. Uchitelle*
|
916
1018
|
|
1019
|
+
* Remove ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base.
|
1020
|
+
|
1021
|
+
*Ryuta Kamizono*
|
1022
|
+
|
1023
|
+
* Prevent `build_association` from `touching` a parent record if the record isn't persisted for `has_one` associations.
|
1024
|
+
|
1025
|
+
Fixes #38219.
|
1026
|
+
|
1027
|
+
*Josh Brody*
|
1028
|
+
|
1029
|
+
* Add support for `if_not_exists` option for adding index.
|
1030
|
+
|
1031
|
+
The `add_index` method respects `if_not_exists` option. If it is set to true
|
1032
|
+
index won't be added.
|
1033
|
+
|
1034
|
+
Usage:
|
1035
|
+
|
1036
|
+
```ruby
|
1037
|
+
add_index :users, :account_id, if_not_exists: true
|
1038
|
+
```
|
1039
|
+
|
1040
|
+
The `if_not_exists` option passed to `create_table` also gets propagated to indexes
|
1041
|
+
created within that migration so that if table and its indexes exist then there is no
|
1042
|
+
attempt to create them again.
|
1043
|
+
|
1044
|
+
*Prathamesh Sonpatki*
|
1045
|
+
|
1046
|
+
* Add `ActiveRecord::Base#previously_new_record?` to show if a record was new before the last save.
|
1047
|
+
|
1048
|
+
*Tom Ward*
|
1049
|
+
|
1050
|
+
* Support descending order for `find_each`, `find_in_batches`, and `in_batches`.
|
1051
|
+
|
1052
|
+
Batch processing methods allow you to work with the records in batches, greatly reducing memory consumption, but records are always batched from oldest id to newest.
|
1053
|
+
|
1054
|
+
This change allows reversing the order, batching from newest to oldest. This is useful when you need to process newer batches of records first.
|
1055
|
+
|
1056
|
+
Pass `order: :desc` to yield batches in descending order. The default remains `order: :asc`.
|
1057
|
+
|
1058
|
+
```ruby
|
1059
|
+
Person.find_each(order: :desc) do |person|
|
1060
|
+
person.party_all_night!
|
1061
|
+
end
|
917
1062
|
```
|
1063
|
+
|
1064
|
+
*Alexey Vasiliev*
|
1065
|
+
|
1066
|
+
* Fix `insert_all` with enum values.
|
1067
|
+
|
1068
|
+
Fixes #38716.
|
1069
|
+
|
1070
|
+
*Joel Blum*
|
1071
|
+
|
1072
|
+
* Add support for `db:rollback:name` for multiple database applications.
|
1073
|
+
|
1074
|
+
Multiple database applications will now raise if `db:rollback` is call and recommend using the `db:rollback:[NAME]` to rollback migrations.
|
1075
|
+
|
1076
|
+
*Eileen M. Uchitelle*
|
1077
|
+
|
1078
|
+
* `Relation#pick` now uses already loaded results instead of making another query.
|
1079
|
+
|
1080
|
+
*Eugene Kenny*
|
1081
|
+
|
1082
|
+
* Deprecate using `return`, `break` or `throw` to exit a transaction block after writes.
|
1083
|
+
|
1084
|
+
*Dylan Thacker-Smith*
|
1085
|
+
|
1086
|
+
* Dump the schema or structure of a database when calling `db:migrate:name`.
|
1087
|
+
|
1088
|
+
In previous versions of Rails, `rails db:migrate` would dump the schema of the database. In Rails 6, that holds true (`rails db:migrate` dumps all databases' schemas), but `rails db:migrate:name` does not share that behavior.
|
1089
|
+
|
1090
|
+
Going forward, calls to `rails db:migrate:name` will dump the schema (or structure) of the database being migrated.
|
1091
|
+
|
1092
|
+
*Kyle Thompson*
|
1093
|
+
|
1094
|
+
* Reset the `ActiveRecord::Base` connection after `rails db:migrate:name`.
|
1095
|
+
|
1096
|
+
When `rails db:migrate` has finished, it ensures the `ActiveRecord::Base` connection is reset to its original configuration. Going forward, `rails db:migrate:name` will have the same behavior.
|
1097
|
+
|
1098
|
+
*Kyle Thompson*
|
1099
|
+
|
1100
|
+
* Disallow calling `connected_to` on subclasses of `ActiveRecord::Base`.
|
1101
|
+
|
1102
|
+
Behavior has not changed here but the previous API could be misleading to people who thought it would switch connections for only that class. `connected_to` switches the context from which we are getting connections, not the connections themselves.
|
1103
|
+
|
1104
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1105
|
+
|
1106
|
+
* Add support for horizontal sharding to `connects_to` and `connected_to`.
|
1107
|
+
|
1108
|
+
Applications can now connect to multiple shards and switch between their shards in an application. Note that the shard swapping is still a manual process as this change does not include an API for automatic shard swapping.
|
1109
|
+
|
1110
|
+
Usage:
|
1111
|
+
|
1112
|
+
Given the following configuration:
|
1113
|
+
|
1114
|
+
```yaml
|
1115
|
+
# config/database.yml
|
918
1116
|
production:
|
1117
|
+
primary:
|
1118
|
+
database: my_database
|
1119
|
+
primary_shard_one:
|
1120
|
+
database: my_database_shard_one
|
1121
|
+
```
|
1122
|
+
|
1123
|
+
Connect to multiple shards:
|
1124
|
+
|
1125
|
+
```ruby
|
1126
|
+
class ApplicationRecord < ActiveRecord::Base
|
1127
|
+
self.abstract_class = true
|
1128
|
+
|
1129
|
+
connects_to shards: {
|
1130
|
+
default: { writing: :primary },
|
1131
|
+
shard_one: { writing: :primary_shard_one }
|
1132
|
+
}
|
1133
|
+
```
|
1134
|
+
|
1135
|
+
Swap between shards in your controller / model code:
|
1136
|
+
|
1137
|
+
```ruby
|
1138
|
+
ActiveRecord::Base.connected_to(shard: :shard_one) do
|
1139
|
+
# Read from shard one
|
1140
|
+
end
|
1141
|
+
```
|
1142
|
+
|
1143
|
+
The horizontal sharding API also supports read replicas. See guides for more details.
|
1144
|
+
|
1145
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1146
|
+
|
1147
|
+
* Deprecate `spec_name` in favor of `name` on database configurations.
|
1148
|
+
|
1149
|
+
The accessors for `spec_name` on `configs_for` and `DatabaseConfig` are deprecated. Please use `name` instead.
|
1150
|
+
|
1151
|
+
Deprecated behavior:
|
1152
|
+
|
1153
|
+
```ruby
|
1154
|
+
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
|
1155
|
+
db_config.spec_name
|
1156
|
+
```
|
1157
|
+
|
1158
|
+
New behavior:
|
1159
|
+
|
1160
|
+
```ruby
|
1161
|
+
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", name: "primary")
|
1162
|
+
db_config.name
|
1163
|
+
```
|
1164
|
+
|
1165
|
+
*Eileen M. Uchitelle*
|
1166
|
+
|
1167
|
+
* Add additional database-specific rake tasks for multi-database users.
|
1168
|
+
|
1169
|
+
Previously, `rails db:create`, `rails db:drop`, and `rails db:migrate` were the only rails tasks that could operate on a single
|
1170
|
+
database. For example:
|
1171
|
+
|
1172
|
+
```
|
1173
|
+
rails db:create
|
1174
|
+
rails db:create:primary
|
1175
|
+
rails db:create:animals
|
1176
|
+
rails db:drop
|
1177
|
+
rails db:drop:primary
|
1178
|
+
rails db:drop:animals
|
1179
|
+
rails db:migrate
|
1180
|
+
rails db:migrate:primary
|
1181
|
+
rails db:migrate:animals
|
1182
|
+
```
|
1183
|
+
|
1184
|
+
With these changes, `rails db:schema:dump`, `rails db:schema:load`, `rails db:structure:dump`, `rails db:structure:load` and
|
1185
|
+
`rails db:test:prepare` can additionally operate on a single database. For example:
|
1186
|
+
|
1187
|
+
```
|
1188
|
+
rails db:schema:dump
|
1189
|
+
rails db:schema:dump:primary
|
1190
|
+
rails db:schema:dump:animals
|
1191
|
+
rails db:schema:load
|
1192
|
+
rails db:schema:load:primary
|
1193
|
+
rails db:schema:load:animals
|
1194
|
+
rails db:structure:dump
|
1195
|
+
rails db:structure:dump:primary
|
1196
|
+
rails db:structure:dump:animals
|
1197
|
+
rails db:structure:load
|
1198
|
+
rails db:structure:load:primary
|
1199
|
+
rails db:structure:load:animals
|
1200
|
+
rails db:test:prepare
|
1201
|
+
rails db:test:prepare:primary
|
1202
|
+
rails db:test:prepare:animals
|
1203
|
+
```
|
1204
|
+
|
1205
|
+
*Kyle Thompson*
|
1206
|
+
|
1207
|
+
* Add support for `strict_loading` mode on association declarations.
|
1208
|
+
|
1209
|
+
Raise an error if attempting to load a record from an association that has been marked as `strict_loading` unless it was explicitly eager loaded.
|
1210
|
+
|
1211
|
+
Usage:
|
1212
|
+
|
1213
|
+
```ruby
|
1214
|
+
class Developer < ApplicationRecord
|
1215
|
+
has_many :projects, strict_loading: true
|
1216
|
+
end
|
1217
|
+
|
1218
|
+
dev = Developer.first
|
1219
|
+
dev.projects.first
|
1220
|
+
# => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.
|
1221
|
+
```
|
1222
|
+
|
1223
|
+
*Kevin Deisz*
|
1224
|
+
|
1225
|
+
* Add support for `strict_loading` mode to prevent lazy loading of records.
|
1226
|
+
|
1227
|
+
Raise an error if a parent record is marked as `strict_loading` and attempts to lazily load its associations. This is useful for finding places you may want to preload an association and avoid additional queries.
|
1228
|
+
|
1229
|
+
Usage:
|
1230
|
+
|
1231
|
+
```ruby
|
1232
|
+
dev = Developer.strict_loading.first
|
1233
|
+
dev.audit_logs.to_a
|
1234
|
+
# => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
|
1235
|
+
```
|
1236
|
+
|
1237
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*
|
1238
|
+
|
1239
|
+
* Add support for PostgreSQL 11+ partitioned indexes when using `upsert_all`.
|
1240
|
+
|
1241
|
+
*Sebastián Palma*
|
1242
|
+
|
1243
|
+
* Adds support for `if_not_exists` to `add_column` and `if_exists` to `remove_column`.
|
1244
|
+
|
1245
|
+
Applications can set their migrations to ignore exceptions raised when adding a column that already exists or when removing a column that does not exist.
|
1246
|
+
|
1247
|
+
Example Usage:
|
1248
|
+
|
1249
|
+
```ruby
|
1250
|
+
class AddColumnTitle < ActiveRecord::Migration[6.1]
|
1251
|
+
def change
|
1252
|
+
add_column :posts, :title, :string, if_not_exists: true
|
1253
|
+
end
|
1254
|
+
end
|
1255
|
+
```
|
1256
|
+
|
1257
|
+
```ruby
|
1258
|
+
class RemoveColumnTitle < ActiveRecord::Migration[6.1]
|
1259
|
+
def change
|
1260
|
+
remove_column :posts, :title, if_exists: true
|
1261
|
+
end
|
1262
|
+
end
|
1263
|
+
```
|
1264
|
+
|
1265
|
+
*Eileen M. Uchitelle*
|
1266
|
+
|
1267
|
+
* Regexp-escape table name for MS SQL Server.
|
1268
|
+
|
1269
|
+
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.
|
1270
|
+
|
1271
|
+
*Larry Reid*
|
1272
|
+
|
1273
|
+
* Store advisory locks on their own named connection.
|
1274
|
+
|
1275
|
+
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.
|
1276
|
+
|
1277
|
+
In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdvisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
|
1278
|
+
|
1279
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1280
|
+
|
1281
|
+
* Allow schema cache path to be defined in the database configuration file.
|
1282
|
+
|
1283
|
+
For example:
|
1284
|
+
|
1285
|
+
```yaml
|
1286
|
+
development:
|
919
1287
|
adapter: postgresql
|
920
|
-
|
1288
|
+
database: blog_development
|
1289
|
+
pool: 5
|
1290
|
+
schema_cache_path: tmp/schema/main.yml
|
921
1291
|
```
|
922
1292
|
|
923
|
-
*
|
1293
|
+
*Katrina Owen*
|
924
1294
|
|
925
|
-
*
|
1295
|
+
* Deprecate `#remove_connection` in favor of `#remove_connection_pool` when called on the handler.
|
926
1296
|
|
927
|
-
|
1297
|
+
`#remove_connection` is deprecated in order to support returning a `DatabaseConfig` object instead of a `Hash`. Use `#remove_connection_pool`, `#remove_connection` will be removed in 6.2.
|
928
1298
|
|
929
|
-
*
|
1299
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
930
1300
|
|
931
|
-
|
1301
|
+
* Deprecate `#default_hash` and it's alias `#[]` on database configurations.
|
1302
|
+
|
1303
|
+
Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in 6.2.
|
1304
|
+
|
1305
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1306
|
+
|
1307
|
+
* Add scale support to `ActiveRecord::Validations::NumericalityValidator`.
|
1308
|
+
|
1309
|
+
*Gannon McGibbon*
|
1310
|
+
|
1311
|
+
* Find orphans by looking for missing relations through chaining `where.missing`:
|
1312
|
+
|
1313
|
+
Before:
|
1314
|
+
|
1315
|
+
```ruby
|
1316
|
+
Post.left_joins(:author).where(authors: { id: nil })
|
1317
|
+
```
|
1318
|
+
|
1319
|
+
After:
|
1320
|
+
|
1321
|
+
```ruby
|
1322
|
+
Post.where.missing(:author)
|
1323
|
+
```
|
1324
|
+
|
1325
|
+
*Tom Rossi*
|
1326
|
+
|
1327
|
+
* Ensure `:reading` connections always raise if a write is attempted.
|
1328
|
+
|
1329
|
+
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`.
|
1330
|
+
|
1331
|
+
*Eileen M. Uchitelle*
|
1332
|
+
|
1333
|
+
* Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
|
1334
|
+
|
1335
|
+
`"primary"` has been deprecated as the `connection_specification_name` for `ActiveRecord::Base` in favor of using `"ActiveRecord::Base"`. This change affects calls to `ActiveRecord::Base.connection_handler.retrieve_connection` and `ActiveRecord::Base.connection_handler.remove_connection`. If you're calling these methods with `"primary"`, please switch to `"ActiveRecord::Base"`.
|
1336
|
+
|
1337
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1338
|
+
|
1339
|
+
* Add `ActiveRecord::Validations::NumericalityValidator` with
|
1340
|
+
support for casting floats using a database columns' precision value.
|
1341
|
+
|
1342
|
+
*Gannon McGibbon*
|
1343
|
+
|
1344
|
+
* Enforce fresh ETag header after a collection's contents change by adding
|
1345
|
+
ActiveRecord::Relation#cache_key_with_version. This method will be used by
|
1346
|
+
ActionController::ConditionalGet to ensure that when collection cache versioning
|
1347
|
+
is enabled, requests using ConditionalGet don't return the same ETag header
|
1348
|
+
after a collection is modified.
|
1349
|
+
|
1350
|
+
Fixes #38078.
|
1351
|
+
|
1352
|
+
*Aaron Lipman*
|
1353
|
+
|
1354
|
+
* Skip test database when running `db:create` or `db:drop` in development
|
1355
|
+
with `DATABASE_URL` set.
|
1356
|
+
|
1357
|
+
*Brian Buchalter*
|
1358
|
+
|
1359
|
+
* Don't allow mutations on the database configurations hash.
|
1360
|
+
|
1361
|
+
Freeze the configurations hash to disallow directly changing it. If applications need to change the hash, for example to create databases for parallelization, they should use the `DatabaseConfig` object directly.
|
1362
|
+
|
1363
|
+
Before:
|
1364
|
+
|
1365
|
+
```ruby
|
1366
|
+
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
|
1367
|
+
@db_config.configuration_hash.merge!(idle_timeout: "0.02")
|
1368
|
+
```
|
1369
|
+
|
1370
|
+
After:
|
1371
|
+
|
1372
|
+
```ruby
|
1373
|
+
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
|
1374
|
+
config = @db_config.configuration_hash.merge(idle_timeout: "0.02")
|
1375
|
+
db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)
|
1376
|
+
```
|
1377
|
+
|
1378
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1379
|
+
|
1380
|
+
* Remove `:connection_id` from the `sql.active_record` notification.
|
1381
|
+
|
1382
|
+
*Aaron Patterson*, *Rafael Mendonça França*
|
1383
|
+
|
1384
|
+
* The `:name` key will no longer be returned as part of `DatabaseConfig#configuration_hash`. Please use `DatabaseConfig#owner_name` instead.
|
1385
|
+
|
1386
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1387
|
+
|
1388
|
+
* ActiveRecord's `belongs_to_required_by_default` flag can now be set per model.
|
1389
|
+
|
1390
|
+
You can now opt-out/opt-in specific models from having their associations required
|
1391
|
+
by default.
|
1392
|
+
|
1393
|
+
This change is meant to ease the process of migrating all your models to have
|
1394
|
+
their association required.
|
1395
|
+
|
1396
|
+
*Edouard Chin*
|
1397
|
+
|
1398
|
+
* The `connection_config` method has been deprecated, please use `connection_db_config` instead which will return a `DatabaseConfigurations::DatabaseConfig` instead of a `Hash`.
|
1399
|
+
|
1400
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1401
|
+
|
1402
|
+
* Retain explicit selections on the base model after applying `includes` and `joins`.
|
1403
|
+
|
1404
|
+
Resolves #34889.
|
1405
|
+
|
1406
|
+
*Patrick Rebsch*
|
1407
|
+
|
1408
|
+
* The `database` kwarg is deprecated without replacement because it can't be used for sharding and creates an issue if it's used during a request. Applications that need to create new connections should use `connects_to` instead.
|
932
1409
|
|
933
|
-
|
1410
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
934
1411
|
|
935
|
-
|
1412
|
+
* Allow attributes to be fetched from Arel node groupings.
|
936
1413
|
|
937
|
-
*
|
938
|
-
seed load in environments without Rails and custom DB configuration
|
1414
|
+
*Jeff Emminger*, *Gannon McGibbon*
|
939
1415
|
|
940
|
-
|
1416
|
+
* A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgreSQL `options`.
|
941
1417
|
|
942
|
-
*
|
1418
|
+
*Joshua Flanagan*
|
943
1419
|
|
944
|
-
|
1420
|
+
* Calling methods like `establish_connection` with a `Hash` which is invalid (eg: no `adapter`) will now raise an error the same way as connections defined in `config/database.yml`.
|
945
1421
|
|
946
|
-
*
|
1422
|
+
*John Crepezzi*
|
1423
|
+
|
1424
|
+
* Specifying `implicit_order_column` now subsorts the records by primary key if available to ensure deterministic results.
|
1425
|
+
|
1426
|
+
*Paweł Urbanek*
|
1427
|
+
|
1428
|
+
* `where(attr => [])` now loads an empty result without making a query.
|
1429
|
+
|
1430
|
+
*John Hawthorn*
|
1431
|
+
|
1432
|
+
* Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
|
1433
|
+
|
1434
|
+
*Hiroyuki Ishii*
|
1435
|
+
|
1436
|
+
* Add support for `belongs_to` to `has_many` inversing.
|
1437
|
+
|
1438
|
+
*Gannon McGibbon*
|
1439
|
+
|
1440
|
+
* Allow length configuration for `has_secure_token` method. The minimum length
|
1441
|
+
is set at 24 characters.
|
1442
|
+
|
1443
|
+
Before:
|
1444
|
+
|
1445
|
+
```ruby
|
1446
|
+
has_secure_token :auth_token
|
1447
|
+
```
|
1448
|
+
|
1449
|
+
After:
|
1450
|
+
|
1451
|
+
```ruby
|
1452
|
+
has_secure_token :default_token # 24 characters
|
1453
|
+
has_secure_token :auth_token, length: 36 # 36 characters
|
1454
|
+
has_secure_token :invalid_token, length: 12 # => ActiveRecord::SecureToken::MinimumLengthError
|
1455
|
+
```
|
1456
|
+
|
1457
|
+
*Bernardo de Araujo*
|
1458
|
+
|
1459
|
+
* Deprecate `DatabaseConfigurations#to_h`. These connection hashes are still available via `ActiveRecord::Base.configurations.configs_for`.
|
1460
|
+
|
1461
|
+
*Eileen Uchitelle*, *John Crepezzi*
|
1462
|
+
|
1463
|
+
* Add `DatabaseConfig#configuration_hash` to return database configuration hashes with symbol keys, and use all symbol-key configuration hashes internally. Deprecate `DatabaseConfig#config` which returns a String-keyed `Hash` with the same values.
|
1464
|
+
|
1465
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
1466
|
+
|
1467
|
+
* Allow column names to be passed to `remove_index` positionally along with other options.
|
1468
|
+
|
1469
|
+
Passing other options can be necessary to make `remove_index` correctly reversible.
|
1470
|
+
|
1471
|
+
Before:
|
1472
|
+
|
1473
|
+
add_index :reports, :report_id # => works
|
1474
|
+
add_index :reports, :report_id, unique: true # => works
|
1475
|
+
remove_index :reports, :report_id # => works
|
1476
|
+
remove_index :reports, :report_id, unique: true # => ArgumentError
|
1477
|
+
|
1478
|
+
After:
|
1479
|
+
|
1480
|
+
remove_index :reports, :report_id, unique: true # => works
|
1481
|
+
|
1482
|
+
*Eugene Kenny*
|
1483
|
+
|
1484
|
+
* Allow bulk `ALTER` statements to drop and recreate indexes with the same name.
|
1485
|
+
|
1486
|
+
*Eugene Kenny*
|
1487
|
+
|
1488
|
+
* `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
|
1489
|
+
|
1490
|
+
*Eugene Kenny*
|
1491
|
+
|
1492
|
+
* Call `while_preventing_writes` directly from `connected_to`.
|
1493
|
+
|
1494
|
+
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)`.
|
1495
|
+
|
1496
|
+
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.
|
1497
|
+
|
1498
|
+
*Eileen M. Uchitelle*
|
1499
|
+
|
1500
|
+
* Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
|
1501
|
+
|
1502
|
+
*Kir Shatrov*
|
1503
|
+
|
1504
|
+
* Stop trying to read yaml file fixtures when loading Active Record fixtures.
|
1505
|
+
|
1506
|
+
*Gannon McGibbon*
|
1507
|
+
|
1508
|
+
* Deprecate `.reorder(nil)` with `.first` / `.first!` taking non-deterministic result.
|
1509
|
+
|
1510
|
+
To continue taking non-deterministic result, use `.take` / `.take!` instead.
|
947
1511
|
|
948
1512
|
*Ryuta Kamizono*
|
949
1513
|
|
950
|
-
*
|
1514
|
+
* Preserve user supplied joins order as much as possible.
|
951
1515
|
|
952
|
-
Fixes #
|
1516
|
+
Fixes #36761, #34328, #24281, #12953.
|
953
1517
|
|
954
|
-
*
|
1518
|
+
*Ryuta Kamizono*
|
955
1519
|
|
956
|
-
*
|
1520
|
+
* Allow `matches_regex` and `does_not_match_regexp` on the MySQL Arel visitor.
|
957
1521
|
|
958
|
-
*
|
1522
|
+
*James Pearson*
|
959
1523
|
|
960
|
-
*
|
1524
|
+
* Allow specifying fixtures to be ignored by setting `ignore` in YAML file's '_fixture' section.
|
961
1525
|
|
962
|
-
|
1526
|
+
*Tongfei Gao*
|
963
1527
|
|
964
|
-
|
1528
|
+
* Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
|
965
1529
|
|
966
|
-
*
|
1530
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
967
1531
|
|
968
|
-
|
1532
|
+
* Add a warning for enum elements with 'not_' prefix.
|
969
1533
|
|
970
|
-
|
971
|
-
|
1534
|
+
class Foo
|
1535
|
+
enum status: [:sent, :not_sent]
|
1536
|
+
end
|
972
1537
|
|
973
|
-
*
|
1538
|
+
*Edu Depetris*
|
974
1539
|
|
975
|
-
*
|
1540
|
+
* Make currency symbols optional for money column type in PostgreSQL.
|
976
1541
|
|
977
|
-
*
|
1542
|
+
*Joel Schneider*
|
978
1543
|
|
979
|
-
* Add
|
1544
|
+
* Add support for beginless ranges, introduced in Ruby 2.7.
|
980
1545
|
|
981
|
-
|
1546
|
+
*Josh Goodall*
|
982
1547
|
|
983
|
-
|
1548
|
+
* Add `database_exists?` method to connection adapters to check if a database exists.
|
984
1549
|
|
985
|
-
*
|
1550
|
+
*Guilherme Mansur*
|
986
1551
|
|
987
|
-
*
|
1552
|
+
* Loading the schema for a model that has no `table_name` raises a `TableNotSpecified` error.
|
988
1553
|
|
989
|
-
*
|
1554
|
+
*Guilherme Mansur*, *Eugene Kenny*
|
990
1555
|
|
991
|
-
*
|
1556
|
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
992
1557
|
|
993
|
-
|
1558
|
+
Fixes #36022.
|
994
1559
|
|
995
|
-
*
|
1560
|
+
*Ryuta Kamizono*
|
996
1561
|
|
997
|
-
|
1562
|
+
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
998
1563
|
|
999
|
-
|
1564
|
+
Fixes #36465.
|
1000
1565
|
|
1001
|
-
*
|
1566
|
+
*Jeff Doering*
|
1002
1567
|
|
1003
|
-
* Add
|
1004
|
-
`ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
|
1568
|
+
* Add support for multiple databases to `rails db:abort_if_pending_migrations`.
|
1005
1569
|
|
1006
|
-
*
|
1570
|
+
*Mark Lee*
|
1007
1571
|
|
1008
|
-
*
|
1572
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
1009
1573
|
|
1010
|
-
*
|
1574
|
+
*Martin R. Schuster*
|
1575
|
+
|
1576
|
+
* Fix invalid schema when primary key column has a comment.
|
1577
|
+
|
1578
|
+
Fixes #29966.
|
1579
|
+
|
1580
|
+
*Guilherme Goettems Schneider*
|
1581
|
+
|
1582
|
+
* Fix table comment also being applied to the primary key column.
|
1583
|
+
|
1584
|
+
*Guilherme Goettems Schneider*
|
1585
|
+
|
1586
|
+
* Allow generated `create_table` migrations to include or skip timestamps.
|
1587
|
+
|
1588
|
+
*Michael Duchemin*
|
1011
1589
|
|
1012
1590
|
|
1013
|
-
Please check [
|
1591
|
+
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activerecord/CHANGELOG.md) for previous changes.
|