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