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