activerecord 6.1.7.4 → 7.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1449 -1014
- data/README.rdoc +3 -3
- data/lib/active_record/aggregations.rb +1 -1
- data/lib/active_record/association_relation.rb +0 -10
- data/lib/active_record/associations/association.rb +33 -17
- data/lib/active_record/associations/association_scope.rb +1 -3
- data/lib/active_record/associations/belongs_to_association.rb +15 -4
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +10 -2
- data/lib/active_record/associations/builder/association.rb +8 -2
- data/lib/active_record/associations/builder/belongs_to.rb +19 -6
- data/lib/active_record/associations/builder/collection_association.rb +10 -3
- data/lib/active_record/associations/builder/has_many.rb +3 -2
- data/lib/active_record/associations/builder/has_one.rb +2 -1
- data/lib/active_record/associations/builder/singular_association.rb +2 -2
- data/lib/active_record/associations/collection_association.rb +19 -21
- data/lib/active_record/associations/collection_proxy.rb +10 -5
- data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
- data/lib/active_record/associations/has_many_association.rb +8 -5
- data/lib/active_record/associations/has_many_through_association.rb +2 -1
- data/lib/active_record/associations/has_one_association.rb +14 -7
- data/lib/active_record/associations/has_one_through_association.rb +1 -1
- data/lib/active_record/associations/join_dependency.rb +23 -15
- data/lib/active_record/associations/preloader/association.rb +186 -52
- data/lib/active_record/associations/preloader/batch.rb +48 -0
- data/lib/active_record/associations/preloader/branch.rb +147 -0
- data/lib/active_record/associations/preloader/through_association.rb +50 -14
- data/lib/active_record/associations/preloader.rb +39 -113
- data/lib/active_record/associations/singular_association.rb +15 -7
- data/lib/active_record/associations/through_association.rb +3 -3
- data/lib/active_record/associations.rb +138 -100
- data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
- data/lib/active_record/attribute_assignment.rb +1 -1
- data/lib/active_record/attribute_methods/before_type_cast.rb +7 -2
- data/lib/active_record/attribute_methods/dirty.rb +49 -16
- data/lib/active_record/attribute_methods/primary_key.rb +2 -2
- data/lib/active_record/attribute_methods/query.rb +2 -2
- data/lib/active_record/attribute_methods/read.rb +8 -6
- data/lib/active_record/attribute_methods/serialization.rb +57 -19
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +4 -3
- data/lib/active_record/attribute_methods/write.rb +7 -10
- data/lib/active_record/attribute_methods.rb +19 -22
- data/lib/active_record/attributes.rb +24 -35
- data/lib/active_record/autosave_association.rb +17 -28
- data/lib/active_record/base.rb +19 -1
- data/lib/active_record/callbacks.rb +14 -16
- data/lib/active_record/coders/yaml_column.rb +4 -8
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +292 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +209 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +76 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +47 -561
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +0 -17
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +46 -22
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +24 -12
- data/lib/active_record/connection_adapters/abstract/quoting.rb +42 -72
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +4 -17
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +52 -23
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +14 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +82 -25
- data/lib/active_record/connection_adapters/abstract/transaction.rb +15 -22
- data/lib/active_record/connection_adapters/abstract_adapter.rb +153 -74
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +112 -84
- data/lib/active_record/connection_adapters/column.rb +4 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +36 -24
- data/lib/active_record/connection_adapters/mysql/quoting.rb +45 -21
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +4 -1
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +7 -1
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +20 -1
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +12 -6
- data/lib/active_record/connection_adapters/pool_config.rb +7 -7
- data/lib/active_record/connection_adapters/postgresql/column.rb +19 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +20 -17
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +8 -0
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +5 -0
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +53 -14
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/timestamp.rb +15 -0
- data/lib/active_record/connection_adapters/postgresql/oid/timestamp_with_time_zone.rb +30 -0
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +18 -6
- data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +71 -71
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +34 -0
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +21 -1
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +22 -1
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +25 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +40 -21
- data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -10
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +207 -106
- data/lib/active_record/connection_adapters/schema_cache.rb +39 -38
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +25 -19
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +28 -16
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +17 -15
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +97 -32
- data/lib/active_record/connection_adapters.rb +6 -5
- data/lib/active_record/connection_handling.rb +49 -55
- data/lib/active_record/core.rb +123 -148
- data/lib/active_record/database_configurations/connection_url_resolver.rb +2 -1
- data/lib/active_record/database_configurations/database_config.rb +12 -9
- data/lib/active_record/database_configurations/hash_config.rb +63 -5
- data/lib/active_record/database_configurations/url_config.rb +2 -2
- data/lib/active_record/database_configurations.rb +15 -32
- data/lib/active_record/delegated_type.rb +53 -12
- data/lib/active_record/destroy_association_async_job.rb +1 -1
- data/lib/active_record/disable_joins_association_relation.rb +39 -0
- data/lib/active_record/dynamic_matchers.rb +1 -1
- data/lib/active_record/encryption/cipher/aes256_gcm.rb +98 -0
- data/lib/active_record/encryption/cipher.rb +53 -0
- data/lib/active_record/encryption/config.rb +44 -0
- data/lib/active_record/encryption/configurable.rb +67 -0
- data/lib/active_record/encryption/context.rb +35 -0
- data/lib/active_record/encryption/contexts.rb +72 -0
- data/lib/active_record/encryption/derived_secret_key_provider.rb +12 -0
- data/lib/active_record/encryption/deterministic_key_provider.rb +14 -0
- data/lib/active_record/encryption/encryptable_record.rb +206 -0
- data/lib/active_record/encryption/encrypted_attribute_type.rb +140 -0
- data/lib/active_record/encryption/encrypted_fixtures.rb +38 -0
- data/lib/active_record/encryption/encrypting_only_encryptor.rb +12 -0
- data/lib/active_record/encryption/encryptor.rb +155 -0
- data/lib/active_record/encryption/envelope_encryption_key_provider.rb +55 -0
- data/lib/active_record/encryption/errors.rb +15 -0
- data/lib/active_record/encryption/extended_deterministic_queries.rb +160 -0
- data/lib/active_record/encryption/extended_deterministic_uniqueness_validator.rb +28 -0
- data/lib/active_record/encryption/key.rb +28 -0
- data/lib/active_record/encryption/key_generator.rb +42 -0
- data/lib/active_record/encryption/key_provider.rb +46 -0
- data/lib/active_record/encryption/message.rb +33 -0
- data/lib/active_record/encryption/message_serializer.rb +90 -0
- data/lib/active_record/encryption/null_encryptor.rb +21 -0
- data/lib/active_record/encryption/properties.rb +76 -0
- data/lib/active_record/encryption/read_only_null_encryptor.rb +24 -0
- data/lib/active_record/encryption/scheme.rb +99 -0
- data/lib/active_record/encryption.rb +55 -0
- data/lib/active_record/enum.rb +50 -43
- data/lib/active_record/errors.rb +67 -4
- data/lib/active_record/explain_registry.rb +11 -6
- data/lib/active_record/explain_subscriber.rb +1 -1
- data/lib/active_record/fixture_set/file.rb +15 -1
- data/lib/active_record/fixture_set/table_row.rb +41 -6
- data/lib/active_record/fixture_set/table_rows.rb +4 -4
- data/lib/active_record/fixtures.rb +20 -23
- data/lib/active_record/future_result.rb +139 -0
- data/lib/active_record/gem_version.rb +5 -5
- data/lib/active_record/inheritance.rb +55 -17
- data/lib/active_record/insert_all.rb +80 -14
- data/lib/active_record/integration.rb +4 -3
- data/lib/active_record/internal_metadata.rb +1 -5
- data/lib/active_record/legacy_yaml_adapter.rb +2 -39
- data/lib/active_record/locking/optimistic.rb +36 -21
- data/lib/active_record/locking/pessimistic.rb +10 -4
- data/lib/active_record/log_subscriber.rb +23 -7
- data/lib/active_record/middleware/database_selector/resolver.rb +6 -10
- data/lib/active_record/middleware/database_selector.rb +18 -6
- data/lib/active_record/middleware/shard_selector.rb +60 -0
- data/lib/active_record/migration/command_recorder.rb +8 -9
- data/lib/active_record/migration/compatibility.rb +91 -2
- data/lib/active_record/migration/join_table.rb +1 -1
- data/lib/active_record/migration.rb +115 -84
- data/lib/active_record/model_schema.rb +58 -59
- data/lib/active_record/nested_attributes.rb +13 -12
- data/lib/active_record/no_touching.rb +3 -3
- data/lib/active_record/null_relation.rb +2 -6
- data/lib/active_record/persistence.rb +228 -60
- data/lib/active_record/query_cache.rb +2 -2
- data/lib/active_record/query_logs.rb +149 -0
- data/lib/active_record/querying.rb +16 -6
- data/lib/active_record/railtie.rb +136 -22
- data/lib/active_record/railties/controller_runtime.rb +1 -1
- data/lib/active_record/railties/databases.rake +78 -136
- data/lib/active_record/readonly_attributes.rb +11 -0
- data/lib/active_record/reflection.rb +80 -49
- data/lib/active_record/relation/batches/batch_enumerator.rb +19 -5
- data/lib/active_record/relation/batches.rb +6 -6
- data/lib/active_record/relation/calculations.rb +92 -60
- data/lib/active_record/relation/delegation.rb +7 -7
- data/lib/active_record/relation/finder_methods.rb +31 -35
- data/lib/active_record/relation/merger.rb +20 -13
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +20 -1
- data/lib/active_record/relation/predicate_builder.rb +2 -6
- data/lib/active_record/relation/query_attribute.rb +5 -11
- data/lib/active_record/relation/query_methods.rb +285 -68
- data/lib/active_record/relation/record_fetch_warning.rb +7 -9
- data/lib/active_record/relation/spawn_methods.rb +2 -2
- data/lib/active_record/relation/where_clause.rb +10 -19
- data/lib/active_record/relation.rb +189 -88
- data/lib/active_record/result.rb +23 -11
- data/lib/active_record/runtime_registry.rb +9 -13
- data/lib/active_record/sanitization.rb +17 -12
- data/lib/active_record/schema.rb +38 -23
- data/lib/active_record/schema_dumper.rb +29 -19
- data/lib/active_record/schema_migration.rb +4 -4
- data/lib/active_record/scoping/default.rb +60 -13
- data/lib/active_record/scoping/named.rb +3 -11
- data/lib/active_record/scoping.rb +64 -34
- data/lib/active_record/serialization.rb +6 -1
- data/lib/active_record/signed_id.rb +3 -3
- data/lib/active_record/store.rb +2 -2
- data/lib/active_record/suppressor.rb +11 -15
- data/lib/active_record/table_metadata.rb +5 -1
- data/lib/active_record/tasks/database_tasks.rb +127 -60
- data/lib/active_record/tasks/mysql_database_tasks.rb +1 -1
- data/lib/active_record/tasks/postgresql_database_tasks.rb +19 -13
- data/lib/active_record/test_databases.rb +1 -1
- data/lib/active_record/test_fixtures.rb +9 -6
- data/lib/active_record/timestamp.rb +3 -4
- data/lib/active_record/transactions.rb +9 -14
- data/lib/active_record/translation.rb +3 -3
- data/lib/active_record/type/adapter_specific_registry.rb +32 -7
- data/lib/active_record/type/hash_lookup_type_map.rb +34 -1
- data/lib/active_record/type/internal/timezone.rb +2 -2
- data/lib/active_record/type/serialized.rb +5 -5
- data/lib/active_record/type/type_map.rb +17 -20
- data/lib/active_record/type.rb +1 -2
- data/lib/active_record/validations/associated.rb +4 -4
- data/lib/active_record/validations/presence.rb +2 -2
- data/lib/active_record/validations/uniqueness.rb +4 -4
- data/lib/active_record/version.rb +1 -1
- data/lib/active_record.rb +225 -27
- data/lib/arel/attributes/attribute.rb +0 -8
- data/lib/arel/crud.rb +28 -22
- data/lib/arel/delete_manager.rb +18 -4
- data/lib/arel/filter_predications.rb +9 -0
- data/lib/arel/insert_manager.rb +2 -3
- data/lib/arel/nodes/casted.rb +1 -1
- data/lib/arel/nodes/delete_statement.rb +12 -13
- data/lib/arel/nodes/filter.rb +10 -0
- data/lib/arel/nodes/function.rb +1 -0
- data/lib/arel/nodes/insert_statement.rb +2 -2
- data/lib/arel/nodes/select_core.rb +2 -2
- data/lib/arel/nodes/select_statement.rb +2 -2
- data/lib/arel/nodes/update_statement.rb +8 -3
- data/lib/arel/nodes.rb +1 -0
- data/lib/arel/predications.rb +11 -3
- data/lib/arel/select_manager.rb +10 -4
- data/lib/arel/table.rb +0 -1
- data/lib/arel/tree_manager.rb +0 -12
- data/lib/arel/update_manager.rb +18 -4
- data/lib/arel/visitors/dot.rb +80 -90
- data/lib/arel/visitors/mysql.rb +8 -2
- data/lib/arel/visitors/postgresql.rb +0 -10
- data/lib/arel/visitors/to_sql.rb +58 -2
- data/lib/arel.rb +2 -1
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
- data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +1 -1
- data/lib/rails/generators/active_record/model/templates/module.rb.tt +2 -2
- data/lib/rails/generators/active_record/multi_db/multi_db_generator.rb +16 -0
- data/lib/rails/generators/active_record/multi_db/templates/multi_db.rb.tt +44 -0
- metadata +58 -14
data/CHANGELOG.md
CHANGED
@@ -1,19 +1,166 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 7.0.6 (June 29, 2023) ##
|
2
|
+
|
3
|
+
* Fix autosave associations with validations added on `:base` of the associated objects.
|
4
|
+
|
5
|
+
*fatkodima*
|
6
|
+
|
7
|
+
* Fix result with anonymous PostgreSQL columns of different type from json.
|
8
|
+
|
9
|
+
*Oleksandr Avoiants*
|
10
|
+
|
11
|
+
* Preserve timestamp when setting an `ActiveSupport::TimeWithZone` value to `timestamptz` attribute.
|
12
|
+
|
13
|
+
*fatkodima*
|
14
|
+
|
15
|
+
* Fix where on association with has_one/has_many polymorphic relations.
|
16
|
+
|
17
|
+
Before:
|
18
|
+
```ruby
|
19
|
+
Treasure.where(price_estimates: PriceEstimate.all)
|
20
|
+
#=> SELECT (...) WHERE "treasures"."id" IN (SELECT "price_estimates"."estimate_of_id" FROM "price_estimates")
|
21
|
+
```
|
22
|
+
|
23
|
+
Later:
|
24
|
+
```ruby
|
25
|
+
Treasure.where(price_estimates: PriceEstimate.all)
|
26
|
+
#=> SELECT (...) WHERE "treasures"."id" IN (SELECT "price_estimates"."estimate_of_id" FROM "price_estimates" WHERE "price_estimates"."estimate_of_type" = 'Treasure')
|
27
|
+
```
|
28
|
+
|
29
|
+
*Lázaro Nixon*
|
30
|
+
|
31
|
+
* Fix decrementing counter caches on optimistically locked record deletion
|
32
|
+
|
33
|
+
*fatkodima*
|
34
|
+
|
35
|
+
* Ensure binary-destined values have binary encoding during type cast.
|
36
|
+
|
37
|
+
*Matthew Draper*
|
38
|
+
|
39
|
+
* Preserve existing column default functions when altering table in SQLite.
|
40
|
+
|
41
|
+
*fatkodima*
|
42
|
+
|
43
|
+
* Remove table alias added when using `where.missing` or `where.associated`.
|
44
|
+
|
45
|
+
*fatkodima*
|
46
|
+
|
47
|
+
* Fix `Enumerable#in_order_of` to only flatten first level to preserve nesting.
|
48
|
+
|
49
|
+
*Miha Rekar*
|
50
|
+
|
51
|
+
|
52
|
+
## Rails 7.0.5.1 (June 26, 2023) ##
|
2
53
|
|
3
54
|
* No changes.
|
4
55
|
|
56
|
+
## Rails 7.0.5 (May 24, 2023) ##
|
57
|
+
|
58
|
+
* Type cast `#attribute_changed?` `:from` and `:to` options.
|
59
|
+
|
60
|
+
*Andrew Novoselac*
|
61
|
+
|
62
|
+
* Fix `index_exists?` when column is an array.
|
63
|
+
|
64
|
+
*Eileen M. Uchitelle*
|
65
|
+
|
66
|
+
* Handle `Date` objects for PostgreSQL `timestamptz` columns.
|
67
|
+
|
68
|
+
*Alex Ghiculescu*
|
69
|
+
|
70
|
+
* Fix collation for changing column to non-string.
|
71
|
+
|
72
|
+
*Hartley McGuire*
|
73
|
+
|
74
|
+
* Map through subtype in `PostgreSQL::OID::Array`.
|
75
|
+
|
76
|
+
*Jonathan Hefner*
|
77
|
+
|
78
|
+
* Store correct environment in `internal_metadata` when run rails `db:prepare`.
|
79
|
+
|
80
|
+
*fatkodima*
|
81
|
+
|
82
|
+
* Make sure `ActiveRecord::Relation#sum` works with objects that implement `#coerce` without deprecation.
|
83
|
+
|
84
|
+
*Alex Ghiculescu*
|
85
|
+
|
86
|
+
* Fix retrieving foreign keys referencing tables named like keywords in PostgreSQL and MySQL.
|
87
|
+
|
88
|
+
*fatkodima*
|
89
|
+
|
90
|
+
* Support UUIDs in Disable Joins.
|
91
|
+
|
92
|
+
*Samuel Cochran*
|
93
|
+
|
94
|
+
* Fix Active Record's explain for queries starting with comments.
|
95
|
+
|
96
|
+
*fatkodima*
|
97
|
+
|
98
|
+
* Fix incorrectly preloading through association records when middle association has been loaded.
|
99
|
+
|
100
|
+
*Joshua Young*
|
101
|
+
|
102
|
+
* Fix where.missing and where.associated for parent/child associations.
|
103
|
+
|
104
|
+
*fatkodima*
|
105
|
+
|
106
|
+
* Fix Enumerable#in_order_of to preserve duplicates.
|
107
|
+
|
108
|
+
*fatkodima*
|
109
|
+
|
110
|
+
* Fix autoincrement on primary key for mysql.
|
111
|
+
|
112
|
+
*Eileen M. Uchitelle*
|
113
|
+
|
114
|
+
* Restore ability to redefine column in `create_table` for Rails 5.2 migrations.
|
115
|
+
|
116
|
+
*fatkodima*
|
117
|
+
|
118
|
+
* Fix schema cache dumping of virtual columns.
|
119
|
+
|
120
|
+
*fatkodima*
|
121
|
+
|
122
|
+
* Fix Active Record grouped calculations on joined tables on column present in both tables.
|
123
|
+
|
124
|
+
*fatkodima*
|
125
|
+
|
126
|
+
* Fix mutation detection for serialized attributes backed by binary columns.
|
127
|
+
|
128
|
+
*Jean Boussier*
|
129
|
+
|
130
|
+
* Fix a bug where using groups and counts with long table names would return incorrect results.
|
131
|
+
|
132
|
+
*Shota Toguchi*, *Yusaku Ono*
|
133
|
+
|
134
|
+
* Fix erroneous nil default precision on virtual datetime columns.
|
135
|
+
|
136
|
+
Prior to this change, virtual datetime columns did not have the same
|
137
|
+
default precision as regular datetime columns, resulting in the following
|
138
|
+
being erroneously equivalent:
|
5
139
|
|
6
|
-
|
140
|
+
t.virtual :name, type: datetime, as: "expression"
|
141
|
+
t.virtual :name, type: datetime, precision: nil, as: "expression"
|
142
|
+
|
143
|
+
This change fixes the default precision lookup, so virtual and regular
|
144
|
+
datetime column default precisions match.
|
145
|
+
|
146
|
+
*Sam Bostock*
|
147
|
+
|
148
|
+
* Fix a case where the query cache can return wrong values. See #46044
|
149
|
+
|
150
|
+
*Aaron Patterson*
|
151
|
+
|
152
|
+
|
153
|
+
## Rails 7.0.4.3 (March 13, 2023) ##
|
7
154
|
|
8
155
|
* No changes.
|
9
156
|
|
10
157
|
|
11
|
-
## Rails
|
158
|
+
## Rails 7.0.4.2 (January 24, 2023) ##
|
12
159
|
|
13
160
|
* No changes.
|
14
161
|
|
15
162
|
|
16
|
-
## Rails
|
163
|
+
## Rails 7.0.4.1 (January 17, 2023) ##
|
17
164
|
|
18
165
|
* Make sanitize_as_sql_comment more strict
|
19
166
|
|
@@ -22,7 +169,7 @@
|
|
22
169
|
carefully crafted input.
|
23
170
|
|
24
171
|
This commit makes the sanitization more robust by replacing any
|
25
|
-
|
172
|
+
occurrences of "/*" or "*/" with "/ *" or "* /". It also performs a
|
26
173
|
first pass to remove one surrounding comment to avoid compatibility
|
27
174
|
issues for users relying on the existing removal.
|
28
175
|
|
@@ -43,7 +190,8 @@
|
|
43
190
|
|
44
191
|
[CVE-2022-44566]
|
45
192
|
|
46
|
-
|
193
|
+
|
194
|
+
## Rails 7.0.4 (September 09, 2022) ##
|
47
195
|
|
48
196
|
* Symbol is allowed by default for YAML columns
|
49
197
|
|
@@ -56,1757 +204,2044 @@
|
|
56
204
|
|
57
205
|
*Jean Boussier*
|
58
206
|
|
59
|
-
*
|
207
|
+
* Add `timestamptz` as a time zone aware type for PostgreSQL
|
60
208
|
|
61
|
-
|
209
|
+
This is required for correctly parsing `timestamp with time zone` values in your database.
|
62
210
|
|
63
|
-
|
64
|
-
|
65
|
-
## Rails 6.1.6.1 (July 12, 2022) ##
|
66
|
-
|
67
|
-
* Change ActiveRecord::Coders::YAMLColumn default to safe_load
|
211
|
+
If you don't want this, you can opt out by adding this initializer:
|
68
212
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
* `config.active_storage.use_yaml_unsafe_load`
|
73
|
-
|
74
|
-
When set to true, this configuration option tells Rails to use the old
|
75
|
-
"unsafe" YAML loading strategy, maintaining the existing behavior but leaving
|
76
|
-
the possible escalation vulnerability in place. Setting this option to true
|
77
|
-
is *not* recommended, but can aid in upgrading.
|
78
|
-
|
79
|
-
* `config.active_record.yaml_column_permitted_classes`
|
80
|
-
|
81
|
-
The "safe YAML" loading method does not allow all classes to be deserialized
|
82
|
-
by default. This option allows you to specify classes deemed "safe" in your
|
83
|
-
application. For example, if your application uses Symbol and Time in
|
84
|
-
serialized data, you can add Symbol and Time to the allowed list as follows:
|
85
|
-
|
86
|
-
```
|
87
|
-
config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
|
213
|
+
```ruby
|
214
|
+
ActiveRecord::Base.time_zone_aware_types -= [:timestamptz]
|
88
215
|
```
|
89
216
|
|
90
|
-
|
217
|
+
*Alex Ghiculescu*
|
91
218
|
|
219
|
+
* Fix supporting timezone awareness for `tsrange` and `tstzrange` array columns.
|
92
220
|
|
93
|
-
|
221
|
+
```ruby
|
222
|
+
# In database migrations
|
223
|
+
add_column :shops, :open_hours, :tsrange, array: true
|
224
|
+
# In app config
|
225
|
+
ActiveRecord::Base.time_zone_aware_types += [:tsrange]
|
226
|
+
# In the code times are properly converted to app time zone
|
227
|
+
Shop.create!(open_hours: [Time.current..8.hour.from_now])
|
228
|
+
```
|
94
229
|
|
95
|
-
*
|
230
|
+
*Wojciech Wnętrzak*
|
96
231
|
|
232
|
+
* Resolve issue where a relation cache_version could be left stale.
|
97
233
|
|
98
|
-
|
234
|
+
Previously, when `reset` was called on a relation object it did not reset the cache_versions
|
235
|
+
ivar. This led to a confusing situation where despite having the correct data the relation
|
236
|
+
still reported a stale cache_version.
|
99
237
|
|
100
|
-
|
238
|
+
Usage:
|
101
239
|
|
240
|
+
```ruby
|
241
|
+
developers = Developer.all
|
242
|
+
developers.cache_version
|
102
243
|
|
103
|
-
|
244
|
+
Developer.update_all(updated_at: Time.now.utc + 1.second)
|
104
245
|
|
105
|
-
|
246
|
+
developers.cache_version # Stale cache_version
|
247
|
+
developers.reset
|
248
|
+
developers.cache_version # Returns the current correct cache_version
|
249
|
+
```
|
106
250
|
|
107
|
-
|
108
|
-
In Ruby 2.6, the receiver of the `String#-@` method is modified under certain circumstances.
|
109
|
-
This was later identified as a bug (https://bugs.ruby-lang.org/issues/15926) and only
|
110
|
-
fixed in Ruby 2.7.
|
251
|
+
Fixes #45341.
|
111
252
|
|
112
|
-
|
113
|
-
`ActiveRecord::ConnectionAdapters::SchemaCache#deep_deduplicate` method, which internally
|
114
|
-
calls the `String#-@` method, could also modify an input string argument in Ruby 2.6 --
|
115
|
-
changing a tainted, unfrozen string into a tainted, frozen string.
|
253
|
+
*Austen Madden*
|
116
254
|
|
117
|
-
|
255
|
+
* Fix `load_async` when called on an association proxy.
|
118
256
|
|
119
|
-
|
257
|
+
Calling `load_async` directly an association would schedule
|
258
|
+
a query but never use it.
|
120
259
|
|
121
|
-
|
122
|
-
|
260
|
+
```ruby
|
261
|
+
comments = post.comments.load_async # schedule a query
|
262
|
+
comments.to_a # perform an entirely new sync query
|
263
|
+
```
|
123
264
|
|
124
|
-
|
125
|
-
|
265
|
+
Now it does use the async query, however note that it doesn't
|
266
|
+
cause the association to be loaded.
|
126
267
|
|
127
|
-
*
|
268
|
+
*Jean Boussier*
|
128
269
|
|
129
|
-
* Fix
|
270
|
+
* Fix eager loading for models without primary keys.
|
130
271
|
|
131
|
-
*
|
272
|
+
*Anmol Chopra*, *Matt Lawrence*, and *Jonathan Hefner*
|
132
273
|
|
133
|
-
*
|
274
|
+
* `rails db:schema:{dump,load}` now checks `ENV["SCHEMA_FORMAT"]` before config
|
275
|
+
|
276
|
+
Since `rails db:structure:{dump,load}` was deprecated there wasn't a simple
|
277
|
+
way to dump a schema to both SQL and Ruby formats. You can now do this with
|
278
|
+
an environment variable. For example:
|
134
279
|
|
135
|
-
```
|
136
|
-
|
280
|
+
```
|
281
|
+
SCHEMA_FORMAT=sql rake db:schema:dump
|
137
282
|
```
|
138
283
|
|
139
|
-
|
140
|
-
responsible to detect write queries.
|
284
|
+
*Alex Ghiculescu*
|
141
285
|
|
142
|
-
|
143
|
-
not be able to handle it, but will either succeed or failed in a more correct way.
|
286
|
+
* Fix Hstore deserialize regression.
|
144
287
|
|
145
|
-
*
|
288
|
+
*edsharp*
|
146
289
|
|
147
|
-
* Ignore persisted in-memory records when merging target lists.
|
148
290
|
|
149
|
-
|
291
|
+
## Rails 7.0.3.1 (July 12, 2022) ##
|
150
292
|
|
151
|
-
*
|
152
|
-
`has_many` through relations.
|
293
|
+
* Change ActiveRecord::Coders::YAMLColumn default to safe_load
|
153
294
|
|
154
|
-
|
295
|
+
This adds two new configuration options The configuration options are as
|
296
|
+
follows:
|
155
297
|
|
156
|
-
*
|
298
|
+
* `config.active_record.use_yaml_unsafe_load`
|
157
299
|
|
158
|
-
|
159
|
-
|
300
|
+
When set to true, this configuration option tells Rails to use the old
|
301
|
+
"unsafe" YAML loading strategy, maintaining the existing behavior but leaving
|
302
|
+
the possible escalation vulnerability in place. Setting this option to true
|
303
|
+
is *not* recommended, but can aid in upgrading.
|
160
304
|
|
161
|
-
|
162
|
-
various DB management tasks.
|
305
|
+
* `config.active_record.yaml_column_permitted_classes`
|
163
306
|
|
164
|
-
|
307
|
+
The "safe YAML" loading method does not allow all classes to be deserialized
|
308
|
+
by default. This option allows you to specify classes deemed "safe" in your
|
309
|
+
application. For example, if your application uses Symbol and Time in
|
310
|
+
serialized data, you can add Symbol and Time to the allowed list as follows:
|
165
311
|
|
166
|
-
|
312
|
+
```
|
313
|
+
config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
|
314
|
+
```
|
167
315
|
|
168
|
-
|
316
|
+
[CVE-2022-32224]
|
169
317
|
|
170
|
-
*Justin Carvalho*
|
171
318
|
|
172
|
-
|
319
|
+
## Rails 7.0.3 (May 09, 2022) ##
|
173
320
|
|
174
|
-
|
321
|
+
* Some internal housekeeping on reloads could break custom `respond_to?`
|
322
|
+
methods in class objects that referenced reloadable constants. See
|
323
|
+
[#44125](https://github.com/rails/rails/issues/44125) for details.
|
175
324
|
|
176
|
-
*
|
325
|
+
*Xavier Noria*
|
177
326
|
|
178
|
-
*
|
327
|
+
* Fixed MariaDB default function support.
|
179
328
|
|
180
|
-
|
329
|
+
Defaults would be written wrong in "db/schema.rb" and not work correctly
|
330
|
+
if using `db:schema:load`. Further more the function name would be
|
331
|
+
added as string content when saving new records.
|
332
|
+
|
333
|
+
*kaspernj*
|
181
334
|
|
182
|
-
* Fix
|
335
|
+
* Fix `remove_foreign_key` with `:if_exists` option when foreign key actually exists.
|
183
336
|
|
184
337
|
*fatkodima*
|
185
338
|
|
339
|
+
* Remove `--no-comments` flag in structure dumps for PostgreSQL
|
186
340
|
|
187
|
-
|
341
|
+
This broke some apps that used custom schema comments. If you don't want
|
342
|
+
comments in your structure dump, you can use:
|
188
343
|
|
189
|
-
|
344
|
+
```ruby
|
345
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = ['--no-comments']
|
346
|
+
```
|
347
|
+
|
348
|
+
*Alex Ghiculescu*
|
190
349
|
|
350
|
+
* Use the model name as a prefix when filtering encrypted attributes from logs.
|
191
351
|
|
192
|
-
|
352
|
+
For example, when encrypting `Person#name` it will add `person.name` as a filter
|
353
|
+
parameter, instead of just `name`. This prevents unintended filtering of parameters
|
354
|
+
with a matching name in other models.
|
193
355
|
|
194
|
-
*
|
356
|
+
*Jorge Manrubia*
|
195
357
|
|
358
|
+
* Fix quoting of `ActiveSupport::Duration` and `Rational` numbers in the MySQL adapter.
|
196
359
|
|
197
|
-
|
360
|
+
*Kevin McPhillips*
|
198
361
|
|
199
|
-
*
|
362
|
+
* Fix `change_column_comment` to preserve column's AUTO_INCREMENT in the MySQL adapter
|
200
363
|
|
364
|
+
*fatkodima*
|
201
365
|
|
202
|
-
## Rails
|
366
|
+
## Rails 7.0.2.4 (April 26, 2022) ##
|
203
367
|
|
204
368
|
* No changes.
|
205
369
|
|
206
370
|
|
207
|
-
## Rails
|
371
|
+
## Rails 7.0.2.3 (March 08, 2022) ##
|
208
372
|
|
209
373
|
* No changes.
|
210
374
|
|
211
375
|
|
212
|
-
## Rails
|
376
|
+
## Rails 7.0.2.2 (February 11, 2022) ##
|
213
377
|
|
214
378
|
* No changes.
|
215
379
|
|
216
380
|
|
217
|
-
## Rails
|
381
|
+
## Rails 7.0.2.1 (February 11, 2022) ##
|
218
382
|
|
219
383
|
* No changes.
|
220
384
|
|
221
385
|
|
222
|
-
## Rails
|
386
|
+
## Rails 7.0.2 (February 08, 2022) ##
|
223
387
|
|
224
|
-
*
|
388
|
+
* Fix `PG.connect` keyword arguments deprecation warning on ruby 2.7.
|
225
389
|
|
226
|
-
*
|
390
|
+
*Nikita Vasilevsky*
|
227
391
|
|
228
|
-
*
|
392
|
+
* Fix the ability to exclude encryption params from being autofiltered.
|
229
393
|
|
230
|
-
*
|
394
|
+
*Mark Gangl*
|
231
395
|
|
232
|
-
*
|
396
|
+
* Dump the precision for datetime columns following the new defaults.
|
233
397
|
|
234
|
-
|
235
|
-
Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
|
398
|
+
*Rafael Mendonça França*
|
236
399
|
|
237
|
-
|
400
|
+
* Make sure encrypted attributes are not being filtered twice.
|
238
401
|
|
239
|
-
*
|
402
|
+
*Nikita Vasilevsky*
|
240
403
|
|
241
|
-
|
404
|
+
* Dump the database schema containing the current Rails version.
|
242
405
|
|
243
|
-
|
406
|
+
Since https://github.com/rails/rails/pull/42297, Rails now generate datetime columns
|
407
|
+
with a default precision of 6. This means that users upgrading to Rails 7.0 from 6.1,
|
408
|
+
when loading the database schema, would get the new precision value, which would not match
|
409
|
+
the production schema.
|
244
410
|
|
245
|
-
|
411
|
+
To avoid this the schema dumper will generate the new format which will include the Rails
|
412
|
+
version and will look like this:
|
246
413
|
|
247
|
-
|
414
|
+
```
|
415
|
+
ActiveRecord::Schema[7.0].define
|
416
|
+
```
|
248
417
|
|
249
|
-
|
418
|
+
When upgrading from Rails 6.1 to Rails 7.0, you can run the `rails app:update` task that will
|
419
|
+
set the current schema version to 6.1.
|
250
420
|
|
251
|
-
*
|
421
|
+
*Rafael Mendonça França*
|
252
422
|
|
253
|
-
|
423
|
+
* Fix parsing expression for PostgreSQL generated column.
|
254
424
|
|
255
|
-
*
|
425
|
+
*fatkodima*
|
256
426
|
|
257
|
-
|
427
|
+
* Fix `Mysql2::Error: Commands out of sync; you can't run this command now`
|
428
|
+
when bulk-inserting fixtures that exceed `max_allowed_packet` configuration.
|
258
429
|
|
259
|
-
*
|
260
|
-
`quoted_node` so that PostgreSQL arrays are quoted properly.
|
430
|
+
*Nikita Vasilevsky*
|
261
431
|
|
262
|
-
|
432
|
+
* Fix error when saving an association with a relation named `record`.
|
263
433
|
|
264
|
-
*
|
434
|
+
*Dorian Marié*
|
265
435
|
|
266
|
-
|
436
|
+
* Fix `MySQL::SchemaDumper` behavior about datetime precision value.
|
267
437
|
|
268
|
-
*
|
438
|
+
*y0t4*
|
269
439
|
|
270
|
-
|
440
|
+
* Improve associated with no reflection error.
|
271
441
|
|
272
|
-
*
|
442
|
+
*Nikolai*
|
273
443
|
|
274
|
-
|
444
|
+
* Fix PG.connect keyword arguments deprecation warning on ruby 2.7.
|
275
445
|
|
276
|
-
|
446
|
+
Fixes #44307.
|
277
447
|
|
278
|
-
|
279
|
-
relation set `strict_loading` to false the false wasn't considered when
|
280
|
-
deciding whether to raise/warn about strict loading.
|
448
|
+
*Nikita Vasilevsky*
|
281
449
|
|
282
|
-
|
283
|
-
class Dog < ActiveRecord::Base
|
284
|
-
self.strict_loading_by_default = true
|
450
|
+
* Fix passing options to `check_constraint` from `change_table`.
|
285
451
|
|
286
|
-
|
287
|
-
end
|
288
|
-
```
|
452
|
+
*Frederick Cheung*
|
289
453
|
|
290
|
-
In the example, `dog.treats` would still raise even though
|
291
|
-
`strict_loading` was set to false. This is a bug affecting more than
|
292
|
-
Active Storage which is why I made this PR superseding #41461. We need
|
293
|
-
to fix this for all applications since the behavior is a little
|
294
|
-
surprising. I took the test from #41461 and the code suggestion from #41453
|
295
|
-
with some additions.
|
296
454
|
|
297
|
-
|
455
|
+
## Rails 7.0.1 (January 06, 2022) ##
|
298
456
|
|
299
|
-
* Fix numericality validator without precision.
|
300
457
|
|
301
|
-
|
458
|
+
* Change `QueryMethods#in_order_of` to drop records not listed in values.
|
302
459
|
|
303
|
-
|
460
|
+
`in_order_of` now filters down to the values provided, to match the behavior of the `Enumerable` version.
|
304
461
|
|
305
|
-
*
|
462
|
+
*Kevin Newton*
|
463
|
+
|
464
|
+
* Allow named expression indexes to be revertible.
|
465
|
+
|
466
|
+
Previously, the following code would raise an error in a reversible migration executed while rolling back, due to the index name not being used in the index removal.
|
306
467
|
|
307
|
-
|
468
|
+
```ruby
|
469
|
+
add_index(:settings, "(data->'property')", using: :gin, name: :index_settings_data_property)
|
470
|
+
```
|
308
471
|
|
309
|
-
|
472
|
+
Fixes #43331.
|
310
473
|
|
311
|
-
*
|
474
|
+
*Oliver Günther*
|
312
475
|
|
313
|
-
|
476
|
+
* Better error messages when association name is invalid in the argument of `ActiveRecord::QueryMethods::WhereChain#missing`.
|
314
477
|
|
315
|
-
*
|
478
|
+
*ykpythemind*
|
316
479
|
|
317
|
-
|
480
|
+
* Fix ordered migrations for single db in multi db environment.
|
318
481
|
|
482
|
+
*Himanshu*
|
319
483
|
|
320
|
-
|
484
|
+
* Extract `on update CURRENT_TIMESTAMP` for mysql2 adapter.
|
321
485
|
|
322
|
-
*
|
486
|
+
*Kazuhiro Masuda*
|
323
487
|
|
488
|
+
* Fix incorrect argument in PostgreSQL structure dump tasks.
|
324
489
|
|
325
|
-
|
490
|
+
Updating the `--no-comment` argument added in Rails 7 to the correct `--no-comments` argument.
|
326
491
|
|
327
|
-
*
|
492
|
+
*Alex Dent*
|
328
493
|
|
494
|
+
* Fix schema dumping column default SQL values for sqlite3.
|
329
495
|
|
330
|
-
|
496
|
+
*fatkodima*
|
331
497
|
|
332
|
-
*
|
333
|
-
to the connection session.
|
498
|
+
* Correctly parse complex check constraint expressions for PostgreSQL.
|
334
499
|
|
335
|
-
*
|
500
|
+
*fatkodima*
|
336
501
|
|
337
|
-
* Fix
|
338
|
-
are enabled.
|
502
|
+
* Fix `timestamptz` attributes on PostgreSQL handle blank inputs.
|
339
503
|
|
340
|
-
*
|
504
|
+
*Alex Ghiculescu*
|
341
505
|
|
342
|
-
* Fix
|
343
|
-
an `IN` clause.
|
506
|
+
* Fix migration compatibility to create SQLite references/belongs_to column as integer when migration version is 6.0.
|
344
507
|
|
345
|
-
|
508
|
+
Reference/belongs_to in migrations with version 6.0 were creating columns as
|
509
|
+
bigint instead of integer for the SQLite Adapter.
|
346
510
|
|
347
|
-
*
|
348
|
-
with a having clause
|
511
|
+
*Marcelo Lauxen*
|
349
512
|
|
350
|
-
|
351
|
-
references an aliased select value would generate an error when
|
352
|
-
#include? was called, due to an optimisation that would generate
|
353
|
-
call #exists? on the relation instead, which effectively alters
|
354
|
-
the select values of the query (and thus removes the aliased select
|
355
|
-
values), but leaves the having clause intact. Because the having
|
356
|
-
clause is then referencing an aliased column that is no longer
|
357
|
-
present in the simplified query, an ActiveRecord::InvalidStatement
|
358
|
-
error was raised.
|
513
|
+
* Fix joining through a polymorphic association.
|
359
514
|
|
360
|
-
|
515
|
+
*Alexandre Ruban*
|
516
|
+
|
517
|
+
* Fix `QueryMethods#in_order_of` to handle empty order list.
|
361
518
|
|
362
519
|
```ruby
|
363
|
-
|
364
|
-
.joins(:posts)
|
365
|
-
.group(:id)
|
366
|
-
.having('total_posts > 2')
|
367
|
-
.include?(Author.first)
|
520
|
+
Post.in_order_of(:id, []).to_a
|
368
521
|
```
|
369
522
|
|
370
|
-
|
371
|
-
|
372
|
-
|
523
|
+
Also more explicitly set the column as secondary order, so that any other
|
524
|
+
value is still ordered.
|
525
|
+
|
526
|
+
*Jean Boussier*
|
373
527
|
|
374
|
-
|
528
|
+
* Fix `rails dbconsole` for 3-tier config.
|
375
529
|
|
376
|
-
*
|
530
|
+
*Eileen M. Uchitelle*
|
377
531
|
|
378
|
-
*
|
379
|
-
without Rails knowledge (e.g., if app gets kill -9d during long-running query or due to Rack::Timeout), app won't end
|
380
|
-
up in perpetual crash state for being inconsistent with Postgres.
|
532
|
+
* Fix quoting of column aliases generated by calculation methods.
|
381
533
|
|
382
|
-
|
534
|
+
Since the alias is derived from the table name, we can't assume the result
|
535
|
+
is a valid identifier.
|
383
536
|
|
537
|
+
```ruby
|
538
|
+
class Test < ActiveRecord::Base
|
539
|
+
self.table_name = '1abc'
|
540
|
+
end
|
541
|
+
Test.group(:id).count
|
542
|
+
# syntax error at or near "1" (ActiveRecord::StatementInvalid)
|
543
|
+
# LINE 1: SELECT COUNT(*) AS count_all, "1abc"."id" AS 1abc_id FROM "1...
|
544
|
+
```
|
384
545
|
|
385
|
-
|
546
|
+
*Jean Boussier*
|
386
547
|
|
387
|
-
* Fix possible DoS vector in PostgreSQL money type
|
388
548
|
|
389
|
-
|
390
|
-
for validating the money format in the PostgreSQL adapter. This patch
|
391
|
-
fixes the regexp.
|
549
|
+
## Rails 7.0.0 (December 15, 2021) ##
|
392
550
|
|
393
|
-
|
551
|
+
* Better handle SQL queries with invalid encoding.
|
552
|
+
|
553
|
+
```ruby
|
554
|
+
Post.create(name: "broken \xC8 UTF-8")
|
555
|
+
```
|
394
556
|
|
395
|
-
|
557
|
+
Would cause all adapters to fail in a non controlled way in the code
|
558
|
+
responsible to detect write queries.
|
396
559
|
|
397
|
-
|
560
|
+
The query is now properly passed to the database connection, which might or might
|
561
|
+
not be able to handle it, but will either succeed or failed in a more correct way.
|
398
562
|
|
563
|
+
*Jean Boussier*
|
399
564
|
|
400
|
-
|
565
|
+
* Move database and shard selection config options to a generator.
|
401
566
|
|
402
|
-
|
567
|
+
Rather than generating the config options in `production.rb` when applications are created, applications can now run a generator to create an initializer and uncomment / update options as needed. All multi-db configuration can be implemented in this initializer.
|
403
568
|
|
404
569
|
*Eileen M. Uchitelle*
|
405
570
|
|
406
|
-
* Make destroy async transactional.
|
407
571
|
|
408
|
-
|
409
|
-
case the job would enqueue even though the database deletion
|
410
|
-
rolledback putting things in a funky state.
|
572
|
+
## Rails 7.0.0.rc3 (December 14, 2021) ##
|
411
573
|
|
412
|
-
|
574
|
+
* No changes.
|
413
575
|
|
414
|
-
*Cory Gwin*
|
415
576
|
|
416
|
-
|
577
|
+
## Rails 7.0.0.rc2 (December 14, 2021) ##
|
417
578
|
|
418
|
-
|
579
|
+
* No changes.
|
419
580
|
|
420
|
-
* Connection specification now passes the "url" key as a configuration for the
|
421
|
-
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
|
422
|
-
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
|
423
|
-
are assumed to be adapter specification urls.
|
424
581
|
|
425
|
-
|
582
|
+
## Rails 7.0.0.rc1 (December 06, 2021) ##
|
426
583
|
|
427
|
-
|
584
|
+
* Remove deprecated `ActiveRecord::DatabaseConfigurations::DatabaseConfig#spec_name`.
|
428
585
|
|
429
|
-
*
|
586
|
+
*Rafael Mendonça França*
|
430
587
|
|
431
|
-
|
588
|
+
* Remove deprecated `ActiveRecord::Connection#in_clause_length`.
|
432
589
|
|
433
|
-
*
|
590
|
+
*Rafael Mendonça França*
|
591
|
+
|
592
|
+
* Remove deprecated `ActiveRecord::Connection#allowed_index_name_length`.
|
593
|
+
|
594
|
+
*Rafael Mendonça França*
|
434
595
|
|
435
|
-
|
596
|
+
* Remove deprecated `ActiveRecord::Base#remove_connection`.
|
436
597
|
|
437
|
-
*
|
598
|
+
*Rafael Mendonça França*
|
438
599
|
|
439
|
-
|
600
|
+
* Load STI Models in fixtures
|
440
601
|
|
441
|
-
|
602
|
+
Data from Fixtures now loads based on the specific class for models with
|
603
|
+
Single Table Inheritance. This affects enums defined in subclasses, previously
|
604
|
+
the value of these fields was not parsed and remained `nil`
|
442
605
|
|
443
|
-
*
|
606
|
+
*Andres Howard*
|
444
607
|
|
445
|
-
*
|
608
|
+
* `#authenticate` returns false when the password is blank instead of raising an error.
|
446
609
|
|
447
|
-
*
|
610
|
+
*Muhammad Muhammad Ibrahim*
|
448
611
|
|
612
|
+
* Fix `ActiveRecord::QueryMethods#in_order_of` behavior for integer enums.
|
449
613
|
|
450
|
-
|
614
|
+
`ActiveRecord::QueryMethods#in_order_of` didn't work as expected for enums stored as integers in the database when passing an array of strings or symbols as the order argument. This unexpected behavior occurred because the string or symbol values were not casted to match the integers in the database.
|
451
615
|
|
452
|
-
|
616
|
+
The following example now works as expected:
|
453
617
|
|
454
|
-
|
618
|
+
```ruby
|
619
|
+
class Book < ApplicationRecord
|
620
|
+
enum status: [:proposed, :written, :published]
|
621
|
+
end
|
455
622
|
|
456
|
-
|
623
|
+
Book.in_order_of(:status, %w[written published proposed])
|
624
|
+
```
|
457
625
|
|
458
|
-
*
|
626
|
+
*Alexandre Ruban*
|
459
627
|
|
460
|
-
*
|
628
|
+
* Ignore persisted in-memory records when merging target lists.
|
461
629
|
|
462
|
-
*
|
630
|
+
*Kevin Sjöberg*
|
463
631
|
|
464
|
-
*
|
632
|
+
* Add a new option `:update_only` to `upsert_all` to configure the list of columns to update in case of conflict.
|
465
633
|
|
466
|
-
|
634
|
+
Before, you could only customize the update SQL sentence via `:on_duplicate`. There is now a new option `:update_only` that lets you provide a list of columns to update in case of conflict:
|
467
635
|
|
468
|
-
|
636
|
+
```ruby
|
637
|
+
Commodity.upsert_all(
|
638
|
+
[
|
639
|
+
{ id: 2, name: "Copper", price: 4.84 },
|
640
|
+
{ id: 4, name: "Gold", price: 1380.87 },
|
641
|
+
{ id: 6, name: "Aluminium", price: 0.35 }
|
642
|
+
],
|
643
|
+
update_only: [:price] # Only prices will be updated
|
644
|
+
)
|
645
|
+
```
|
469
646
|
|
470
|
-
*
|
647
|
+
*Jorge Manrubia*
|
471
648
|
|
472
|
-
*
|
649
|
+
* Remove deprecated `ActiveRecord::Result#map!` and `ActiveRecord::Result#collect!`.
|
473
650
|
|
474
|
-
*
|
651
|
+
*Rafael Mendonça França*
|
475
652
|
|
476
|
-
*
|
653
|
+
* Remove deprecated `ActiveRecord::Base.configurations.to_h`.
|
477
654
|
|
478
655
|
*Rafael Mendonça França*
|
479
656
|
|
480
|
-
*
|
657
|
+
* Remove deprecated `ActiveRecord::Base.configurations.default_hash`.
|
481
658
|
|
482
|
-
*
|
659
|
+
*Rafael Mendonça França*
|
483
660
|
|
484
|
-
*
|
661
|
+
* Remove deprecated `ActiveRecord::Base.arel_attribute`.
|
485
662
|
|
486
|
-
*
|
663
|
+
*Rafael Mendonça França*
|
487
664
|
|
488
|
-
*
|
665
|
+
* Remove deprecated `ActiveRecord::Base.connection_config`.
|
489
666
|
|
490
|
-
|
491
|
-
to throw an error saying :polymorphic would not be a valid option.
|
667
|
+
*Rafael Mendonça França*
|
492
668
|
|
493
|
-
|
669
|
+
* Filter attributes in SQL logs
|
494
670
|
|
495
|
-
|
671
|
+
Previously, SQL queries in logs containing `ActiveRecord::Base.filter_attributes` were not filtered.
|
496
672
|
|
497
|
-
|
673
|
+
Now, the filter attributes will be masked `[FILTERED]` in the logs when `prepared_statement` is enabled.
|
498
674
|
|
499
|
-
|
500
|
-
|
501
|
-
|
675
|
+
```
|
676
|
+
# Before:
|
677
|
+
Foo Load (0.2ms) SELECT "foos".* FROM "foos" WHERE "foos"."passw" = ? LIMIT ? [["passw", "hello"], ["LIMIT", 1]]
|
502
678
|
|
503
|
-
|
504
|
-
|
679
|
+
# After:
|
680
|
+
Foo Load (0.5ms) SELECT "foos".* FROM "foos" WHERE "foos"."passw" = ? LIMIT ? [["passw", "[FILTERED]"], ["LIMIT", 1]]
|
505
681
|
```
|
506
682
|
|
507
|
-
*
|
683
|
+
*Aishwarya Subramanian*
|
508
684
|
|
685
|
+
* Remove deprecated `Tasks::DatabaseTasks.spec`.
|
509
686
|
|
510
|
-
|
687
|
+
*Rafael Mendonça França*
|
511
688
|
|
512
|
-
*
|
689
|
+
* Remove deprecated `Tasks::DatabaseTasks.current_config`.
|
513
690
|
|
514
|
-
|
691
|
+
*Rafael Mendonça França*
|
515
692
|
|
516
|
-
|
693
|
+
* Deprecate `Tasks::DatabaseTasks.schema_file_type`.
|
517
694
|
|
518
|
-
*
|
695
|
+
*Rafael Mendonça França*
|
696
|
+
|
697
|
+
* Remove deprecated `Tasks::DatabaseTasks.dump_filename`.
|
519
698
|
|
520
699
|
*Rafael Mendonça França*
|
521
700
|
|
522
|
-
*
|
701
|
+
* Remove deprecated `Tasks::DatabaseTasks.schema_file`.
|
702
|
+
|
703
|
+
*Rafael Mendonça França*
|
523
704
|
|
524
|
-
|
705
|
+
* Remove deprecated `environment` and `name` arguments from `Tasks::DatabaseTasks.schema_up_to_date?`.
|
525
706
|
|
526
|
-
*
|
707
|
+
*Rafael Mendonça França*
|
527
708
|
|
528
|
-
*
|
709
|
+
* Merging conditions on the same column no longer maintain both conditions,
|
710
|
+
and will be consistently replaced by the latter condition.
|
529
711
|
|
530
712
|
```ruby
|
531
|
-
|
532
|
-
|
713
|
+
# Rails 6.1 (IN clause is replaced by merger side equality condition)
|
714
|
+
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
715
|
+
# Rails 6.1 (both conflict conditions exists, deprecated)
|
716
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
|
717
|
+
# Rails 6.1 with rewhere to migrate to Rails 7.0's behavior
|
718
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
|
719
|
+
# Rails 7.0 (same behavior with IN clause, mergee side condition is consistently replaced)
|
720
|
+
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
721
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
|
533
722
|
|
534
|
-
|
535
|
-
@author = author
|
536
|
-
end
|
537
|
-
end
|
723
|
+
*Rafael Mendonça França*
|
538
724
|
|
539
|
-
|
540
|
-
```
|
725
|
+
* Remove deprecated support to `Model.reorder(nil).first` to search using non-deterministic order.
|
541
726
|
|
542
|
-
*
|
727
|
+
*Rafael Mendonça França*
|
543
728
|
|
544
|
-
*
|
729
|
+
* Remove deprecated rake tasks:
|
545
730
|
|
546
|
-
|
731
|
+
* `db:schema:load_if_ruby`
|
732
|
+
* `db:structure:dump`
|
733
|
+
* `db:structure:load`
|
734
|
+
* `db:structure:load_if_sql`
|
735
|
+
* `db:structure:dump:#{name}`
|
736
|
+
* `db:structure:load:#{name}`
|
737
|
+
* `db:test:load_structure`
|
738
|
+
* `db:test:load_structure:#{name}`
|
547
739
|
|
548
|
-
|
740
|
+
*Rafael Mendonça França*
|
549
741
|
|
550
|
-
|
551
|
-
MealsRecord.connected_to(role: :reading) do
|
552
|
-
Dog.first # read from animals replica
|
553
|
-
Dinner.first # read from meals replica
|
554
|
-
Person.first # read from primary writer
|
555
|
-
end
|
556
|
-
end
|
742
|
+
* Remove deprecated `DatabaseConfig#config` method.
|
557
743
|
|
558
|
-
|
744
|
+
*Rafael Mendonça França*
|
559
745
|
|
560
|
-
|
561
|
-
Dog.first # read from animals replica
|
562
|
-
Dinner.first # read from meals replica
|
563
|
-
Person.first # read from primary writer
|
564
|
-
end
|
746
|
+
* Rollback transactions when the block returns earlier than expected.
|
565
747
|
|
566
|
-
|
748
|
+
Before this change, when a transaction block returned early, the transaction would be committed.
|
749
|
+
|
750
|
+
The problem is that timeouts triggered inside the transaction block was also making the incomplete transaction
|
751
|
+
to be committed, so in order to avoid this mistake, the transaction block is rolled back.
|
567
752
|
|
568
|
-
*
|
753
|
+
*Rafael Mendonça França*
|
569
754
|
|
570
|
-
|
755
|
+
* Add middleware for automatic shard swapping.
|
571
756
|
|
572
|
-
|
757
|
+
Provides a basic middleware to perform automatic shard swapping. Applications will provide a resolver which will determine for an individual request which shard should be used. Example:
|
573
758
|
|
574
|
-
|
759
|
+
```ruby
|
760
|
+
config.active_record.shard_resolver = ->(request) {
|
761
|
+
subdomain = request.subdomain
|
762
|
+
tenant = Tenant.find_by_subdomain!(subdomain)
|
763
|
+
tenant.shard
|
764
|
+
}
|
765
|
+
```
|
575
766
|
|
576
|
-
|
767
|
+
See guides for more details.
|
577
768
|
|
578
|
-
|
769
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
579
770
|
|
580
|
-
|
771
|
+
* Remove deprecated support to pass a column to `type_cast`.
|
581
772
|
|
582
|
-
*
|
773
|
+
*Rafael Mendonça França*
|
583
774
|
|
584
|
-
|
775
|
+
* Remove deprecated support to type cast to database values `ActiveRecord::Base` objects.
|
585
776
|
|
586
|
-
|
777
|
+
*Rafael Mendonça França*
|
587
778
|
|
588
|
-
|
779
|
+
* Remove deprecated support to quote `ActiveRecord::Base` objects.
|
589
780
|
|
590
|
-
*
|
781
|
+
*Rafael Mendonça França*
|
591
782
|
|
592
|
-
*
|
593
|
-
no longer enforce case sensitive comparison by default.
|
783
|
+
* Remove deprecacated support to resolve connection using `"primary"` as connection specification name.
|
594
784
|
|
595
|
-
*
|
785
|
+
*Rafael Mendonça França*
|
596
786
|
|
597
|
-
* Remove
|
787
|
+
* Remove deprecation warning when using `:interval` column is used in PostgreSQL database.
|
598
788
|
|
599
|
-
`
|
600
|
-
`table_name_length`
|
601
|
-
`columns_per_table`
|
602
|
-
`indexes_per_table`
|
603
|
-
`columns_per_multicolumn_index`
|
604
|
-
`sql_query_length`
|
605
|
-
`joins_per_query`
|
789
|
+
Now, interval columns will return `ActiveSupport::Duration` objects instead of strings.
|
606
790
|
|
607
|
-
|
791
|
+
To keep the old behavior, you can add this line to your model:
|
608
792
|
|
609
|
-
|
793
|
+
```ruby
|
794
|
+
attribute :column, :string
|
795
|
+
```
|
610
796
|
|
611
797
|
*Rafael Mendonça França*
|
612
798
|
|
613
|
-
* Remove deprecated `ActiveRecord::
|
799
|
+
* Remove deprecated support to YAML load `ActiveRecord::Base` instance in the Rails 4.2 and 4.1 formats.
|
614
800
|
|
615
801
|
*Rafael Mendonça França*
|
616
802
|
|
617
|
-
* Remove deprecated `
|
803
|
+
* Remove deprecated option `:spec_name` in the `configs_for` method.
|
618
804
|
|
619
805
|
*Rafael Mendonça França*
|
620
806
|
|
621
|
-
* Remove deprecated
|
807
|
+
* Remove deprecated `ActiveRecord::Base.allow_unsafe_raw_sql`.
|
622
808
|
|
623
809
|
*Rafael Mendonça França*
|
624
810
|
|
625
|
-
*
|
811
|
+
* Fix regression bug that caused ignoring additional conditions for preloading has_many-through relations.
|
626
812
|
|
627
|
-
|
813
|
+
Fixes #43132
|
628
814
|
|
629
|
-
*
|
815
|
+
*Alexander Pauly*
|
630
816
|
|
631
|
-
|
817
|
+
* Fix `has_many` inversing recursion on models with recursive associations.
|
632
818
|
|
633
|
-
*
|
634
|
-
in initialization block and callbacks.
|
819
|
+
*Gannon McGibbon*
|
635
820
|
|
636
|
-
|
821
|
+
* Add `accepts_nested_attributes_for` support for `delegated_type`
|
637
822
|
|
638
|
-
|
639
|
-
|
640
|
-
|
823
|
+
```ruby
|
824
|
+
class Entry < ApplicationRecord
|
825
|
+
delegated_type :entryable, types: %w[ Message Comment ]
|
826
|
+
accepts_nested_attributes_for :entryable
|
827
|
+
end
|
641
828
|
|
642
|
-
|
829
|
+
entry = Entry.create(entryable_type: 'Message', entryable_attributes: { content: 'Hello world' })
|
830
|
+
# => #<Entry:0x00>
|
831
|
+
# id: 1
|
832
|
+
# entryable_id: 1,
|
833
|
+
# entryable_type: 'Message'
|
834
|
+
# ...>
|
835
|
+
|
836
|
+
entry.entryable
|
837
|
+
# => #<Message:0x01>
|
838
|
+
# id: 1
|
839
|
+
# content: 'Hello world'
|
840
|
+
# ...>
|
841
|
+
```
|
643
842
|
|
644
|
-
|
645
|
-
User.find_by(name: "David") # => #<User name: "David", ...>
|
646
|
-
end
|
843
|
+
Previously it would raise an error:
|
647
844
|
|
648
|
-
|
845
|
+
```ruby
|
846
|
+
Entry.create(entryable_type: 'Message', entryable_attributes: { content: 'Hello world' })
|
847
|
+
# ArgumentError: Cannot build association `entryable'. Are you trying to build a polymorphic one-to-one association?
|
848
|
+
```
|
649
849
|
|
650
|
-
*
|
850
|
+
*Sjors Baltus*
|
651
851
|
|
652
|
-
|
653
|
-
scope :david, -> { User.where(name: "David") }
|
654
|
-
end
|
852
|
+
* Use subquery for DELETE with GROUP_BY and HAVING clauses.
|
655
853
|
|
656
|
-
|
854
|
+
Prior to this change, deletes with GROUP_BY and HAVING were returning an error.
|
657
855
|
|
658
|
-
|
659
|
-
# SELECT * FROM users WHERE name = 'John' AND name = 'David'
|
856
|
+
After this change, GROUP_BY and HAVING are valid clauses in DELETE queries, generating the following query:
|
660
857
|
|
661
|
-
|
858
|
+
```sql
|
859
|
+
DELETE FROM "posts" WHERE "posts"."id" IN (
|
860
|
+
SELECT "posts"."id" FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id" GROUP BY "posts"."id" HAVING (count(comments.id) >= 2))
|
861
|
+
) [["flagged", "t"]]
|
862
|
+
```
|
662
863
|
|
663
|
-
|
664
|
-
# SELECT * FROM users WHERE name = 'David'
|
864
|
+
*Ignacio Chiazzo Cardarello*
|
665
865
|
|
666
|
-
|
866
|
+
* Use subquery for UPDATE with GROUP_BY and HAVING clauses.
|
667
867
|
|
668
|
-
|
868
|
+
Prior to this change, updates with GROUP_BY and HAVING were being ignored, generating a SQL like this:
|
669
869
|
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
870
|
+
```sql
|
871
|
+
UPDATE "posts" SET "flagged" = ? WHERE "posts"."id" IN (
|
872
|
+
SELECT "posts"."id" FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
|
873
|
+
) [["flagged", "t"]]
|
874
|
+
```
|
675
875
|
|
676
|
-
|
876
|
+
After this change, GROUP_BY and HAVING clauses are used as a subquery in updates, like this:
|
677
877
|
|
678
|
-
|
878
|
+
```sql
|
879
|
+
UPDATE "posts" SET "flagged" = ? WHERE "posts"."id" IN (
|
880
|
+
SELECT "posts"."id" FROM "posts" INNER JOIN "comments" ON "comments"."post_id" = "posts"."id"
|
881
|
+
GROUP BY posts.id HAVING (count(comments.id) >= 2)
|
882
|
+
) [["flagged", "t"]]
|
883
|
+
```
|
679
884
|
|
680
|
-
|
885
|
+
*Ignacio Chiazzo Cardarello*
|
681
886
|
|
682
|
-
|
683
|
-
# SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
|
887
|
+
* Add support for setting the filename of the schema or structure dump in the database config.
|
684
888
|
|
685
|
-
|
889
|
+
Applications may now set their the filename or path of the schema / structure dump file in their database configuration.
|
686
890
|
|
687
|
-
|
688
|
-
|
891
|
+
```yaml
|
892
|
+
production:
|
893
|
+
primary:
|
894
|
+
database: my_db
|
895
|
+
schema_dump: my_schema_dump_filename.rb
|
896
|
+
animals:
|
897
|
+
database: animals_db
|
898
|
+
schema_dump: false
|
899
|
+
```
|
689
900
|
|
690
|
-
|
901
|
+
The filename set in `schema_dump` will be used by the application. If set to `false` the schema will not be dumped. The database tasks are responsible for adding the database directory to the filename. If a full path is provided, the Rails tasks will use that instead of `ActiveRecord::DatabaseTasks.db_dir`.
|
691
902
|
|
692
|
-
*
|
903
|
+
*Eileen M. Uchitelle*, *Ryan Kerr*
|
693
904
|
|
694
|
-
|
905
|
+
* Add `ActiveRecord::Base.prohibit_shard_swapping` to prevent attempts to change the shard within a block.
|
695
906
|
|
696
|
-
*
|
907
|
+
*John Crepezzi*, *Eileen M. Uchitelle*
|
697
908
|
|
698
|
-
|
909
|
+
* Filter unchanged attributes with default function from insert query when `partial_inserts` is disabled.
|
699
910
|
|
700
|
-
*
|
911
|
+
*Akshay Birajdar*, *Jacopo Beschi*
|
701
912
|
|
702
|
-
|
913
|
+
* Add support for FILTER clause (SQL:2003) to Arel.
|
703
914
|
|
704
|
-
|
705
|
-
message using `config.active_record.suppress_multiple_database_warning`.
|
915
|
+
Currently supported by PostgreSQL 9.4+ and SQLite 3.30+.
|
706
916
|
|
707
|
-
*
|
917
|
+
*Andrey Novikov*
|
708
918
|
|
709
|
-
*
|
919
|
+
* Automatically set timestamps on record creation during bulk insert/upsert
|
710
920
|
|
711
|
-
|
921
|
+
Prior to this change, only updates during an upsert operation (e.g. `upsert_all`) would touch timestamps (`updated_{at,on}`). Now, record creations also touch timestamp columns (`{created,updated}_{at,on}`).
|
712
922
|
|
713
|
-
|
923
|
+
This behaviour is controlled by the `<model>.record_timestamps` config, matching the behaviour of `create`, `update`, etc. It can also be overridden by using the `record_timestamps:` keyword argument.
|
714
924
|
|
715
|
-
|
925
|
+
Note that this means `upsert_all` on models with `record_timestamps = false` will no longer touch `updated_{at,on}` automatically.
|
716
926
|
|
717
|
-
|
718
|
-
ActiveRecord::Base.connected_to(role: :reading) do
|
719
|
-
User.first # reads from default replica
|
720
|
-
Dog.first # reads from default replica
|
927
|
+
*Sam Bostock*
|
721
928
|
|
722
|
-
|
723
|
-
User.first # reads from default replica
|
724
|
-
Dog.first # reads from shard one primary
|
725
|
-
end
|
929
|
+
* Don't require `role` when passing `shard` to `connected_to`.
|
726
930
|
|
727
|
-
|
728
|
-
Dog.first # reads from default replica
|
931
|
+
`connected_to` can now be called with a `shard` only. Note that `role` is still inherited if `connected_to` calls are nested.
|
729
932
|
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
933
|
+
*Eileen M. Uchitelle*
|
934
|
+
|
935
|
+
* Add option to lazily load the schema cache on the connection.
|
936
|
+
|
937
|
+
Previously, the only way to load the schema cache in Active Record was through the Railtie on boot. This option provides the ability to load the schema cache on the connection after it's been established. Loading the cache lazily on the connection can be beneficial for Rails applications that use multiple databases because it will load the cache at the time the connection is established. Currently Railties doesn't have access to the connections before boot.
|
938
|
+
|
939
|
+
To use the cache, set `config.active_record.lazily_load_schema_cache = true` in your application configuration. In addition a `schema_cache_path` should be set in your database configuration if you don't want to use the default "db/schema_cache.yml" path.
|
940
|
+
|
941
|
+
*Eileen M. Uchitelle*
|
942
|
+
|
943
|
+
* Allow automatic `inverse_of` detection for associations with scopes.
|
944
|
+
|
945
|
+
Automatic `inverse_of` detection now works for associations with scopes. For
|
946
|
+
example, the `comments` association here now automatically detects
|
947
|
+
`inverse_of: :post`, so we don't need to pass that option:
|
948
|
+
|
949
|
+
```ruby
|
950
|
+
class Post < ActiveRecord::Base
|
951
|
+
has_many :comments, -> { visible }
|
952
|
+
end
|
953
|
+
|
954
|
+
class Comment < ActiveRecord::Base
|
955
|
+
belongs_to :post
|
734
956
|
end
|
735
957
|
```
|
736
958
|
|
737
|
-
|
959
|
+
Note that the automatic detection still won't work if the inverse
|
960
|
+
association has a scope. In this example a scope on the `post` association
|
961
|
+
would still prevent Rails from finding the inverse for the `comments`
|
962
|
+
association.
|
963
|
+
|
964
|
+
This will be the default for new apps in Rails 7. To opt in:
|
965
|
+
|
966
|
+
```ruby
|
967
|
+
config.active_record.automatic_scope_inversing = true
|
968
|
+
```
|
969
|
+
|
970
|
+
*Daniel Colson*, *Chris Bloom*
|
971
|
+
|
972
|
+
* Accept optional transaction args to `ActiveRecord::Locking::Pessimistic#with_lock`
|
738
973
|
|
739
|
-
|
974
|
+
`#with_lock` now accepts transaction options like `requires_new:`,
|
975
|
+
`isolation:`, and `joinable:`
|
740
976
|
|
741
|
-
*
|
977
|
+
*John Mileham*
|
742
978
|
|
743
|
-
*
|
979
|
+
* Adds support for deferrable foreign key constraints in PostgreSQL.
|
744
980
|
|
745
|
-
|
981
|
+
By default, foreign key constraints in PostgreSQL are checked after each statement. This works for most use cases,
|
982
|
+
but becomes a major limitation when creating related records before the parent record is inserted into the database.
|
983
|
+
One example of this is looking up / creating a person via one or more unique alias.
|
746
984
|
|
747
985
|
```ruby
|
748
|
-
|
749
|
-
|
750
|
-
|
986
|
+
Person.transaction do
|
987
|
+
alias = Alias
|
988
|
+
.create_with(user_id: SecureRandom.uuid)
|
989
|
+
.create_or_find_by(name: "DHH")
|
990
|
+
|
991
|
+
person = Person
|
992
|
+
.create_with(name: "David Heinemeier Hansson")
|
993
|
+
.create_or_find_by(id: alias.user_id)
|
994
|
+
end
|
751
995
|
```
|
752
996
|
|
753
|
-
|
997
|
+
Using the default behavior, the transaction would fail when executing the first `INSERT` statement.
|
754
998
|
|
755
|
-
|
999
|
+
By passing the `:deferrable` option to the `add_foreign_key` statement in migrations, it's possible to defer this
|
1000
|
+
check.
|
756
1001
|
|
757
|
-
|
1002
|
+
```ruby
|
1003
|
+
add_foreign_key :aliases, :person, deferrable: true
|
1004
|
+
```
|
758
1005
|
|
759
|
-
|
1006
|
+
Passing `deferrable: true` doesn't change the default behavior, but allows manually deferring the check using
|
1007
|
+
`SET CONSTRAINTS ALL DEFERRED` within a transaction. This will cause the foreign keys to be checked after the
|
1008
|
+
transaction.
|
760
1009
|
|
761
|
-
|
1010
|
+
It's also possible to adjust the default behavior from an immediate check (after the statement), to a deferred check
|
1011
|
+
(after the transaction):
|
762
1012
|
|
763
1013
|
```ruby
|
764
|
-
|
765
|
-
validates_uniqueness_of :title, conditions: ->(article) {
|
766
|
-
published_at = article.published_at
|
767
|
-
where(published_at: published_at.beginning_of_year..published_at.end_of_year)
|
768
|
-
}
|
769
|
-
end
|
1014
|
+
add_foreign_key :aliases, :person, deferrable: :deferred
|
770
1015
|
```
|
771
1016
|
|
772
|
-
*
|
1017
|
+
*Benedikt Deicke*
|
1018
|
+
|
1019
|
+
* Allow configuring Postgres password through the socket URL.
|
1020
|
+
|
1021
|
+
For example:
|
1022
|
+
```ruby
|
1023
|
+
ActiveRecord::DatabaseConfigurations::UrlConfig.new(
|
1024
|
+
:production, :production, 'postgres:///?user=user&password=secret&dbname=app', {}
|
1025
|
+
).configuration_hash
|
1026
|
+
```
|
773
1027
|
|
774
|
-
|
775
|
-
total number of rows affected, just like their non-batched counterparts.
|
1028
|
+
will now return,
|
776
1029
|
|
777
1030
|
```ruby
|
778
|
-
|
779
|
-
Person.in_batches.delete_all # => 42
|
1031
|
+
{ :user=>"user", :password=>"secret", :dbname=>"app", :adapter=>"postgresql" }
|
780
1032
|
```
|
781
1033
|
|
782
|
-
|
1034
|
+
*Abeid Ahmed*
|
783
1035
|
|
784
|
-
|
1036
|
+
* PostgreSQL: support custom enum types
|
785
1037
|
|
786
|
-
|
787
|
-
`ActiveSupport::Duration` when loading records from database and
|
788
|
-
serialization to ISO 8601 formatted duration string on save.
|
789
|
-
Add support to define a column in migrations and get it in a schema dump.
|
790
|
-
Optional column precision is supported.
|
1038
|
+
In migrations, use `create_enum` to add a new enum type, and `t.enum` to add a column.
|
791
1039
|
|
792
|
-
|
1040
|
+
```ruby
|
1041
|
+
def up
|
1042
|
+
create_enum :mood, ["happy", "sad"]
|
793
1043
|
|
794
|
-
|
1044
|
+
change_table :cats do |t|
|
1045
|
+
t.enum :current_mood, enum_type: "mood", default: "happy", null: false
|
1046
|
+
end
|
1047
|
+
end
|
1048
|
+
```
|
795
1049
|
|
796
|
-
|
1050
|
+
Enums will be presented correctly in `schema.rb`. Note that this is only supported by
|
1051
|
+
the PostgreSQL adapter.
|
797
1052
|
|
798
|
-
|
1053
|
+
*Alex Ghiculescu*
|
799
1054
|
|
800
|
-
|
1055
|
+
* Avoid COMMENT statements in PostgreSQL structure dumps
|
801
1056
|
|
802
|
-
|
803
|
-
|
804
|
-
t.interval :duration
|
805
|
-
end
|
1057
|
+
COMMENT statements are now omitted from the output of `db:structure:dump` when using PostgreSQL >= 11.
|
1058
|
+
This allows loading the dump without a pgsql superuser account.
|
806
1059
|
|
807
|
-
|
808
|
-
attribute :duration, :interval
|
809
|
-
end
|
1060
|
+
Fixes #36816, #43107.
|
810
1061
|
|
811
|
-
|
812
|
-
Event.last.duration # => 2 days
|
813
|
-
Event.last.duration.iso8601 # => "P2D"
|
814
|
-
Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
|
815
|
-
Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
|
1062
|
+
*Janosch Müller*
|
816
1063
|
|
817
|
-
|
1064
|
+
* Add support for generated columns in PostgreSQL adapter
|
818
1065
|
|
819
|
-
|
1066
|
+
Generated columns are supported since version 12.0 of PostgreSQL. This adds
|
1067
|
+
support of those to the PostgreSQL adapter.
|
820
1068
|
|
821
1069
|
```ruby
|
822
|
-
|
823
|
-
|
1070
|
+
create_table :users do |t|
|
1071
|
+
t.string :name
|
1072
|
+
t.virtual :name_upcased, type: :string, as: 'upper(name)', stored: true
|
824
1073
|
end
|
825
1074
|
```
|
826
1075
|
|
827
|
-
|
1076
|
+
*Michał Begejowicz*
|
828
1077
|
|
829
|
-
*DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
|
830
1078
|
|
831
|
-
|
1079
|
+
## Rails 7.0.0.alpha2 (September 15, 2021) ##
|
832
1080
|
|
833
|
-
|
1081
|
+
* No changes.
|
834
1082
|
|
835
|
-
* `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
|
836
1083
|
|
837
|
-
|
1084
|
+
## Rails 7.0.0.alpha1 (September 15, 2021) ##
|
838
1085
|
|
839
|
-
|
1086
|
+
* Remove warning when overwriting existing scopes
|
840
1087
|
|
841
|
-
|
842
|
-
`ActiveRecord::StatementInvalid` when they encounter a connection error.
|
1088
|
+
Removes the following unnecessary warning message that appeared when overwriting existing scopes
|
843
1089
|
|
844
|
-
|
1090
|
+
```
|
1091
|
+
Creating scope :my_scope_name. Overwriting existing method "MyClass.my_scope_name" when overwriting existing scopes
|
1092
|
+
```
|
845
1093
|
|
846
|
-
*
|
847
|
-
`ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
|
1094
|
+
*Weston Ganger*
|
848
1095
|
|
849
|
-
|
1096
|
+
* Use full precision for `updated_at` in `insert_all`/`upsert_all`
|
850
1097
|
|
851
|
-
|
1098
|
+
`CURRENT_TIMESTAMP` provides differing precision depending on the database,
|
1099
|
+
and not all databases support explicitly specifying additional precision.
|
852
1100
|
|
853
|
-
|
1101
|
+
Instead, we delegate to the new `connection.high_precision_current_timestamp`
|
1102
|
+
for the SQL to produce a high precision timestamp on the current database.
|
854
1103
|
|
855
|
-
|
1104
|
+
Fixes #42992
|
856
1105
|
|
857
|
-
|
1106
|
+
*Sam Bostock*
|
858
1107
|
|
859
|
-
|
1108
|
+
* Add ssl support for postgresql database tasks
|
860
1109
|
|
861
|
-
|
1110
|
+
Add `PGSSLMODE`, `PGSSLCERT`, `PGSSLKEY` and `PGSSLROOTCERT` to pg_env from database config
|
1111
|
+
when running postgresql database tasks.
|
862
1112
|
|
863
|
-
```
|
864
|
-
|
865
|
-
enum label: [:default, :child]
|
866
|
-
has_many :children, class_name: "Comment", foreign_key: :parent_id
|
867
|
-
end
|
1113
|
+
```yaml
|
1114
|
+
# config/database.yml
|
868
1115
|
|
869
|
-
|
870
|
-
|
1116
|
+
production:
|
1117
|
+
sslmode: verify-full
|
1118
|
+
sslcert: client.crt
|
1119
|
+
sslkey: client.key
|
1120
|
+
sslrootcert: ca.crt
|
871
1121
|
```
|
872
1122
|
|
873
|
-
|
1123
|
+
Environment variables
|
874
1124
|
|
875
|
-
|
1125
|
+
```
|
1126
|
+
PGSSLMODE=verify-full
|
1127
|
+
PGSSLCERT=client.crt
|
1128
|
+
PGSSLKEY=client.key
|
1129
|
+
PGSSLROOTCERT=ca.crt
|
1130
|
+
```
|
876
1131
|
|
877
|
-
|
878
|
-
by `store_full_sti_class` class attribute.
|
1132
|
+
Fixes #42994
|
879
1133
|
|
880
|
-
|
1134
|
+
*Michael Bayucot*
|
881
1135
|
|
882
|
-
|
1136
|
+
* Avoid scoping update callbacks in `ActiveRecord::Relation#update!`.
|
883
1137
|
|
884
|
-
|
885
|
-
|
886
|
-
depending on `config.active_record.schema_format` configuration value.
|
1138
|
+
Making it consistent with how scoping is applied only to the query in `ActiveRecord::Relation#update`
|
1139
|
+
and not also to the callbacks from the update itself.
|
887
1140
|
|
888
|
-
*
|
1141
|
+
*Dylan Thacker-Smith*
|
889
1142
|
|
890
|
-
*
|
1143
|
+
* Fix 2 cases that inferred polymorphic class from the association's `foreign_type`
|
1144
|
+
using `String#constantize` instead of the model's `polymorphic_class_for`.
|
891
1145
|
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
post.body # => ActiveModel::MissingAttributeError
|
1146
|
+
When updating a polymorphic association, the old `foreign_type` was not inferred correctly when:
|
1147
|
+
1. `touch`ing the previously associated record
|
1148
|
+
2. updating the previously associated record's `counter_cache`
|
896
1149
|
|
897
|
-
|
898
|
-
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
899
|
-
post.title # => "Welcome to the weblog"
|
900
|
-
post.body # => "Such a lovely day"
|
1150
|
+
*Jimmy Bourassa*
|
901
1151
|
|
902
|
-
|
903
|
-
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
904
|
-
post.title # => "WELCOME TO THE WEBLOG"
|
905
|
-
post.body # => ActiveModel::MissingAttributeError
|
906
|
-
```
|
1152
|
+
* Add config option for ignoring tables when dumping the schema cache.
|
907
1153
|
|
908
|
-
|
1154
|
+
Applications can now be configured to ignore certain tables when dumping the schema cache.
|
909
1155
|
|
910
|
-
|
1156
|
+
The configuration option can table an array of tables:
|
911
1157
|
|
912
1158
|
```ruby
|
913
|
-
|
914
|
-
|
915
|
-
end
|
1159
|
+
config.active_record.schema_cache_ignored_tables = ["ignored_table", "another_ignored_table"]
|
1160
|
+
```
|
916
1161
|
|
917
|
-
|
918
|
-
Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
|
1162
|
+
Or a regex:
|
919
1163
|
|
920
|
-
|
921
|
-
|
1164
|
+
```ruby
|
1165
|
+
config.active_record.schema_cache_ignored_tables = [/^_/]
|
922
1166
|
```
|
923
1167
|
|
924
|
-
*
|
1168
|
+
*Eileen M. Uchitelle*
|
925
1169
|
|
926
|
-
*
|
1170
|
+
* Make schema cache methods return consistent results.
|
927
1171
|
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
1172
|
+
Previously the schema cache methods `primary_keys`, `columns`, `columns_hash`, and `indexes`
|
1173
|
+
would behave differently than one another when a table didn't exist and differently across
|
1174
|
+
database adapters. This change unifies the behavior so each method behaves the same regardless
|
1175
|
+
of adapter.
|
932
1176
|
|
933
|
-
|
934
|
-
```
|
1177
|
+
The behavior now is:
|
935
1178
|
|
936
|
-
|
1179
|
+
`columns`: (unchanged) raises a db error if the table does not exist.
|
1180
|
+
`columns_hash`: (unchanged) raises a db error if the table does not exist.
|
1181
|
+
`primary_keys`: (unchanged) returns `nil` if the table does not exist.
|
1182
|
+
`indexes`: (changed for mysql2) returns `[]` if the table does not exist.
|
937
1183
|
|
938
|
-
*
|
1184
|
+
*Eileen M. Uchitelle*
|
939
1185
|
|
940
|
-
|
1186
|
+
* Reestablish connection to previous database after after running `db:schema:load:name`
|
941
1187
|
|
942
|
-
|
943
|
-
allows you to specify that all string columns should be frozen unless
|
944
|
-
otherwise specified. This will reduce memory pressure for applications which
|
945
|
-
do not generally mutate string properties of Active Record objects.
|
1188
|
+
After running `db:schema:load:name` the previous connection is restored.
|
946
1189
|
|
947
|
-
*
|
1190
|
+
*Jacopo Beschi*
|
948
1191
|
|
949
|
-
*
|
1192
|
+
* Add database config option `database_tasks`
|
950
1193
|
|
951
|
-
|
1194
|
+
If you would like to connect to an external database without any database
|
1195
|
+
management tasks such as schema management, migrations, seeds, etc. you can set
|
1196
|
+
the per database config option `database_tasks: false`
|
952
1197
|
|
953
|
-
|
1198
|
+
```yaml
|
1199
|
+
# config/database.yml
|
954
1200
|
|
955
|
-
|
956
|
-
|
957
|
-
|
1201
|
+
production:
|
1202
|
+
primary:
|
1203
|
+
database: my_database
|
1204
|
+
adapter: mysql2
|
1205
|
+
animals:
|
1206
|
+
database: my_animals_database
|
1207
|
+
adapter: mysql2
|
1208
|
+
database_tasks: false
|
1209
|
+
```
|
958
1210
|
|
959
|
-
|
1211
|
+
*Weston Ganger*
|
960
1212
|
|
961
|
-
|
962
|
-
david_and_mary.or(mary_and_bob) # => [david, mary, bob]
|
963
|
-
```
|
1213
|
+
* Fix `ActiveRecord::InternalMetadata` to not be broken by `config.active_record.record_timestamps = false`
|
964
1214
|
|
965
|
-
|
1215
|
+
Since the model always create the timestamp columns, it has to set them, otherwise it breaks
|
1216
|
+
various DB management tasks.
|
966
1217
|
|
967
|
-
|
968
|
-
|
969
|
-
|
1218
|
+
Fixes #42983
|
1219
|
+
|
1220
|
+
* Add `ActiveRecord::QueryLogs`.
|
1221
|
+
|
1222
|
+
Configurable tags can be automatically added to all SQL queries generated by Active Record.
|
970
1223
|
|
971
1224
|
```ruby
|
972
|
-
#
|
973
|
-
|
1225
|
+
# config/application.rb
|
1226
|
+
module MyApp
|
1227
|
+
class Application < Rails::Application
|
1228
|
+
config.active_record.query_log_tags_enabled = true
|
1229
|
+
end
|
1230
|
+
end
|
1231
|
+
```
|
974
1232
|
|
975
|
-
|
976
|
-
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
|
1233
|
+
By default the application, controller and action details are added to the query tags:
|
977
1234
|
|
978
|
-
|
979
|
-
|
1235
|
+
```ruby
|
1236
|
+
class BooksController < ApplicationController
|
1237
|
+
def index
|
1238
|
+
@books = Book.all
|
1239
|
+
end
|
1240
|
+
end
|
1241
|
+
```
|
980
1242
|
|
981
|
-
|
982
|
-
|
983
|
-
|
1243
|
+
```ruby
|
1244
|
+
GET /books
|
1245
|
+
# SELECT * FROM books /*application:MyApp;controller:books;action:index*/
|
984
1246
|
```
|
985
1247
|
|
986
|
-
|
1248
|
+
Custom tags containing static values and Procs can be defined in the application configuration:
|
987
1249
|
|
988
|
-
|
1250
|
+
```ruby
|
1251
|
+
config.active_record.query_log_tags = [
|
1252
|
+
:application,
|
1253
|
+
:controller,
|
1254
|
+
:action,
|
1255
|
+
{
|
1256
|
+
custom_static: "foo",
|
1257
|
+
custom_dynamic: -> { Time.now }
|
1258
|
+
}
|
1259
|
+
]
|
1260
|
+
```
|
989
1261
|
|
990
|
-
*
|
1262
|
+
*Keeran Raj Hawoldar*, *Eileen M. Uchitelle*, *Kasper Timm Hansen*
|
991
1263
|
|
992
|
-
*
|
1264
|
+
* Added support for multiple databases to `rails db:setup` and `rails db:reset`.
|
993
1265
|
|
994
|
-
|
995
|
-
`ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
|
996
|
-
was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
|
1266
|
+
*Ryan Hall*
|
997
1267
|
|
998
|
-
|
1268
|
+
* Add `ActiveRecord::Relation#structurally_compatible?`.
|
1269
|
+
|
1270
|
+
Adds a query method by which a user can tell if the relation that they're
|
1271
|
+
about to use for `#or` or `#and` is structurally compatible with the
|
1272
|
+
receiver.
|
1273
|
+
|
1274
|
+
*Kevin Newton*
|
1275
|
+
|
1276
|
+
* Add `ActiveRecord::QueryMethods#in_order_of`.
|
1277
|
+
|
1278
|
+
This allows you to specify an explicit order that you'd like records
|
1279
|
+
returned in based on a SQL expression. By default, this will be accomplished
|
1280
|
+
using a case statement, as in:
|
999
1281
|
|
1000
1282
|
```ruby
|
1001
|
-
|
1002
|
-
|
1003
|
-
t.index "lower(name)", unique: true
|
1004
|
-
end
|
1283
|
+
Post.in_order_of(:id, [3, 5, 1])
|
1284
|
+
```
|
1005
1285
|
|
1006
|
-
|
1286
|
+
will generate the SQL:
|
1287
|
+
|
1288
|
+
```sql
|
1289
|
+
SELECT "posts".* FROM "posts" ORDER BY CASE "posts"."id" WHEN 3 THEN 1 WHEN 5 THEN 2 WHEN 1 THEN 3 ELSE 4 END ASC
|
1007
1290
|
```
|
1008
1291
|
|
1009
|
-
|
1292
|
+
However, because this functionality is built into MySQL in the form of the
|
1293
|
+
`FIELD` function, that connection adapter will generate the following SQL
|
1294
|
+
instead:
|
1010
1295
|
|
1011
|
-
|
1296
|
+
```sql
|
1297
|
+
SELECT "posts".* FROM "posts" ORDER BY FIELD("posts"."id", 1, 5, 3) DESC
|
1298
|
+
```
|
1012
1299
|
|
1013
|
-
*
|
1300
|
+
*Kevin Newton*
|
1014
1301
|
|
1015
|
-
|
1302
|
+
* Fix `eager_loading?` when ordering with `Symbol`.
|
1303
|
+
|
1304
|
+
`eager_loading?` is triggered correctly when using `order` with symbols.
|
1016
1305
|
|
1017
1306
|
```ruby
|
1018
|
-
|
1019
|
-
|
1307
|
+
scope = Post.includes(:comments).order(:"comments.label")
|
1308
|
+
=> true
|
1020
1309
|
```
|
1021
1310
|
|
1022
|
-
*
|
1311
|
+
*Jacopo Beschi*
|
1023
1312
|
|
1024
|
-
*
|
1025
|
-
to enable/disable strict_loading mode by default for a model. The configuration's value is
|
1026
|
-
inheritable by subclasses, but they can override that value and it will not impact parent class.
|
1313
|
+
* Two change tracking methods are added for `belongs_to` associations.
|
1027
1314
|
|
1028
|
-
|
1315
|
+
The `association_changed?` method (assuming an association named `:association`) returns true
|
1316
|
+
if a different associated object has been assigned and the foreign key will be updated in the
|
1317
|
+
next save.
|
1029
1318
|
|
1030
|
-
|
1031
|
-
|
1032
|
-
self.strict_loading_by_default = true
|
1319
|
+
The `association_previously_changed?` method returns true if the previous save updated the
|
1320
|
+
association to reference a different associated object.
|
1033
1321
|
|
1034
|
-
|
1035
|
-
end
|
1322
|
+
*George Claghorn*
|
1036
1323
|
|
1037
|
-
|
1038
|
-
dev.projects.first
|
1039
|
-
# => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.
|
1040
|
-
```
|
1324
|
+
* Add option to disable schema dump per-database.
|
1041
1325
|
|
1042
|
-
|
1326
|
+
Dumping the schema is on by default for all databases in an application. To turn it off for a
|
1327
|
+
specific database, use the `schema_dump` option:
|
1043
1328
|
|
1044
|
-
|
1329
|
+
```yaml
|
1330
|
+
# config/database.yml
|
1045
1331
|
|
1046
|
-
|
1332
|
+
production:
|
1333
|
+
schema_dump: false
|
1334
|
+
```
|
1047
1335
|
|
1048
|
-
*
|
1336
|
+
*Luis Vasconcellos*, *Eileen M. Uchitelle*
|
1049
1337
|
|
1050
|
-
|
1338
|
+
* Fix `eager_loading?` when ordering with `Hash` syntax.
|
1339
|
+
|
1340
|
+
`eager_loading?` is triggered correctly when using `order` with hash syntax
|
1341
|
+
on an outer table.
|
1051
1342
|
|
1052
1343
|
```ruby
|
1053
|
-
|
1054
|
-
|
1344
|
+
Post.includes(:comments).order({ "comments.label": :ASC }).eager_loading?
|
1345
|
+
# => true
|
1055
1346
|
```
|
1056
1347
|
|
1057
|
-
|
1348
|
+
*Jacopo Beschi*
|
1349
|
+
|
1350
|
+
* Move the forcing of clear text encoding to the `ActiveRecord::Encryption::Encryptor`.
|
1351
|
+
|
1352
|
+
Fixes #42699.
|
1353
|
+
|
1354
|
+
*J Smith*
|
1355
|
+
|
1356
|
+
* `partial_inserts` is now disabled by default in new apps.
|
1357
|
+
|
1358
|
+
This will be the default for new apps in Rails 7. To opt in:
|
1058
1359
|
|
1059
1360
|
```ruby
|
1060
|
-
|
1061
|
-
end
|
1361
|
+
config.active_record.partial_inserts = true
|
1062
1362
|
```
|
1063
1363
|
|
1064
|
-
|
1364
|
+
If a migration removes the default value of a column, this option
|
1365
|
+
would cause old processes to no longer be able to create new records.
|
1065
1366
|
|
1066
|
-
|
1067
|
-
|
1367
|
+
If you need to remove a column, you should first use `ignored_columns`
|
1368
|
+
to stop using it.
|
1068
1369
|
|
1069
|
-
*
|
1370
|
+
*Jean Boussier*
|
1070
1371
|
|
1071
|
-
*
|
1372
|
+
* Rails can now verify foreign keys after loading fixtures in tests.
|
1072
1373
|
|
1073
|
-
|
1374
|
+
This will be the default for new apps in Rails 7. To opt in:
|
1074
1375
|
|
1075
1376
|
```ruby
|
1076
|
-
|
1077
|
-
|
1078
|
-
# duplicated group fields, deprecated.
|
1079
|
-
accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
|
1080
|
-
# => {
|
1081
|
-
# [1, 1] => 50,
|
1082
|
-
# [2, 2] => 60
|
1083
|
-
# }
|
1084
|
-
|
1085
|
-
# use `uniq!(:group)` to deduplicate group fields.
|
1086
|
-
accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
|
1087
|
-
# => {
|
1088
|
-
# 1 => 50,
|
1089
|
-
# 2 => 60
|
1090
|
-
# }
|
1377
|
+
config.active_record.verify_foreign_keys_for_fixtures = true
|
1091
1378
|
```
|
1092
1379
|
|
1093
|
-
|
1380
|
+
Tests will not run if there is a foreign key constraint violation in your fixture data.
|
1094
1381
|
|
1095
|
-
|
1382
|
+
The feature is supported by SQLite and PostgreSQL, other adapters can also add support for it.
|
1096
1383
|
|
1097
|
-
|
1384
|
+
*Alex Ghiculescu*
|
1098
1385
|
|
1099
|
-
|
1100
|
-
accounts = Account.where(id: [1, 2]).annotate("david and mary")
|
1386
|
+
* Clear cached `has_one` association after setting `belongs_to` association to `nil`.
|
1101
1387
|
|
1102
|
-
|
1103
|
-
|
1104
|
-
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
|
1388
|
+
After setting a `belongs_to` relation to `nil` and updating an unrelated attribute on the owner,
|
1389
|
+
the owner should still return `nil` on the `has_one` relation.
|
1105
1390
|
|
1106
|
-
#
|
1107
|
-
accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
|
1108
|
-
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
|
1109
|
-
```
|
1391
|
+
Fixes #42597.
|
1110
1392
|
|
1111
|
-
*
|
1393
|
+
*Michiel de Mare*
|
1112
1394
|
|
1113
|
-
*
|
1395
|
+
* OpenSSL constants are now used for Digest computations.
|
1114
1396
|
|
1115
|
-
|
1116
|
-
cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
|
1117
|
-
upon subsequent transactions by maintaining parity with the corresponding
|
1118
|
-
database record's `lock_version` column.
|
1397
|
+
*Dirkjan Bussink*
|
1119
1398
|
|
1120
|
-
|
1399
|
+
* Adds support for `if_not_exists` to `add_foreign_key` and `if_exists` to `remove_foreign_key`.
|
1121
1400
|
|
1122
|
-
|
1401
|
+
Applications can set their migrations to ignore exceptions raised when adding a foreign key
|
1402
|
+
that already exists or when removing a foreign key that does not exist.
|
1403
|
+
|
1404
|
+
Example Usage:
|
1123
1405
|
|
1124
|
-
|
1406
|
+
```ruby
|
1407
|
+
class AddAuthorsForeignKeyToArticles < ActiveRecord::Migration[7.0]
|
1408
|
+
def change
|
1409
|
+
add_foreign_key :articles, :authors, if_not_exists: true
|
1410
|
+
end
|
1411
|
+
end
|
1412
|
+
```
|
1125
1413
|
|
1126
1414
|
```ruby
|
1127
|
-
|
1415
|
+
class RemoveAuthorsForeignKeyFromArticles < ActiveRecord::Migration[7.0]
|
1416
|
+
def change
|
1417
|
+
remove_foreign_key :articles, :authors, if_exists: true
|
1418
|
+
end
|
1419
|
+
end
|
1420
|
+
```
|
1128
1421
|
|
1129
|
-
|
1130
|
-
david_and_mary.merge(Author.where(id: bob)) # => []
|
1422
|
+
*Roberto Miranda*
|
1131
1423
|
|
1132
|
-
|
1133
|
-
david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
|
1424
|
+
* Prevent polluting ENV during postgresql structure dump/load.
|
1134
1425
|
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1426
|
+
Some configuration parameters were provided to pg_dump / psql via
|
1427
|
+
environment variables which persisted beyond the command being run, and may
|
1428
|
+
have caused subsequent commands and connections to fail. Tasks running
|
1429
|
+
across multiple postgresql databases like `rails db:test:prepare` may have
|
1430
|
+
been affected.
|
1138
1431
|
|
1139
|
-
*
|
1432
|
+
*Samuel Cochran*
|
1140
1433
|
|
1141
|
-
*
|
1142
|
-
set to expire and scoped with a purpose. This is particularly useful for things like password reset
|
1143
|
-
or email verification, where you want the bearer of the signed id to be able to interact with the
|
1144
|
-
underlying record, but usually only within a certain time period.
|
1434
|
+
* Set precision 6 by default for `datetime` columns.
|
1145
1435
|
|
1146
|
-
|
1147
|
-
signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
|
1436
|
+
By default, datetime columns will have microseconds precision instead of seconds precision.
|
1148
1437
|
|
1149
|
-
|
1438
|
+
*Roberto Miranda*
|
1150
1439
|
|
1151
|
-
|
1152
|
-
User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
|
1440
|
+
* Allow preloading of associations with instance dependent scopes.
|
1153
1441
|
|
1154
|
-
|
1155
|
-
User.find_signed signed_id, purpose: :password_reset # => User.first
|
1442
|
+
*John Hawthorn*, *John Crepezzi*, *Adam Hess*, *Eileen M. Uchitelle*, *Dinah Shi*
|
1156
1443
|
|
1157
|
-
|
1158
|
-
```
|
1444
|
+
* Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError`.
|
1159
1445
|
|
1160
|
-
*
|
1446
|
+
*Jamie McCarthy*
|
1161
1447
|
|
1162
|
-
*
|
1448
|
+
* Active Record Encryption will now encode values as UTF-8 when using deterministic
|
1449
|
+
encryption. The encoding is part of the encrypted payload, so different encodings for
|
1450
|
+
different values result in different ciphertexts. This can break unique constraints and
|
1451
|
+
queries.
|
1163
1452
|
|
1164
|
-
|
1453
|
+
The new behavior is configurable via `active_record.encryption.forced_encoding_for_deterministic_encryption`
|
1454
|
+
that is `Encoding::UTF_8` by default. It can be disabled by setting it to `nil`.
|
1165
1455
|
|
1166
|
-
*
|
1456
|
+
*Jorge Manrubia*
|
1167
1457
|
|
1168
|
-
|
1458
|
+
* The MySQL adapter now cast numbers and booleans bind parameters to string for safety reasons.
|
1169
1459
|
|
1170
|
-
|
1460
|
+
When comparing a string and a number in a query, MySQL converts the string to a number. So for
|
1461
|
+
instance `"foo" = 0`, will implicitly cast `"foo"` to `0` and will evaluate to `TRUE` which can
|
1462
|
+
lead to security vulnerabilities.
|
1171
1463
|
|
1172
|
-
|
1464
|
+
Active Record already protect against that vulnerability when it knows the type of the column
|
1465
|
+
being compared, however until now it was still vulnerable when using bind parameters:
|
1173
1466
|
|
1174
1467
|
```ruby
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
posts.count
|
1179
|
-
# => { false => 10 }
|
1468
|
+
User.where("login_token = ?", 0).first
|
1469
|
+
```
|
1180
1470
|
|
1181
|
-
|
1182
|
-
posts.unscope(where: :hidden).count
|
1183
|
-
# => { false => 11, true => 1 }
|
1471
|
+
Would perform:
|
1184
1472
|
|
1185
|
-
|
1186
|
-
|
1187
|
-
# => { false => 11 }
|
1473
|
+
```sql
|
1474
|
+
SELECT * FROM `users` WHERE `login_token` = 0 LIMIT 1;
|
1188
1475
|
```
|
1189
1476
|
|
1190
|
-
|
1477
|
+
Now it will perform:
|
1191
1478
|
|
1192
|
-
|
1479
|
+
```sql
|
1480
|
+
SELECT * FROM `users` WHERE `login_token` = '0' LIMIT 1;
|
1481
|
+
```
|
1193
1482
|
|
1194
|
-
|
1195
|
-
steve = Person.find_by(name: "Steve")
|
1196
|
-
david = Author.find_by(name: "David")
|
1483
|
+
*Jean Boussier*
|
1197
1484
|
|
1198
|
-
|
1485
|
+
* Fixture configurations (`_fixture`) are now strictly validated.
|
1199
1486
|
|
1200
|
-
|
1201
|
-
|
1487
|
+
If an error will be raised if that entry contains unknown keys while previously it
|
1488
|
+
would silently have no effects.
|
1202
1489
|
|
1203
|
-
|
1204
|
-
relation.rewhere(writer: david).to_a # => [david]
|
1205
|
-
```
|
1490
|
+
*Jean Boussier*
|
1206
1491
|
|
1207
|
-
|
1492
|
+
* Add `ActiveRecord::Base.update!` that works like `ActiveRecord::Base.update` but raises exceptions.
|
1208
1493
|
|
1209
|
-
|
1494
|
+
This allows for the same behavior as the instance method `#update!` at a class level.
|
1210
1495
|
|
1211
1496
|
```ruby
|
1212
|
-
|
1213
|
-
=> #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
|
1497
|
+
Person.update!(:all, state: "confirmed")
|
1214
1498
|
```
|
1215
1499
|
|
1216
|
-
*
|
1500
|
+
*Dorian Marié*
|
1217
1501
|
|
1218
|
-
*
|
1502
|
+
* Add `ActiveRecord::Base#attributes_for_database`.
|
1219
1503
|
|
1220
|
-
|
1504
|
+
Returns attributes with values for assignment to the database.
|
1221
1505
|
|
1222
|
-
*
|
1506
|
+
*Chris Salzberg*
|
1223
1507
|
|
1224
|
-
|
1508
|
+
* Use an empty query to check if the PostgreSQL connection is still active.
|
1225
1509
|
|
1226
|
-
|
1510
|
+
An empty query is faster than `SELECT 1`.
|
1227
1511
|
|
1228
|
-
*
|
1512
|
+
*Heinrich Lee Yu*
|
1229
1513
|
|
1230
|
-
*
|
1514
|
+
* Add `ActiveRecord::Base#previously_persisted?`.
|
1231
1515
|
|
1232
|
-
|
1516
|
+
Returns `true` if the object has been previously persisted but now it has been deleted.
|
1233
1517
|
|
1234
|
-
*
|
1518
|
+
* Deprecate `partial_writes` in favor of `partial_inserts` and `partial_updates`.
|
1235
1519
|
|
1236
|
-
|
1520
|
+
This allows to have a different behavior on update and create.
|
1237
1521
|
|
1238
|
-
*
|
1522
|
+
*Jean Boussier*
|
1239
1523
|
|
1240
|
-
*
|
1524
|
+
* Fix compatibility with `psych >= 4`.
|
1241
1525
|
|
1242
|
-
|
1526
|
+
Starting in Psych 4.0.0 `YAML.load` behaves like `YAML.safe_load`. To preserve compatibility,
|
1527
|
+
Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
|
1243
1528
|
|
1244
|
-
*
|
1529
|
+
*Jean Boussier*
|
1245
1530
|
|
1246
|
-
|
1531
|
+
* `ActiveRecord::Base.logger` is now a `class_attribute`.
|
1247
1532
|
|
1248
|
-
|
1533
|
+
This means it can no longer be accessed directly through `@@logger`, and that setting `logger =`
|
1534
|
+
on a subclass won't change the parent's logger.
|
1249
1535
|
|
1250
|
-
*
|
1536
|
+
*Jean Boussier*
|
1251
1537
|
|
1252
|
-
|
1253
|
-
index won't be added.
|
1538
|
+
* Add `.asc.nulls_first` for all databases. Unfortunately MySQL still doesn't like `nulls_last`.
|
1254
1539
|
|
1255
|
-
|
1540
|
+
*Keenan Brock*
|
1256
1541
|
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1542
|
+
* Improve performance of `one?` and `many?` by limiting the generated count query to 2 results.
|
1543
|
+
|
1544
|
+
*Gonzalo Riestra*
|
1545
|
+
|
1546
|
+
* Don't check type when using `if_not_exists` on `add_column`.
|
1547
|
+
|
1548
|
+
Previously, if a migration called `add_column` with the `if_not_exists` option set to true
|
1549
|
+
the `column_exists?` check would look for a column with the same name and type as the migration.
|
1260
1550
|
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1551
|
+
Recently it was discovered that the type passed to the migration is not always the same type
|
1552
|
+
as the column after migration. For example a column set to `:mediumblob` in the migration will
|
1553
|
+
be casted to `binary` when calling `column.type`. Since there is no straightforward way to cast
|
1554
|
+
the type to the database type without running the migration, we opted to drop the type check from
|
1555
|
+
`add_column`. This means that migrations adding a duplicate column with a different type will no
|
1556
|
+
longer raise an error.
|
1264
1557
|
|
1265
|
-
*
|
1558
|
+
*Eileen M. Uchitelle*
|
1559
|
+
|
1560
|
+
* Log a warning message when running SQLite in production.
|
1266
1561
|
|
1267
|
-
|
1562
|
+
Using SQLite in production ENV is generally discouraged. SQLite is also the default adapter
|
1563
|
+
in a new Rails application.
|
1564
|
+
For the above reasons log a warning message when running SQLite in production.
|
1268
1565
|
|
1269
|
-
|
1566
|
+
The warning can be disabled by setting `config.active_record.sqlite3_production_warning=false`.
|
1270
1567
|
|
1271
|
-
*
|
1568
|
+
*Jacopo Beschi*
|
1272
1569
|
|
1273
|
-
|
1570
|
+
* Add option to disable joins for `has_one` associations.
|
1274
1571
|
|
1275
|
-
|
1572
|
+
In a multiple database application, associations can't join across
|
1573
|
+
databases. When set, this option instructs Rails to generate 2 or
|
1574
|
+
more queries rather than generating joins for `has_one` associations.
|
1276
1575
|
|
1277
|
-
|
1576
|
+
Set the option on a has one through association:
|
1278
1577
|
|
1279
1578
|
```ruby
|
1280
|
-
Person
|
1281
|
-
|
1579
|
+
class Person
|
1580
|
+
has_one :dog
|
1581
|
+
has_one :veterinarian, through: :dog, disable_joins: true
|
1282
1582
|
end
|
1283
1583
|
```
|
1284
1584
|
|
1285
|
-
|
1585
|
+
Then instead of generating join SQL, two queries are used for `@person.veterinarian`:
|
1586
|
+
|
1587
|
+
```
|
1588
|
+
SELECT "dogs"."id" FROM "dogs" WHERE "dogs"."person_id" = ? [["person_id", 1]]
|
1589
|
+
SELECT "veterinarians".* FROM "veterinarians" WHERE "veterinarians"."dog_id" = ? [["dog_id", 1]]
|
1590
|
+
```
|
1286
1591
|
|
1287
|
-
*
|
1592
|
+
*Sarah Vessels*, *Eileen M. Uchitelle*
|
1288
1593
|
|
1289
|
-
|
1594
|
+
* `Arel::Visitors::Dot` now renders a complete set of properties when visiting
|
1595
|
+
`Arel::Nodes::SelectCore`, `SelectStatement`, `InsertStatement`, `UpdateStatement`, and
|
1596
|
+
`DeleteStatement`, which fixes #42026. Previously, some properties were omitted.
|
1290
1597
|
|
1291
|
-
*
|
1598
|
+
*Mike Dalessio*
|
1292
1599
|
|
1293
|
-
*
|
1600
|
+
* `Arel::Visitors::Dot` now supports `Arel::Nodes::Bin`, `Case`, `CurrentRow`, `Distinct`,
|
1601
|
+
`DistinctOn`, `Else`, `Except`, `InfixOperation`, `Intersect`, `Lock`, `NotRegexp`, `Quoted`,
|
1602
|
+
`Regexp`, `UnaryOperation`, `Union`, `UnionAll`, `When`, and `With`. Previously, these node
|
1603
|
+
types caused an exception to be raised by `Arel::Visitors::Dot#accept`.
|
1294
1604
|
|
1295
|
-
|
1605
|
+
*Mike Dalessio*
|
1296
1606
|
|
1297
|
-
|
1607
|
+
* Optimize `remove_columns` to use a single SQL statement.
|
1298
1608
|
|
1299
|
-
|
1609
|
+
```ruby
|
1610
|
+
remove_columns :my_table, :col_one, :col_two
|
1611
|
+
```
|
1300
1612
|
|
1301
|
-
|
1613
|
+
Now results in the following SQL:
|
1302
1614
|
|
1303
|
-
|
1615
|
+
```sql
|
1616
|
+
ALTER TABLE "my_table" DROP COLUMN "col_one", DROP COLUMN "col_two"
|
1617
|
+
```
|
1304
1618
|
|
1305
|
-
*
|
1619
|
+
*Jon Dufresne*
|
1306
1620
|
|
1307
|
-
*
|
1621
|
+
* Ensure `has_one` autosave association callbacks get called once.
|
1308
1622
|
|
1309
|
-
|
1623
|
+
Change the `has_one` autosave callback to be non cyclic as well.
|
1624
|
+
By doing this the autosave callback are made more consistent for
|
1625
|
+
all 3 cases: `has_many`, `has_one`, and `belongs_to`.
|
1310
1626
|
|
1311
|
-
|
1627
|
+
*Petrik de Heus*
|
1312
1628
|
|
1313
|
-
|
1629
|
+
* Add option to disable joins for associations.
|
1314
1630
|
|
1315
|
-
|
1631
|
+
In a multiple database application, associations can't join across
|
1632
|
+
databases. When set, this option instructs Rails to generate 2 or
|
1633
|
+
more queries rather than generating joins for associations.
|
1316
1634
|
|
1317
|
-
|
1635
|
+
Set the option on a has many through association:
|
1318
1636
|
|
1319
|
-
|
1637
|
+
```ruby
|
1638
|
+
class Dog
|
1639
|
+
has_many :treats, through: :humans, disable_joins: true
|
1640
|
+
has_many :humans
|
1641
|
+
end
|
1642
|
+
```
|
1320
1643
|
|
1321
|
-
|
1644
|
+
Then instead of generating join SQL, two queries are used for `@dog.treats`:
|
1322
1645
|
|
1323
|
-
|
1646
|
+
```
|
1647
|
+
SELECT "humans"."id" FROM "humans" WHERE "humans"."dog_id" = ? [["dog_id", 1]]
|
1648
|
+
SELECT "treats".* FROM "treats" WHERE "treats"."human_id" IN (?, ?, ?) [["human_id", 1], ["human_id", 2], ["human_id", 3]]
|
1649
|
+
```
|
1324
1650
|
|
1325
|
-
*Eileen M. Uchitelle*, *
|
1651
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*, *Lee Quarella*
|
1326
1652
|
|
1327
|
-
* Add
|
1653
|
+
* Add setting for enumerating column names in SELECT statements.
|
1328
1654
|
|
1329
|
-
|
1655
|
+
Adding a column to a PostgreSQL database, for example, while the application is running can
|
1656
|
+
change the result of wildcard `SELECT *` queries, which invalidates the result
|
1657
|
+
of cached prepared statements and raises a `PreparedStatementCacheExpired` error.
|
1330
1658
|
|
1331
|
-
|
1659
|
+
When enabled, Active Record will avoid wildcards and always include column names
|
1660
|
+
in `SELECT` queries, which will return consistent results and avoid prepared
|
1661
|
+
statement errors.
|
1332
1662
|
|
1333
|
-
|
1663
|
+
Before:
|
1334
1664
|
|
1335
|
-
```
|
1336
|
-
|
1337
|
-
|
1338
|
-
primary:
|
1339
|
-
database: my_database
|
1340
|
-
primary_shard_one:
|
1341
|
-
database: my_database_shard_one
|
1665
|
+
```ruby
|
1666
|
+
Book.limit(5)
|
1667
|
+
# SELECT * FROM books LIMIT 5
|
1342
1668
|
```
|
1343
1669
|
|
1344
|
-
|
1670
|
+
After:
|
1345
1671
|
|
1346
1672
|
```ruby
|
1347
|
-
|
1348
|
-
|
1673
|
+
# config/application.rb
|
1674
|
+
module MyApp
|
1675
|
+
class Application < Rails::Application
|
1676
|
+
config.active_record.enumerate_columns_in_select_statements = true
|
1677
|
+
end
|
1678
|
+
end
|
1349
1679
|
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1680
|
+
# or, configure per-model
|
1681
|
+
class Book < ApplicationRecord
|
1682
|
+
self.enumerate_columns_in_select_statements = true
|
1683
|
+
end
|
1354
1684
|
```
|
1355
1685
|
|
1356
|
-
Swap between shards in your controller / model code:
|
1357
|
-
|
1358
1686
|
```ruby
|
1359
|
-
|
1360
|
-
|
1361
|
-
end
|
1687
|
+
Book.limit(5)
|
1688
|
+
# SELECT id, author_id, name, format, status, language, etc FROM books LIMIT 5
|
1362
1689
|
```
|
1363
1690
|
|
1364
|
-
|
1691
|
+
*Matt Duszynski*
|
1365
1692
|
|
1366
|
-
|
1693
|
+
* Allow passing SQL as `on_duplicate` value to `#upsert_all` to make it possible to use raw SQL to update columns on conflict:
|
1367
1694
|
|
1368
|
-
|
1695
|
+
```ruby
|
1696
|
+
Book.upsert_all(
|
1697
|
+
[{ id: 1, status: 1 }, { id: 2, status: 1 }],
|
1698
|
+
on_duplicate: Arel.sql("status = GREATEST(books.status, EXCLUDED.status)")
|
1699
|
+
)
|
1700
|
+
```
|
1369
1701
|
|
1370
|
-
|
1702
|
+
*Vladimir Dementyev*
|
1371
1703
|
|
1372
|
-
|
1704
|
+
* Allow passing SQL as `returning` statement to `#upsert_all`:
|
1373
1705
|
|
1374
1706
|
```ruby
|
1375
|
-
|
1376
|
-
|
1707
|
+
Article.insert_all(
|
1708
|
+
[
|
1709
|
+
{ title: "Article 1", slug: "article-1", published: false },
|
1710
|
+
{ title: "Article 2", slug: "article-2", published: false }
|
1711
|
+
],
|
1712
|
+
returning: Arel.sql("id, (xmax = '0') as inserted, name as new_name")
|
1713
|
+
)
|
1377
1714
|
```
|
1378
1715
|
|
1379
|
-
|
1716
|
+
*Vladimir Dementyev*
|
1380
1717
|
|
1381
|
-
|
1382
|
-
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", name: "primary")
|
1383
|
-
db_config.name
|
1384
|
-
```
|
1718
|
+
* Deprecate `legacy_connection_handling`.
|
1385
1719
|
|
1386
1720
|
*Eileen M. Uchitelle*
|
1387
1721
|
|
1388
|
-
* Add
|
1722
|
+
* Add attribute encryption support.
|
1389
1723
|
|
1390
|
-
|
1391
|
-
|
1724
|
+
Encrypted attributes are declared at the model level. These
|
1725
|
+
are regular Active Record attributes backed by a column with
|
1726
|
+
the same name. The system will transparently encrypt these
|
1727
|
+
attributes before saving them into the database and will
|
1728
|
+
decrypt them when retrieving their values.
|
1392
1729
|
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
rails db:drop:animals
|
1400
|
-
rails db:migrate
|
1401
|
-
rails db:migrate:primary
|
1402
|
-
rails db:migrate:animals
|
1730
|
+
|
1731
|
+
```ruby
|
1732
|
+
class Person < ApplicationRecord
|
1733
|
+
encrypts :name
|
1734
|
+
encrypts :email_address, deterministic: true
|
1735
|
+
end
|
1403
1736
|
```
|
1404
1737
|
|
1405
|
-
|
1406
|
-
|
1738
|
+
You can learn more in the [Active Record Encryption
|
1739
|
+
guide](https://edgeguides.rubyonrails.org/active_record_encryption.html).
|
1407
1740
|
|
1408
|
-
|
1409
|
-
rails db:schema:dump
|
1410
|
-
rails db:schema:dump:primary
|
1411
|
-
rails db:schema:dump:animals
|
1412
|
-
rails db:schema:load
|
1413
|
-
rails db:schema:load:primary
|
1414
|
-
rails db:schema:load:animals
|
1415
|
-
rails db:structure:dump
|
1416
|
-
rails db:structure:dump:primary
|
1417
|
-
rails db:structure:dump:animals
|
1418
|
-
rails db:structure:load
|
1419
|
-
rails db:structure:load:primary
|
1420
|
-
rails db:structure:load:animals
|
1421
|
-
rails db:test:prepare
|
1422
|
-
rails db:test:prepare:primary
|
1423
|
-
rails db:test:prepare:animals
|
1424
|
-
```
|
1741
|
+
*Jorge Manrubia*
|
1425
1742
|
|
1426
|
-
|
1743
|
+
* Changed Arel predications `contains` and `overlaps` to use
|
1744
|
+
`quoted_node` so that PostgreSQL arrays are quoted properly.
|
1427
1745
|
|
1428
|
-
*
|
1746
|
+
*Bradley Priest*
|
1429
1747
|
|
1430
|
-
|
1748
|
+
* Add mode argument to record level `strict_loading!`.
|
1431
1749
|
|
1432
|
-
|
1750
|
+
This argument can be used when enabling strict loading for a single record
|
1751
|
+
to specify that we only want to raise on n plus one queries.
|
1433
1752
|
|
1434
1753
|
```ruby
|
1435
|
-
|
1436
|
-
has_many :projects, strict_loading: true
|
1437
|
-
end
|
1754
|
+
developer.strict_loading!(mode: :n_plus_one_only)
|
1438
1755
|
|
1439
|
-
|
1440
|
-
|
1441
|
-
# => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.
|
1756
|
+
developer.projects.to_a # Does not raise
|
1757
|
+
developer.projects.first.client # Raises StrictLoadingViolationError
|
1442
1758
|
```
|
1443
1759
|
|
1444
|
-
|
1760
|
+
Previously, enabling strict loading would cause any lazily loaded
|
1761
|
+
association to raise an error. Using `n_plus_one_only` mode allows us to
|
1762
|
+
lazily load belongs_to, has_many, and other associations that are fetched
|
1763
|
+
through a single query.
|
1445
1764
|
|
1446
|
-
*
|
1765
|
+
*Dinah Shi*
|
1447
1766
|
|
1448
|
-
|
1767
|
+
* Fix Float::INFINITY assignment to datetime column with postgresql adapter.
|
1449
1768
|
|
1450
|
-
|
1769
|
+
Before:
|
1451
1770
|
|
1452
1771
|
```ruby
|
1453
|
-
|
1454
|
-
|
1455
|
-
# => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
|
1456
|
-
```
|
1772
|
+
# With this config
|
1773
|
+
ActiveRecord::Base.time_zone_aware_attributes = true
|
1457
1774
|
|
1458
|
-
|
1775
|
+
# and the following schema:
|
1776
|
+
create_table "postgresql_infinities" do |t|
|
1777
|
+
t.datetime "datetime"
|
1778
|
+
end
|
1459
1779
|
|
1460
|
-
|
1780
|
+
# This test fails
|
1781
|
+
record = PostgresqlInfinity.create!(datetime: Float::INFINITY)
|
1782
|
+
assert_equal Float::INFINITY, record.datetime # record.datetime gets nil
|
1783
|
+
```
|
1461
1784
|
|
1462
|
-
|
1785
|
+
After this commit, `record.datetime` gets `Float::INFINITY` as expected.
|
1463
1786
|
|
1464
|
-
*
|
1787
|
+
*Shunichi Ikegami*
|
1465
1788
|
|
1466
|
-
|
1789
|
+
* Type cast enum values by the original attribute type.
|
1467
1790
|
|
1468
|
-
|
1791
|
+
The notable thing about this change is that unknown labels will no longer match 0 on MySQL.
|
1469
1792
|
|
1470
1793
|
```ruby
|
1471
|
-
class
|
1472
|
-
|
1473
|
-
add_column :posts, :title, :string, if_not_exists: true
|
1474
|
-
end
|
1794
|
+
class Book < ActiveRecord::Base
|
1795
|
+
enum :status, { proposed: 0, written: 1, published: 2 }
|
1475
1796
|
end
|
1476
1797
|
```
|
1477
1798
|
|
1799
|
+
Before:
|
1800
|
+
|
1478
1801
|
```ruby
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1802
|
+
# SELECT `books`.* FROM `books` WHERE `books`.`status` = 'prohibited' LIMIT 1
|
1803
|
+
Book.find_by(status: :prohibited)
|
1804
|
+
# => #<Book id: 1, status: "proposed", ...> (for mysql2 adapter)
|
1805
|
+
# => ActiveRecord::StatementInvalid: PG::InvalidTextRepresentation: ERROR: invalid input syntax for type integer: "prohibited" (for postgresql adapter)
|
1806
|
+
# => nil (for sqlite3 adapter)
|
1484
1807
|
```
|
1485
1808
|
|
1486
|
-
|
1487
|
-
|
1488
|
-
* Regexp-escape table name for MS SQL Server.
|
1489
|
-
|
1490
|
-
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.
|
1491
|
-
|
1492
|
-
*Larry Reid*
|
1493
|
-
|
1494
|
-
* Store advisory locks on their own named connection.
|
1809
|
+
After:
|
1495
1810
|
|
1496
|
-
|
1811
|
+
```ruby
|
1812
|
+
# SELECT `books`.* FROM `books` WHERE `books`.`status` IS NULL LIMIT 1
|
1813
|
+
Book.find_by(status: :prohibited)
|
1814
|
+
# => nil (for all adapters)
|
1815
|
+
```
|
1497
1816
|
|
1498
|
-
|
1817
|
+
*Ryuta Kamizono*
|
1499
1818
|
|
1500
|
-
|
1819
|
+
* Fixtures for `has_many :through` associations now load timestamps on join tables.
|
1501
1820
|
|
1502
|
-
|
1821
|
+
Given this fixture:
|
1503
1822
|
|
1504
|
-
|
1823
|
+
```yml
|
1824
|
+
### monkeys.yml
|
1825
|
+
george:
|
1826
|
+
name: George the Monkey
|
1827
|
+
fruits: apple
|
1505
1828
|
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
database: blog_development
|
1510
|
-
pool: 5
|
1511
|
-
schema_cache_path: tmp/schema/main.yml
|
1829
|
+
### fruits.yml
|
1830
|
+
apple:
|
1831
|
+
name: apple
|
1512
1832
|
```
|
1513
1833
|
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1834
|
+
If the join table (`fruit_monkeys`) contains `created_at` or `updated_at` columns,
|
1835
|
+
these will now be populated when loading the fixture. Previously, fixture loading
|
1836
|
+
would crash if these columns were required, and leave them as null otherwise.
|
1517
1837
|
|
1518
|
-
|
1519
|
-
|
1520
|
-
*Eileen M. Uchitelle*, *John Crepezzi*
|
1521
|
-
|
1522
|
-
* Deprecate `#default_hash` and it's alias `#[]` on database configurations.
|
1838
|
+
*Alex Ghiculescu*
|
1523
1839
|
|
1524
|
-
|
1840
|
+
* Allow applications to configure the thread pool for async queries.
|
1525
1841
|
|
1526
|
-
|
1842
|
+
Some applications may want one thread pool per database whereas others want to use
|
1843
|
+
a single global thread pool for all queries. By default, Rails will set `async_query_executor`
|
1844
|
+
to `nil` which will not initialize any executor. If `load_async` is called and no executor
|
1845
|
+
has been configured, the query will be executed in the foreground.
|
1527
1846
|
|
1528
|
-
|
1847
|
+
To create one thread pool for all database connections to use applications can set
|
1848
|
+
`config.active_record.async_query_executor` to `:global_thread_pool` and optionally define
|
1849
|
+
`config.active_record.global_executor_concurrency`. This defaults to 4. For applications that want
|
1850
|
+
to have a thread pool for each database connection, `config.active_record.async_query_executor` can
|
1851
|
+
be set to `:multi_thread_pool`. The configuration for each thread pool is set in the database
|
1852
|
+
configuration.
|
1529
1853
|
|
1530
|
-
*
|
1854
|
+
*Eileen M. Uchitelle*
|
1531
1855
|
|
1532
|
-
*
|
1856
|
+
* Allow new syntax for `enum` to avoid leading `_` from reserved options.
|
1533
1857
|
|
1534
1858
|
Before:
|
1535
1859
|
|
1536
1860
|
```ruby
|
1537
|
-
|
1861
|
+
class Book < ActiveRecord::Base
|
1862
|
+
enum status: [ :proposed, :written ], _prefix: true, _scopes: false
|
1863
|
+
enum cover: [ :hard, :soft ], _suffix: true, _default: :hard
|
1864
|
+
end
|
1538
1865
|
```
|
1539
1866
|
|
1540
1867
|
After:
|
1541
1868
|
|
1542
1869
|
```ruby
|
1543
|
-
|
1870
|
+
class Book < ActiveRecord::Base
|
1871
|
+
enum :status, [ :proposed, :written ], prefix: true, scopes: false
|
1872
|
+
enum :cover, [ :hard, :soft ], suffix: true, default: :hard
|
1873
|
+
end
|
1544
1874
|
```
|
1545
1875
|
|
1546
|
-
*
|
1547
|
-
|
1548
|
-
* Ensure `:reading` connections always raise if a write is attempted.
|
1549
|
-
|
1550
|
-
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`.
|
1551
|
-
|
1552
|
-
*Eileen M. Uchitelle*
|
1553
|
-
|
1554
|
-
* Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
|
1555
|
-
|
1556
|
-
`"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"`.
|
1876
|
+
*Ryuta Kamizono*
|
1557
1877
|
|
1558
|
-
|
1878
|
+
* Add `ActiveRecord::Relation#load_async`.
|
1559
1879
|
|
1560
|
-
|
1561
|
-
support for casting floats using a database columns' precision value.
|
1880
|
+
This method schedules the query to be performed asynchronously from a thread pool.
|
1562
1881
|
|
1563
|
-
|
1882
|
+
If the result is accessed before a background thread had the opportunity to perform
|
1883
|
+
the query, it will be performed in the foreground.
|
1564
1884
|
|
1565
|
-
|
1566
|
-
|
1567
|
-
ActionController::ConditionalGet to ensure that when collection cache versioning
|
1568
|
-
is enabled, requests using ConditionalGet don't return the same ETag header
|
1569
|
-
after a collection is modified.
|
1885
|
+
This is useful for queries that can be performed long enough before their result will be
|
1886
|
+
needed, or for controllers which need to perform several independent queries.
|
1570
1887
|
|
1571
|
-
|
1888
|
+
```ruby
|
1889
|
+
def index
|
1890
|
+
@categories = Category.some_complex_scope.load_async
|
1891
|
+
@posts = Post.some_complex_scope.load_async
|
1892
|
+
end
|
1893
|
+
```
|
1572
1894
|
|
1573
|
-
|
1895
|
+
Active Record logs will also include timing info for the duration of how long
|
1896
|
+
the main thread had to wait to access the result. This timing is useful to know
|
1897
|
+
whether or not it's worth to load the query asynchronously.
|
1574
1898
|
|
1575
|
-
|
1576
|
-
|
1899
|
+
```
|
1900
|
+
DEBUG -- : Category Load (62.1ms) SELECT * FROM `categories` LIMIT 50
|
1901
|
+
DEBUG -- : ASYNC Post Load (64ms) (db time 126.1ms) SELECT * FROM `posts` LIMIT 100
|
1902
|
+
```
|
1577
1903
|
|
1578
|
-
|
1904
|
+
The duration in the first set of parens is how long the main thread was blocked
|
1905
|
+
waiting for the results, and the second set of parens with "db time" is how long
|
1906
|
+
the entire query took to execute.
|
1579
1907
|
|
1580
|
-
*
|
1908
|
+
*Jean Boussier*
|
1581
1909
|
|
1582
|
-
|
1910
|
+
* Implemented `ActiveRecord::Relation#excluding` method.
|
1583
1911
|
|
1584
|
-
|
1912
|
+
This method excludes the specified record (or collection of records) from
|
1913
|
+
the resulting relation:
|
1585
1914
|
|
1586
1915
|
```ruby
|
1587
|
-
|
1588
|
-
|
1916
|
+
Post.excluding(post)
|
1917
|
+
Post.excluding(post_one, post_two)
|
1589
1918
|
```
|
1590
1919
|
|
1591
|
-
|
1920
|
+
Also works on associations:
|
1592
1921
|
|
1593
1922
|
```ruby
|
1594
|
-
|
1595
|
-
|
1596
|
-
db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)
|
1923
|
+
post.comments.excluding(comment)
|
1924
|
+
post.comments.excluding(comment_one, comment_two)
|
1597
1925
|
```
|
1598
1926
|
|
1599
|
-
|
1600
|
-
|
1601
|
-
* Remove `:connection_id` from the `sql.active_record` notification.
|
1927
|
+
This is short-hand for `Post.where.not(id: post.id)` (for a single record)
|
1928
|
+
and `Post.where.not(id: [post_one.id, post_two.id])` (for a collection).
|
1602
1929
|
|
1603
|
-
*
|
1930
|
+
*Glen Crawford*
|
1604
1931
|
|
1605
|
-
*
|
1932
|
+
* Skip optimised #exist? query when #include? is called on a relation
|
1933
|
+
with a having clause.
|
1606
1934
|
|
1607
|
-
|
1935
|
+
Relations that have aliased select values AND a having clause that
|
1936
|
+
references an aliased select value would generate an error when
|
1937
|
+
#include? was called, due to an optimisation that would generate
|
1938
|
+
call #exists? on the relation instead, which effectively alters
|
1939
|
+
the select values of the query (and thus removes the aliased select
|
1940
|
+
values), but leaves the having clause intact. Because the having
|
1941
|
+
clause is then referencing an aliased column that is no longer
|
1942
|
+
present in the simplified query, an ActiveRecord::InvalidStatement
|
1943
|
+
error was raised.
|
1608
1944
|
|
1609
|
-
|
1945
|
+
A sample query affected by this problem:
|
1610
1946
|
|
1611
|
-
|
1612
|
-
|
1947
|
+
```ruby
|
1948
|
+
Author.select('COUNT(*) as total_posts', 'authors.*')
|
1949
|
+
.joins(:posts)
|
1950
|
+
.group(:id)
|
1951
|
+
.having('total_posts > 2')
|
1952
|
+
.include?(Author.first)
|
1953
|
+
```
|
1613
1954
|
|
1614
|
-
This change
|
1615
|
-
|
1955
|
+
This change adds an addition check to the condition that skips the
|
1956
|
+
simplified #exists? query, which simply checks for the presence of
|
1957
|
+
a having clause.
|
1616
1958
|
|
1617
|
-
|
1959
|
+
Fixes #41417.
|
1618
1960
|
|
1619
|
-
*
|
1961
|
+
*Michael Smart*
|
1620
1962
|
|
1621
|
-
|
1963
|
+
* Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
|
1964
|
+
without Rails knowledge (e.g., if app gets killed during long-running query or due to Rack::Timeout), app won't end
|
1965
|
+
up in perpetual crash state for being inconsistent with PostgreSQL.
|
1622
1966
|
|
1623
|
-
*
|
1967
|
+
*wbharding*, *Martin Tepper*
|
1624
1968
|
|
1625
|
-
|
1969
|
+
* Add ability to apply `scoping` to `all_queries`.
|
1626
1970
|
|
1627
|
-
|
1971
|
+
Some applications may want to use the `scoping` method but previously it only
|
1972
|
+
worked on certain types of queries. This change allows the `scoping` method to apply
|
1973
|
+
to all queries for a model in a block.
|
1628
1974
|
|
1629
|
-
|
1975
|
+
```ruby
|
1976
|
+
Post.where(blog_id: post.blog_id).scoping(all_queries: true) do
|
1977
|
+
post.update(title: "a post title") # adds `posts.blog_id = 1` to the query
|
1978
|
+
end
|
1979
|
+
```
|
1630
1980
|
|
1631
|
-
*Eileen M. Uchitelle
|
1981
|
+
*Eileen M. Uchitelle*
|
1632
1982
|
|
1633
|
-
*
|
1983
|
+
* `ActiveRecord::Calculations.calculate` called with `:average`
|
1984
|
+
(aliased as `ActiveRecord::Calculations.average`) will now use column-based
|
1985
|
+
type casting. This means that floating-point number columns will now be
|
1986
|
+
aggregated as `Float` and decimal columns will be aggregated as `BigDecimal`.
|
1634
1987
|
|
1635
|
-
|
1988
|
+
Integers are handled as a special case returning `BigDecimal` always
|
1989
|
+
(this was the case before already).
|
1636
1990
|
|
1637
|
-
|
1991
|
+
```ruby
|
1992
|
+
# With the following schema:
|
1993
|
+
create_table "measurements" do |t|
|
1994
|
+
t.float "temperature"
|
1995
|
+
end
|
1638
1996
|
|
1639
|
-
|
1997
|
+
# Before:
|
1998
|
+
Measurement.average(:temperature).class
|
1999
|
+
# => BigDecimal
|
1640
2000
|
|
1641
|
-
|
2001
|
+
# After:
|
2002
|
+
Measurement.average(:temperature).class
|
2003
|
+
# => Float
|
2004
|
+
```
|
1642
2005
|
|
1643
|
-
|
2006
|
+
Before this change, Rails just called `to_d` on average aggregates from the
|
2007
|
+
database adapter. This is not the case anymore. If you relied on that kind
|
2008
|
+
of magic, you now need to register your own `ActiveRecord::Type`
|
2009
|
+
(see `ActiveRecord::Attributes::ClassMethods` for documentation).
|
1644
2010
|
|
1645
|
-
*
|
2011
|
+
*Josua Schmid*
|
1646
2012
|
|
1647
|
-
|
2013
|
+
* PostgreSQL: introduce `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.datetime_type`.
|
1648
2014
|
|
1649
|
-
|
2015
|
+
This setting controls what native type Active Record should use when you call `datetime` in
|
2016
|
+
a migration or schema. It takes a symbol which must correspond to one of the configured
|
2017
|
+
`NATIVE_DATABASE_TYPES`. The default is `:timestamp`, meaning `t.datetime` in a migration
|
2018
|
+
will create a "timestamp without time zone" column. To use "timestamp with time zone",
|
2019
|
+
change this to `:timestamptz` in an initializer.
|
1650
2020
|
|
1651
|
-
|
2021
|
+
You should run `bin/rails db:migrate` to rebuild your schema.rb if you change this.
|
1652
2022
|
|
1653
|
-
*
|
2023
|
+
*Alex Ghiculescu*
|
1654
2024
|
|
1655
|
-
|
2025
|
+
* PostgreSQL: handle `timestamp with time zone` columns correctly in `schema.rb`.
|
1656
2026
|
|
1657
|
-
|
2027
|
+
Previously they dumped as `t.datetime :column_name`, now they dump as `t.timestamptz :column_name`,
|
2028
|
+
and are created as `timestamptz` columns when the schema is loaded.
|
1658
2029
|
|
1659
|
-
*
|
2030
|
+
*Alex Ghiculescu*
|
1660
2031
|
|
1661
|
-
*
|
1662
|
-
|
2032
|
+
* Removing trailing whitespace when matching columns in
|
2033
|
+
`ActiveRecord::Sanitization.disallow_raw_sql!`.
|
1663
2034
|
|
1664
|
-
|
2035
|
+
*Gannon McGibbon*, *Adrian Hirt*
|
1665
2036
|
|
1666
|
-
|
1667
|
-
has_secure_token :auth_token
|
1668
|
-
```
|
2037
|
+
* Expose a way for applications to set a `primary_abstract_class`.
|
1669
2038
|
|
1670
|
-
|
2039
|
+
Multiple database applications that use a primary abstract class that is not
|
2040
|
+
named `ApplicationRecord` can now set a specific class to be the `primary_abstract_class`.
|
1671
2041
|
|
1672
2042
|
```ruby
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
2043
|
+
class PrimaryApplicationRecord
|
2044
|
+
self.primary_abstract_class
|
2045
|
+
end
|
1676
2046
|
```
|
1677
2047
|
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
2048
|
+
When an application boots it automatically connects to the primary or first database in the
|
2049
|
+
database configuration file. In a multiple database application that then call `connects_to`
|
2050
|
+
needs to know that the default connection is the same as the `ApplicationRecord` connection.
|
2051
|
+
However, some applications have a differently named `ApplicationRecord`. This prevents Active
|
2052
|
+
Record from opening duplicate connections to the same database.
|
1681
2053
|
|
1682
|
-
*Eileen Uchitelle*, *John Crepezzi*
|
2054
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1683
2055
|
|
1684
|
-
*
|
2056
|
+
* Support hash config for `structure_dump_flags` and `structure_load_flags` flags.
|
2057
|
+
Now that Active Record supports multiple databases configuration,
|
2058
|
+
we need a way to pass specific flags for dump/load databases since
|
2059
|
+
the options are not the same for different adapters.
|
2060
|
+
We can use in the original way:
|
1685
2061
|
|
1686
|
-
|
2062
|
+
```ruby
|
2063
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = ['--no-defaults', '--skip-add-drop-table']
|
2064
|
+
# or
|
2065
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = '--no-defaults --skip-add-drop-table'
|
2066
|
+
```
|
1687
2067
|
|
1688
|
-
|
2068
|
+
And also use it passing a hash, with one or more keys, where the key
|
2069
|
+
is the adapter
|
1689
2070
|
|
1690
|
-
|
2071
|
+
```ruby
|
2072
|
+
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = {
|
2073
|
+
mysql2: ['--no-defaults', '--skip-add-drop-table'],
|
2074
|
+
postgres: '--no-tablespaces'
|
2075
|
+
}
|
2076
|
+
```
|
1691
2077
|
|
1692
|
-
|
2078
|
+
*Gustavo Gonzalez*
|
1693
2079
|
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
2080
|
+
* Connection specification now passes the "url" key as a configuration for the
|
2081
|
+
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
|
2082
|
+
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
|
2083
|
+
are assumed to be adapter specification urls.
|
1698
2084
|
|
1699
|
-
|
2085
|
+
Fixes #41137.
|
1700
2086
|
|
1701
|
-
|
2087
|
+
*Jonathan Bracy*
|
1702
2088
|
|
1703
|
-
|
2089
|
+
* Allow to opt-out of `strict_loading` mode on a per-record base.
|
1704
2090
|
|
1705
|
-
|
2091
|
+
This is useful when strict loading is enabled application wide or on a
|
2092
|
+
model level.
|
1706
2093
|
|
1707
|
-
|
2094
|
+
```ruby
|
2095
|
+
class User < ApplicationRecord
|
2096
|
+
has_many :bookmarks
|
2097
|
+
has_many :articles, strict_loading: true
|
2098
|
+
end
|
1708
2099
|
|
1709
|
-
|
2100
|
+
user = User.first
|
2101
|
+
user.articles # => ActiveRecord::StrictLoadingViolationError
|
2102
|
+
user.bookmarks # => #<ActiveRecord::Associations::CollectionProxy>
|
1710
2103
|
|
1711
|
-
|
2104
|
+
user.strict_loading!(true) # => true
|
2105
|
+
user.bookmarks # => ActiveRecord::StrictLoadingViolationError
|
1712
2106
|
|
1713
|
-
|
2107
|
+
user.strict_loading!(false) # => false
|
2108
|
+
user.bookmarks # => #<ActiveRecord::Associations::CollectionProxy>
|
2109
|
+
user.articles.strict_loading!(false) # => #<ActiveRecord::Associations::CollectionProxy>
|
2110
|
+
```
|
1714
2111
|
|
1715
|
-
|
2112
|
+
*Ayrton De Craene*
|
1716
2113
|
|
1717
|
-
|
2114
|
+
* Add `FinderMethods#sole` and `#find_sole_by` to find and assert the
|
2115
|
+
presence of exactly one record.
|
1718
2116
|
|
1719
|
-
|
2117
|
+
Used when you need a single row, but also want to assert that there aren't
|
2118
|
+
multiple rows matching the condition; especially for when database
|
2119
|
+
constraints aren't enough or are impractical.
|
1720
2120
|
|
1721
|
-
|
2121
|
+
```ruby
|
2122
|
+
Product.where(["price = %?", price]).sole
|
2123
|
+
# => ActiveRecord::RecordNotFound (if no Product with given price)
|
2124
|
+
# => #<Product ...> (if one Product with given price)
|
2125
|
+
# => ActiveRecord::SoleRecordExceeded (if more than one Product with given price)
|
1722
2126
|
|
1723
|
-
|
2127
|
+
user.api_keys.find_sole_by(key: key)
|
2128
|
+
# as above
|
2129
|
+
```
|
1724
2130
|
|
1725
|
-
*
|
2131
|
+
*Asherah Connor*
|
1726
2132
|
|
1727
|
-
|
2133
|
+
* Makes `ActiveRecord::AttributeMethods::Query` respect the getter overrides defined in the model.
|
1728
2134
|
|
1729
|
-
|
2135
|
+
Before:
|
1730
2136
|
|
1731
|
-
|
2137
|
+
```ruby
|
2138
|
+
class User
|
2139
|
+
def admin
|
2140
|
+
false # Overriding the getter to always return false
|
2141
|
+
end
|
2142
|
+
end
|
1732
2143
|
|
1733
|
-
|
2144
|
+
user = User.first
|
2145
|
+
user.update(admin: true)
|
1734
2146
|
|
1735
|
-
|
2147
|
+
user.admin # false (as expected, due to the getter overwrite)
|
2148
|
+
user.admin? # true (not expected, returned the DB column value)
|
2149
|
+
```
|
1736
2150
|
|
1737
|
-
|
2151
|
+
After this commit, `user.admin?` above returns false, as expected.
|
1738
2152
|
|
1739
|
-
|
2153
|
+
Fixes #40771.
|
1740
2154
|
|
1741
|
-
*
|
2155
|
+
*Felipe*
|
1742
2156
|
|
1743
|
-
|
2157
|
+
* Allow delegated_type to be specified primary_key and foreign_key.
|
1744
2158
|
|
1745
|
-
|
2159
|
+
Since delegated_type assumes that the foreign_key ends with `_id`,
|
2160
|
+
`singular_id` defined by it does not work when the foreign_key does
|
2161
|
+
not end with `id`. This change fixes it by taking into account
|
2162
|
+
`primary_key` and `foreign_key` in the options.
|
1746
2163
|
|
1747
|
-
*
|
2164
|
+
*Ryota Egusa*
|
1748
2165
|
|
1749
|
-
*
|
2166
|
+
* Expose an `invert_where` method that will invert all scope conditions.
|
1750
2167
|
|
1751
|
-
|
2168
|
+
```ruby
|
2169
|
+
class User
|
2170
|
+
scope :active, -> { where(accepted: true, locked: false) }
|
2171
|
+
end
|
1752
2172
|
|
1753
|
-
|
2173
|
+
User.active
|
2174
|
+
# ... WHERE `accepted` = 1 AND `locked` = 0
|
1754
2175
|
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
2176
|
+
User.active.invert_where
|
2177
|
+
# ... WHERE NOT (`accepted` = 1 AND `locked` = 0)
|
2178
|
+
```
|
1758
2179
|
|
1759
|
-
*
|
2180
|
+
*Kevin Deisz*
|
1760
2181
|
|
1761
|
-
*
|
2182
|
+
* Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
|
1762
2183
|
|
1763
|
-
|
2184
|
+
Previously, passing `false` would trigger the option validation logic
|
2185
|
+
to throw an error saying :polymorphic would not be a valid option.
|
1764
2186
|
|
1765
|
-
*
|
2187
|
+
*glaszig*
|
1766
2188
|
|
1767
|
-
|
2189
|
+
* Remove deprecated `database` kwarg from `connected_to`.
|
1768
2190
|
|
1769
|
-
*
|
2191
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1770
2192
|
|
1771
|
-
|
2193
|
+
* Allow adding nonnamed expression indexes to be revertible.
|
1772
2194
|
|
1773
|
-
|
2195
|
+
Previously, the following code would raise an error, when executed while rolling back,
|
2196
|
+
and the index name should be specified explicitly. Now, the index name is inferred
|
2197
|
+
automatically.
|
1774
2198
|
|
1775
|
-
|
2199
|
+
```ruby
|
2200
|
+
add_index(:items, "to_tsvector('english', description)")
|
2201
|
+
```
|
1776
2202
|
|
1777
|
-
|
2203
|
+
Fixes #40732.
|
1778
2204
|
|
1779
|
-
|
2205
|
+
*fatkodima*
|
1780
2206
|
|
1781
|
-
|
2207
|
+
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
1782
2208
|
|
1783
|
-
|
2209
|
+
Fixes #39065.
|
1784
2210
|
|
1785
|
-
|
2211
|
+
*Alex Ghiculescu*
|
1786
2212
|
|
1787
|
-
|
2213
|
+
* Add option to run `default_scope` on all queries.
|
1788
2214
|
|
1789
|
-
|
2215
|
+
Previously, a `default_scope` would only run on select or insert queries. In some cases, like non-Rails tenant sharding solutions, it may be desirable to run `default_scope` on all queries in order to ensure queries are including a foreign key for the shard (i.e. `blog_id`).
|
1790
2216
|
|
1791
|
-
|
2217
|
+
Now applications can add an option to run on all queries including select, insert, delete, and update by adding an `all_queries` option to the default scope definition.
|
1792
2218
|
|
1793
|
-
|
2219
|
+
```ruby
|
2220
|
+
class Article < ApplicationRecord
|
2221
|
+
default_scope -> { where(blog_id: Current.blog.id) }, all_queries: true
|
2222
|
+
end
|
2223
|
+
```
|
1794
2224
|
|
1795
|
-
*
|
2225
|
+
*Eileen M. Uchitelle*
|
1796
2226
|
|
1797
|
-
*
|
2227
|
+
* Add `where.associated` to check for the presence of an association.
|
1798
2228
|
|
1799
|
-
|
2229
|
+
```ruby
|
2230
|
+
# Before:
|
2231
|
+
account.users.joins(:contact).where.not(contact_id: nil)
|
1800
2232
|
|
1801
|
-
|
2233
|
+
# After:
|
2234
|
+
account.users.where.associated(:contact)
|
2235
|
+
```
|
1802
2236
|
|
1803
|
-
|
2237
|
+
Also mirrors `where.missing`.
|
1804
2238
|
|
1805
|
-
*
|
2239
|
+
*Kasper Timm Hansen*
|
1806
2240
|
|
1807
|
-
* Allow
|
2241
|
+
* Allow constructors (`build_association` and `create_association`) on
|
2242
|
+
`has_one :through` associations.
|
1808
2243
|
|
1809
|
-
*
|
2244
|
+
*Santiago Perez Perret*
|
1810
2245
|
|
1811
2246
|
|
1812
|
-
Please check [6-
|
2247
|
+
Please check [6-1-stable](https://github.com/rails/rails/blob/6-1-stable/activerecord/CHANGELOG.md) for previous changes.
|