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