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