activerecord 6.1.7 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +520 -1385
- data/MIT-LICENSE +1 -1
- data/README.rdoc +31 -31
- data/examples/performance.rb +2 -2
- data/lib/active_record/aggregations.rb +17 -14
- data/lib/active_record/association_relation.rb +2 -12
- data/lib/active_record/associations/alias_tracker.rb +25 -19
- data/lib/active_record/associations/association.rb +60 -21
- data/lib/active_record/associations/association_scope.rb +17 -12
- data/lib/active_record/associations/belongs_to_association.rb +37 -11
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +13 -4
- data/lib/active_record/associations/builder/association.rb +11 -5
- data/lib/active_record/associations/builder/belongs_to.rb +41 -14
- data/lib/active_record/associations/builder/collection_association.rb +10 -3
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +3 -7
- data/lib/active_record/associations/builder/has_many.rb +4 -4
- data/lib/active_record/associations/builder/has_one.rb +4 -4
- data/lib/active_record/associations/builder/singular_association.rb +6 -2
- data/lib/active_record/associations/collection_association.rb +46 -36
- data/lib/active_record/associations/collection_proxy.rb +44 -16
- data/lib/active_record/associations/disable_joins_association_scope.rb +59 -0
- data/lib/active_record/associations/errors.rb +265 -0
- data/lib/active_record/associations/foreign_association.rb +10 -3
- data/lib/active_record/associations/has_many_association.rb +29 -19
- data/lib/active_record/associations/has_many_through_association.rb +12 -7
- data/lib/active_record/associations/has_one_association.rb +20 -10
- data/lib/active_record/associations/has_one_through_association.rb +1 -1
- data/lib/active_record/associations/join_dependency/join_association.rb +27 -25
- data/lib/active_record/associations/join_dependency.rb +23 -15
- data/lib/active_record/associations/nested_error.rb +47 -0
- data/lib/active_record/associations/preloader/association.rb +212 -53
- data/lib/active_record/associations/preloader/batch.rb +48 -0
- data/lib/active_record/associations/preloader/branch.rb +153 -0
- data/lib/active_record/associations/preloader/through_association.rb +50 -16
- data/lib/active_record/associations/preloader.rb +50 -121
- data/lib/active_record/associations/singular_association.rb +15 -3
- data/lib/active_record/associations/through_association.rb +25 -14
- data/lib/active_record/associations.rb +404 -509
- data/lib/active_record/asynchronous_queries_tracker.rb +60 -0
- data/lib/active_record/attribute_assignment.rb +2 -14
- data/lib/active_record/attribute_methods/before_type_cast.rb +24 -2
- data/lib/active_record/attribute_methods/composite_primary_key.rb +84 -0
- data/lib/active_record/attribute_methods/dirty.rb +73 -22
- data/lib/active_record/attribute_methods/primary_key.rb +47 -27
- data/lib/active_record/attribute_methods/query.rb +31 -19
- data/lib/active_record/attribute_methods/read.rb +14 -11
- data/lib/active_record/attribute_methods/serialization.rb +174 -37
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +11 -9
- data/lib/active_record/attribute_methods/write.rb +12 -15
- data/lib/active_record/attribute_methods.rb +164 -52
- data/lib/active_record/attributes.rb +51 -49
- data/lib/active_record/autosave_association.rb +74 -57
- data/lib/active_record/base.rb +27 -5
- data/lib/active_record/callbacks.rb +18 -34
- data/lib/active_record/coders/column_serializer.rb +61 -0
- data/lib/active_record/coders/json.rb +1 -1
- data/lib/active_record/coders/yaml_column.rb +70 -46
- data/lib/active_record/connection_adapters/abstract/connection_handler.rb +284 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/queue.rb +211 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool/reaper.rb +79 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +327 -612
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +5 -17
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +199 -60
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +201 -64
- data/lib/active_record/connection_adapters/abstract/quoting.rb +119 -131
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +4 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +21 -20
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +186 -31
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +14 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +377 -142
- data/lib/active_record/connection_adapters/abstract/transaction.rb +361 -76
- data/lib/active_record/connection_adapters/abstract_adapter.rb +624 -163
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +345 -166
- data/lib/active_record/connection_adapters/column.rb +13 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +29 -130
- data/lib/active_record/connection_adapters/mysql/quoting.rb +81 -55
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +9 -0
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +10 -1
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +8 -2
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +45 -14
- data/lib/active_record/connection_adapters/mysql2/database_statements.rb +152 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +107 -68
- data/lib/active_record/connection_adapters/pool_config.rb +26 -16
- data/lib/active_record/connection_adapters/pool_manager.rb +19 -9
- data/lib/active_record/connection_adapters/postgresql/column.rb +30 -1
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +114 -54
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +6 -0
- 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/interval.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +3 -2
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +12 -3
- 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/uuid.rb +14 -4
- data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +137 -104
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +28 -0
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +92 -2
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +173 -3
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +78 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +401 -77
- data/lib/active_record/connection_adapters/postgresql/utils.rb +9 -10
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +518 -251
- data/lib/active_record/connection_adapters/schema_cache.rb +326 -102
- data/lib/active_record/connection_adapters/sqlite3/column.rb +62 -0
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +78 -55
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +68 -54
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +22 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +20 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +16 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +66 -22
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +372 -130
- data/lib/active_record/connection_adapters/statement_pool.rb +7 -0
- data/lib/active_record/connection_adapters/trilogy/database_statements.rb +99 -0
- data/lib/active_record/connection_adapters/trilogy_adapter.rb +229 -0
- data/lib/active_record/connection_adapters.rb +130 -6
- data/lib/active_record/connection_handling.rb +132 -146
- data/lib/active_record/core.rb +276 -251
- data/lib/active_record/counter_cache.rb +68 -34
- data/lib/active_record/database_configurations/connection_url_resolver.rb +9 -3
- data/lib/active_record/database_configurations/database_config.rb +34 -10
- data/lib/active_record/database_configurations/hash_config.rb +107 -31
- data/lib/active_record/database_configurations/url_config.rb +38 -13
- data/lib/active_record/database_configurations.rb +96 -60
- data/lib/active_record/delegated_type.rb +90 -20
- data/lib/active_record/deprecator.rb +7 -0
- data/lib/active_record/destroy_association_async_job.rb +4 -2
- data/lib/active_record/disable_joins_association_relation.rb +39 -0
- data/lib/active_record/dynamic_matchers.rb +3 -3
- data/lib/active_record/encryption/auto_filtered_parameters.rb +66 -0
- data/lib/active_record/encryption/cipher/aes256_gcm.rb +101 -0
- data/lib/active_record/encryption/cipher.rb +53 -0
- data/lib/active_record/encryption/config.rb +68 -0
- data/lib/active_record/encryption/configurable.rb +60 -0
- data/lib/active_record/encryption/context.rb +42 -0
- data/lib/active_record/encryption/contexts.rb +76 -0
- data/lib/active_record/encryption/derived_secret_key_provider.rb +18 -0
- data/lib/active_record/encryption/deterministic_key_provider.rb +14 -0
- data/lib/active_record/encryption/encryptable_record.rb +230 -0
- data/lib/active_record/encryption/encrypted_attribute_type.rb +175 -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 +170 -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 +157 -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 +53 -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_pack_message_serializer.rb +76 -0
- data/lib/active_record/encryption/message_serializer.rb +96 -0
- data/lib/active_record/encryption/null_encryptor.rb +25 -0
- data/lib/active_record/encryption/properties.rb +76 -0
- data/lib/active_record/encryption/read_only_null_encryptor.rb +28 -0
- data/lib/active_record/encryption/scheme.rb +100 -0
- data/lib/active_record/encryption.rb +56 -0
- data/lib/active_record/enum.rb +163 -63
- data/lib/active_record/errors.rb +210 -27
- data/lib/active_record/explain.rb +21 -12
- data/lib/active_record/explain_registry.rb +11 -6
- data/lib/active_record/explain_subscriber.rb +1 -1
- data/lib/active_record/fixture_set/file.rb +15 -1
- data/lib/active_record/fixture_set/model_metadata.rb +14 -4
- data/lib/active_record/fixture_set/render_context.rb +2 -0
- data/lib/active_record/fixture_set/table_row.rb +70 -14
- data/lib/active_record/fixture_set/table_rows.rb +4 -4
- data/lib/active_record/fixtures.rb +179 -112
- data/lib/active_record/future_result.rb +178 -0
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +85 -31
- data/lib/active_record/insert_all.rb +148 -32
- data/lib/active_record/integration.rb +14 -10
- data/lib/active_record/internal_metadata.rb +123 -23
- data/lib/active_record/legacy_yaml_adapter.rb +2 -39
- data/lib/active_record/locking/optimistic.rb +43 -27
- data/lib/active_record/locking/pessimistic.rb +15 -6
- data/lib/active_record/log_subscriber.rb +41 -29
- data/lib/active_record/marshalling.rb +56 -0
- data/lib/active_record/message_pack.rb +124 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +10 -10
- data/lib/active_record/middleware/database_selector.rb +23 -13
- data/lib/active_record/middleware/shard_selector.rb +62 -0
- data/lib/active_record/migration/command_recorder.rb +113 -16
- data/lib/active_record/migration/compatibility.rb +235 -46
- data/lib/active_record/migration/default_strategy.rb +22 -0
- data/lib/active_record/migration/execution_strategy.rb +19 -0
- data/lib/active_record/migration/join_table.rb +1 -1
- data/lib/active_record/migration/pending_migration_connection.rb +21 -0
- data/lib/active_record/migration.rb +374 -177
- data/lib/active_record/model_schema.rb +143 -159
- data/lib/active_record/nested_attributes.rb +48 -21
- data/lib/active_record/no_touching.rb +3 -3
- data/lib/active_record/normalization.rb +163 -0
- data/lib/active_record/persistence.rb +282 -283
- data/lib/active_record/promise.rb +84 -0
- data/lib/active_record/query_cache.rb +19 -25
- data/lib/active_record/query_logs.rb +189 -0
- data/lib/active_record/query_logs_formatter.rb +41 -0
- data/lib/active_record/querying.rb +44 -9
- data/lib/active_record/railtie.rb +234 -71
- data/lib/active_record/railties/controller_runtime.rb +25 -11
- data/lib/active_record/railties/databases.rake +189 -256
- data/lib/active_record/railties/job_runtime.rb +23 -0
- data/lib/active_record/readonly_attributes.rb +41 -3
- data/lib/active_record/reflection.rb +325 -103
- data/lib/active_record/relation/batches/batch_enumerator.rb +38 -9
- data/lib/active_record/relation/batches.rb +198 -63
- data/lib/active_record/relation/calculations.rb +300 -111
- data/lib/active_record/relation/delegation.rb +33 -22
- data/lib/active_record/relation/finder_methods.rb +123 -52
- data/lib/active_record/relation/merger.rb +26 -19
- data/lib/active_record/relation/predicate_builder/array_handler.rb +2 -2
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +38 -4
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +10 -7
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +5 -1
- data/lib/active_record/relation/predicate_builder.rb +29 -22
- data/lib/active_record/relation/query_attribute.rb +30 -12
- data/lib/active_record/relation/query_methods.rb +842 -150
- data/lib/active_record/relation/record_fetch_warning.rb +10 -9
- data/lib/active_record/relation/spawn_methods.rb +7 -6
- data/lib/active_record/relation/where_clause.rb +15 -36
- data/lib/active_record/relation.rb +736 -145
- data/lib/active_record/result.rb +67 -54
- data/lib/active_record/runtime_registry.rb +71 -13
- data/lib/active_record/sanitization.rb +84 -34
- data/lib/active_record/schema.rb +39 -23
- data/lib/active_record/schema_dumper.rb +90 -31
- data/lib/active_record/schema_migration.rb +74 -23
- data/lib/active_record/scoping/default.rb +72 -15
- data/lib/active_record/scoping/named.rb +5 -13
- data/lib/active_record/scoping.rb +65 -34
- data/lib/active_record/secure_password.rb +60 -0
- data/lib/active_record/secure_token.rb +21 -3
- data/lib/active_record/serialization.rb +6 -1
- data/lib/active_record/signed_id.rb +30 -9
- data/lib/active_record/statement_cache.rb +7 -7
- data/lib/active_record/store.rb +10 -10
- data/lib/active_record/suppressor.rb +13 -15
- data/lib/active_record/table_metadata.rb +7 -3
- data/lib/active_record/tasks/database_tasks.rb +277 -149
- data/lib/active_record/tasks/mysql_database_tasks.rb +16 -7
- data/lib/active_record/tasks/postgresql_database_tasks.rb +35 -26
- data/lib/active_record/tasks/sqlite_database_tasks.rb +16 -7
- data/lib/active_record/test_databases.rb +1 -1
- data/lib/active_record/test_fixtures.rb +173 -155
- data/lib/active_record/testing/query_assertions.rb +121 -0
- data/lib/active_record/timestamp.rb +32 -19
- data/lib/active_record/token_for.rb +123 -0
- data/lib/active_record/touch_later.rb +12 -7
- data/lib/active_record/transaction.rb +132 -0
- data/lib/active_record/transactions.rb +118 -41
- data/lib/active_record/translation.rb +3 -5
- data/lib/active_record/type/adapter_specific_registry.rb +32 -14
- data/lib/active_record/type/hash_lookup_type_map.rb +34 -1
- data/lib/active_record/type/internal/timezone.rb +7 -2
- data/lib/active_record/type/serialized.rb +9 -7
- data/lib/active_record/type/time.rb +4 -0
- data/lib/active_record/type/type_map.rb +17 -20
- data/lib/active_record/type.rb +1 -2
- data/lib/active_record/type_caster/connection.rb +4 -4
- data/lib/active_record/validations/absence.rb +1 -1
- data/lib/active_record/validations/associated.rb +13 -7
- data/lib/active_record/validations/numericality.rb +5 -4
- data/lib/active_record/validations/presence.rb +5 -28
- data/lib/active_record/validations/uniqueness.rb +64 -15
- data/lib/active_record/validations.rb +12 -5
- data/lib/active_record/version.rb +1 -1
- data/lib/active_record.rb +444 -32
- data/lib/arel/alias_predication.rb +1 -1
- data/lib/arel/attributes/attribute.rb +0 -8
- data/lib/arel/collectors/bind.rb +2 -0
- data/lib/arel/collectors/composite.rb +7 -0
- data/lib/arel/collectors/sql_string.rb +1 -1
- data/lib/arel/collectors/substitute_binds.rb +1 -1
- data/lib/arel/crud.rb +28 -22
- data/lib/arel/delete_manager.rb +18 -4
- data/lib/arel/errors.rb +10 -0
- data/lib/arel/factory_methods.rb +4 -0
- data/lib/arel/filter_predications.rb +9 -0
- data/lib/arel/insert_manager.rb +2 -3
- data/lib/arel/nodes/binary.rb +6 -7
- data/lib/arel/nodes/bound_sql_literal.rb +65 -0
- data/lib/arel/nodes/casted.rb +1 -1
- data/lib/arel/nodes/cte.rb +36 -0
- data/lib/arel/nodes/delete_statement.rb +12 -13
- data/lib/arel/nodes/filter.rb +10 -0
- data/lib/arel/nodes/fragments.rb +35 -0
- data/lib/arel/nodes/function.rb +1 -0
- data/lib/arel/nodes/homogeneous_in.rb +1 -9
- data/lib/arel/nodes/insert_statement.rb +2 -2
- data/lib/arel/nodes/leading_join.rb +8 -0
- data/lib/arel/nodes/{and.rb → nary.rb} +9 -2
- data/lib/arel/nodes/node.rb +115 -5
- data/lib/arel/nodes/select_core.rb +2 -2
- data/lib/arel/nodes/select_statement.rb +2 -2
- data/lib/arel/nodes/sql_literal.rb +13 -0
- data/lib/arel/nodes/table_alias.rb +4 -0
- data/lib/arel/nodes/update_statement.rb +8 -3
- data/lib/arel/nodes.rb +7 -2
- data/lib/arel/predications.rb +14 -4
- data/lib/arel/select_manager.rb +11 -5
- data/lib/arel/table.rb +9 -6
- data/lib/arel/tree_manager.rb +8 -15
- data/lib/arel/update_manager.rb +20 -5
- data/lib/arel/visitors/dot.rb +81 -90
- data/lib/arel/visitors/mysql.rb +23 -5
- data/lib/arel/visitors/postgresql.rb +1 -22
- data/lib/arel/visitors/to_sql.rb +170 -36
- data/lib/arel/visitors/visitor.rb +2 -2
- data/lib/arel.rb +23 -4
- data/lib/rails/generators/active_record/application_record/USAGE +8 -0
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +1 -1
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +4 -1
- data/lib/rails/generators/active_record/migration.rb +3 -1
- data/lib/rails/generators/active_record/model/USAGE +113 -0
- data/lib/rails/generators/active_record/model/model_generator.rb +15 -6
- 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 +100 -14
- data/lib/active_record/connection_adapters/legacy_pool_manager.rb +0 -35
- data/lib/active_record/null_relation.rb +0 -67
data/CHANGELOG.md
CHANGED
@@ -1,1767 +1,902 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 7.2.0 (August 09, 2024) ##
|
2
2
|
|
3
|
-
*
|
3
|
+
* Handle commas in Sqlite3 default function definitions.
|
4
4
|
|
5
|
-
|
5
|
+
*Stephen Margheim*
|
6
6
|
|
7
|
-
*
|
7
|
+
* Fixes `validates_associated` raising an exception when configured with a
|
8
|
+
singular association and having `index_nested_attribute_errors` enabled.
|
8
9
|
|
9
|
-
|
10
|
-
which is wasteful and cause problem with YAML safe_load.
|
10
|
+
*Martin Spickermann*
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
Fixes #44307.
|
17
|
-
|
18
|
-
*Nikita Vasilevsky*
|
19
|
-
|
20
|
-
## Rails 6.1.6.1 (July 12, 2022) ##
|
21
|
-
|
22
|
-
* Change ActiveRecord::Coders::YAMLColumn default to safe_load
|
23
|
-
|
24
|
-
This adds two new configuration options The configuration options are as
|
25
|
-
follows:
|
26
|
-
|
27
|
-
* `config.active_storage.use_yaml_unsafe_load`
|
28
|
-
|
29
|
-
When set to true, this configuration option tells Rails to use the old
|
30
|
-
"unsafe" YAML loading strategy, maintaining the existing behavior but leaving
|
31
|
-
the possible escalation vulnerability in place. Setting this option to true
|
32
|
-
is *not* recommended, but can aid in upgrading.
|
33
|
-
|
34
|
-
* `config.active_record.yaml_column_permitted_classes`
|
35
|
-
|
36
|
-
The "safe YAML" loading method does not allow all classes to be deserialized
|
37
|
-
by default. This option allows you to specify classes deemed "safe" in your
|
38
|
-
application. For example, if your application uses Symbol and Time in
|
39
|
-
serialized data, you can add Symbol and Time to the allowed list as follows:
|
40
|
-
|
41
|
-
```
|
42
|
-
config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
|
43
|
-
```
|
44
|
-
|
45
|
-
[CVE-2022-32224]
|
46
|
-
|
47
|
-
|
48
|
-
## Rails 6.1.6 (May 09, 2022) ##
|
49
|
-
|
50
|
-
* No changes.
|
51
|
-
|
52
|
-
|
53
|
-
## Rails 6.1.5.1 (April 26, 2022) ##
|
54
|
-
|
55
|
-
* No changes.
|
56
|
-
|
57
|
-
|
58
|
-
## Rails 6.1.5 (March 09, 2022) ##
|
59
|
-
|
60
|
-
* Fix `ActiveRecord::ConnectionAdapters::SchemaCache#deep_deduplicate` for Ruby 2.6.
|
61
|
-
|
62
|
-
Ruby 2.6 and 2.7 have slightly different implementations of the `String#-@` method.
|
63
|
-
In Ruby 2.6, the receiver of the `String#-@` method is modified under certain circumstances.
|
64
|
-
This was later identified as a bug (https://bugs.ruby-lang.org/issues/15926) and only
|
65
|
-
fixed in Ruby 2.7.
|
66
|
-
|
67
|
-
Before the changes in this commit, the
|
68
|
-
`ActiveRecord::ConnectionAdapters::SchemaCache#deep_deduplicate` method, which internally
|
69
|
-
calls the `String#-@` method, could also modify an input string argument in Ruby 2.6 --
|
70
|
-
changing a tainted, unfrozen string into a tainted, frozen string.
|
71
|
-
|
72
|
-
Fixes #43056
|
73
|
-
|
74
|
-
*Eric O'Hanlon*
|
75
|
-
|
76
|
-
* Fix migration compatibility to create SQLite references/belongs_to column as integer when
|
77
|
-
migration version is 6.0.
|
78
|
-
|
79
|
-
`reference`/`belongs_to` in migrations with version 6.0 were creating columns as
|
80
|
-
bigint instead of integer for the SQLite Adapter.
|
81
|
-
|
82
|
-
*Marcelo Lauxen*
|
83
|
-
|
84
|
-
* Fix dbconsole for 3-tier config.
|
85
|
-
|
86
|
-
*Eileen M. Uchitelle*
|
87
|
-
|
88
|
-
* Better handle SQL queries with invalid encoding.
|
89
|
-
|
90
|
-
```ruby
|
91
|
-
Post.create(name: "broken \xC8 UTF-8")
|
92
|
-
```
|
93
|
-
|
94
|
-
Would cause all adapters to fail in a non controlled way in the code
|
95
|
-
responsible to detect write queries.
|
96
|
-
|
97
|
-
The query is now properly passed to the database connection, which might or might
|
98
|
-
not be able to handle it, but will either succeed or failed in a more correct way.
|
99
|
-
|
100
|
-
*Jean Boussier*
|
101
|
-
|
102
|
-
* Ignore persisted in-memory records when merging target lists.
|
103
|
-
|
104
|
-
*Kevin Sjöberg*
|
105
|
-
|
106
|
-
* Fix regression bug that caused ignoring additional conditions for preloading
|
107
|
-
`has_many` through relations.
|
108
|
-
|
109
|
-
Fixes #43132
|
110
|
-
|
111
|
-
*Alexander Pauly*
|
112
|
-
|
113
|
-
* Fix `ActiveRecord::InternalMetadata` to not be broken by
|
114
|
-
`config.active_record.record_timestamps = false`
|
115
|
-
|
116
|
-
Since the model always create the timestamp columns, it has to set them, otherwise it breaks
|
117
|
-
various DB management tasks.
|
118
|
-
|
119
|
-
Fixes #42983
|
120
|
-
|
121
|
-
*Jean Boussier*
|
122
|
-
|
123
|
-
* Fix duplicate active record objects on `inverse_of`.
|
124
|
-
|
125
|
-
*Justin Carvalho*
|
126
|
-
|
127
|
-
* Fix duplicate objects stored in has many association after save.
|
128
|
-
|
129
|
-
Fixes #42549.
|
130
|
-
|
131
|
-
*Alex Ghiculescu*
|
132
|
-
|
133
|
-
* Fix performance regression in `CollectionAssocation#build`.
|
134
|
-
|
135
|
-
*Alex Ghiculescu*
|
136
|
-
|
137
|
-
* Fix retrieving default value for text column for MariaDB.
|
138
|
-
|
139
|
-
*fatkodima*
|
140
|
-
|
141
|
-
|
142
|
-
## Rails 6.1.4.7 (March 08, 2022) ##
|
143
|
-
|
144
|
-
* No changes.
|
145
|
-
|
146
|
-
|
147
|
-
## Rails 6.1.4.6 (February 11, 2022) ##
|
148
|
-
|
149
|
-
* No changes.
|
150
|
-
|
151
|
-
|
152
|
-
## Rails 6.1.4.5 (February 11, 2022) ##
|
153
|
-
|
154
|
-
* No changes.
|
155
|
-
|
156
|
-
|
157
|
-
## Rails 6.1.4.4 (December 15, 2021) ##
|
158
|
-
|
159
|
-
* No changes.
|
160
|
-
|
161
|
-
|
162
|
-
## Rails 6.1.4.3 (December 14, 2021) ##
|
163
|
-
|
164
|
-
* No changes.
|
165
|
-
|
166
|
-
|
167
|
-
## Rails 6.1.4.2 (December 14, 2021) ##
|
168
|
-
|
169
|
-
* No changes.
|
170
|
-
|
171
|
-
|
172
|
-
## Rails 6.1.4.1 (August 19, 2021) ##
|
173
|
-
|
174
|
-
* No changes.
|
175
|
-
|
176
|
-
|
177
|
-
## Rails 6.1.4 (June 24, 2021) ##
|
178
|
-
|
179
|
-
* Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError`.
|
180
|
-
|
181
|
-
*Jamie McCarthy*
|
182
|
-
|
183
|
-
* Raise an error if `pool_config` is `nil` in `set_pool_config`.
|
184
|
-
|
185
|
-
*Eileen M. Uchitelle*
|
186
|
-
|
187
|
-
* Fix compatibility with `psych >= 4`.
|
188
|
-
|
189
|
-
Starting in Psych 4.0.0 `YAML.load` behaves like `YAML.safe_load`. To preserve compatibility
|
190
|
-
Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
|
191
|
-
|
192
|
-
*Jean Boussier*
|
193
|
-
|
194
|
-
* Support using replicas when using `rails dbconsole`.
|
195
|
-
|
196
|
-
*Christopher Thornton*
|
197
|
-
|
198
|
-
* Restore connection pools after transactional tests.
|
199
|
-
|
200
|
-
*Eugene Kenny*
|
201
|
-
|
202
|
-
* Change `upsert_all` to fails cleanly for MySQL when `:unique_by` is used.
|
203
|
-
|
204
|
-
*Bastian Bartmann*
|
205
|
-
|
206
|
-
* Fix user-defined `self.default_scope` to respect table alias.
|
207
|
-
|
208
|
-
*Ryuta Kamizono*
|
209
|
-
|
210
|
-
* Clear `@cache_keys` cache after `update_all`, `delete_all`, `destroy_all`.
|
211
|
-
|
212
|
-
*Ryuta Kamizono*
|
213
|
-
|
214
|
-
* Changed Arel predications `contains` and `overlaps` to use
|
215
|
-
`quoted_node` so that PostgreSQL arrays are quoted properly.
|
216
|
-
|
217
|
-
*Bradley Priest*
|
218
|
-
|
219
|
-
* Fix `merge` when the `where` clauses have string contents.
|
220
|
-
|
221
|
-
*Ryuta Kamizono*
|
222
|
-
|
223
|
-
* Fix rollback of parent destruction with nested `dependent: :destroy`.
|
224
|
-
|
225
|
-
*Jacopo Beschi*
|
226
|
-
|
227
|
-
* Fix binds logging for `"WHERE ... IN ..."` statements.
|
228
|
-
|
229
|
-
*Ricardo Díaz*
|
230
|
-
|
231
|
-
* Handle `false` in relation strict loading checks.
|
232
|
-
|
233
|
-
Previously when a model had strict loading set to true and then had a
|
234
|
-
relation set `strict_loading` to false the false wasn't considered when
|
235
|
-
deciding whether to raise/warn about strict loading.
|
236
|
-
|
237
|
-
```
|
238
|
-
class Dog < ActiveRecord::Base
|
239
|
-
self.strict_loading_by_default = true
|
240
|
-
|
241
|
-
has_many :treats, strict_loading: false
|
242
|
-
end
|
243
|
-
```
|
244
|
-
|
245
|
-
In the example, `dog.treats` would still raise even though
|
246
|
-
`strict_loading` was set to false. This is a bug affecting more than
|
247
|
-
Active Storage which is why I made this PR superseding #41461. We need
|
248
|
-
to fix this for all applications since the behavior is a little
|
249
|
-
surprising. I took the test from #41461 and the code suggestion from #41453
|
250
|
-
with some additions.
|
251
|
-
|
252
|
-
*Eileen M. Uchitelle*, *Radamés Roriz*
|
253
|
-
|
254
|
-
* Fix numericality validator without precision.
|
255
|
-
|
256
|
-
*Ryuta Kamizono*
|
257
|
-
|
258
|
-
* Fix aggregate attribute on Enum types.
|
259
|
-
|
260
|
-
*Ryuta Kamizono*
|
261
|
-
|
262
|
-
* Fix `CREATE INDEX` statement generation for PostgreSQL.
|
263
|
-
|
264
|
-
*eltongo*
|
265
|
-
|
266
|
-
* Fix where clause on enum attribute when providing array of strings.
|
267
|
-
|
268
|
-
*Ryuta Kamizono*
|
269
|
-
|
270
|
-
* Fix `unprepared_statement` to work it when nesting.
|
271
|
-
|
272
|
-
*Ryuta Kamizono*
|
273
|
-
|
274
|
-
|
275
|
-
## Rails 6.1.3.2 (May 05, 2021) ##
|
276
|
-
|
277
|
-
* No changes.
|
278
|
-
|
279
|
-
|
280
|
-
## Rails 6.1.3.1 (March 26, 2021) ##
|
281
|
-
|
282
|
-
* No changes.
|
283
|
-
|
284
|
-
|
285
|
-
## Rails 6.1.3 (February 17, 2021) ##
|
286
|
-
|
287
|
-
* Fix the MySQL adapter to always set the right collation and charset
|
288
|
-
to the connection session.
|
289
|
-
|
290
|
-
*Rafael Mendonça França*
|
291
|
-
|
292
|
-
* Fix MySQL adapter handling of time objects when prepared statements
|
293
|
-
are enabled.
|
294
|
-
|
295
|
-
*Rafael Mendonça França*
|
296
|
-
|
297
|
-
* Fix scoping in enum fields using conditions that would generate
|
298
|
-
an `IN` clause.
|
299
|
-
|
300
|
-
*Ryuta Kamizono*
|
301
|
-
|
302
|
-
* Skip optimised #exist? query when #include? is called on a relation
|
303
|
-
with a having clause
|
304
|
-
|
305
|
-
Relations that have aliased select values AND a having clause that
|
306
|
-
references an aliased select value would generate an error when
|
307
|
-
#include? was called, due to an optimisation that would generate
|
308
|
-
call #exists? on the relation instead, which effectively alters
|
309
|
-
the select values of the query (and thus removes the aliased select
|
310
|
-
values), but leaves the having clause intact. Because the having
|
311
|
-
clause is then referencing an aliased column that is no longer
|
312
|
-
present in the simplified query, an ActiveRecord::InvalidStatement
|
313
|
-
error was raised.
|
314
|
-
|
315
|
-
An sample query affected by this problem:
|
316
|
-
|
317
|
-
```ruby
|
318
|
-
Author.select('COUNT(*) as total_posts', 'authors.*')
|
319
|
-
.joins(:posts)
|
320
|
-
.group(:id)
|
321
|
-
.having('total_posts > 2')
|
322
|
-
.include?(Author.first)
|
323
|
-
```
|
324
|
-
|
325
|
-
This change adds an addition check to the condition that skips the
|
326
|
-
simplified #exists? query, which simply checks for the presence of
|
327
|
-
a having clause.
|
328
|
-
|
329
|
-
Fixes #41417
|
330
|
-
|
331
|
-
*Michael Smart*
|
332
|
-
|
333
|
-
* Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
|
334
|
-
without Rails knowledge (e.g., if app gets kill -9d during long-running query or due to Rack::Timeout), app won't end
|
335
|
-
up in perpetual crash state for being inconsistent with Postgres.
|
336
|
-
|
337
|
-
*wbharding*, *Martin Tepper*
|
338
|
-
|
339
|
-
|
340
|
-
## Rails 6.1.2.1 (February 10, 2021) ##
|
341
|
-
|
342
|
-
* Fix possible DoS vector in PostgreSQL money type
|
343
|
-
|
344
|
-
Carefully crafted input can cause a DoS via the regular expressions used
|
345
|
-
for validating the money format in the PostgreSQL adapter. This patch
|
346
|
-
fixes the regexp.
|
347
|
-
|
348
|
-
Thanks to @dee-see from Hackerone for this patch!
|
349
|
-
|
350
|
-
[CVE-2021-22880]
|
351
|
-
|
352
|
-
*Aaron Patterson*
|
353
|
-
|
354
|
-
|
355
|
-
## Rails 6.1.2 (February 09, 2021) ##
|
356
|
-
|
357
|
-
* Fix timestamp type for sqlite3.
|
358
|
-
|
359
|
-
*Eileen M. Uchitelle*
|
360
|
-
|
361
|
-
* Make destroy async transactional.
|
362
|
-
|
363
|
-
An active record rollback could occur while enqueuing a job. In this
|
364
|
-
case the job would enqueue even though the database deletion
|
365
|
-
rolledback putting things in a funky state.
|
366
|
-
|
367
|
-
Now the jobs are only enqueued until after the db transaction has been committed.
|
368
|
-
|
369
|
-
*Cory Gwin*
|
370
|
-
|
371
|
-
* Fix malformed packet error in MySQL statement for connection configuration.
|
372
|
-
|
373
|
-
*robinroestenburg*
|
374
|
-
|
375
|
-
* Connection specification now passes the "url" key as a configuration for the
|
376
|
-
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
|
377
|
-
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
|
378
|
-
are assumed to be adapter specification urls.
|
379
|
-
|
380
|
-
Fixes #41137.
|
381
|
-
|
382
|
-
*Jonathan Bracy*
|
383
|
-
|
384
|
-
* Fix granular connection swapping when there are multiple abstract classes.
|
385
|
-
|
386
|
-
*Eileen M. Uchitelle*
|
387
|
-
|
388
|
-
* Fix `find_by` with custom primary key for belongs_to association.
|
389
|
-
|
390
|
-
*Ryuta Kamizono*
|
391
|
-
|
392
|
-
* Add support for `rails console --sandbox` for multiple database applications.
|
393
|
-
|
394
|
-
*alpaca-tc*
|
395
|
-
|
396
|
-
* Fix `where` on polymorphic association with empty array.
|
397
|
-
|
398
|
-
*Ryuta Kamizono*
|
399
|
-
|
400
|
-
* Fix preventing writes for `ApplicationRecord`.
|
401
|
-
|
402
|
-
*Eileen M. Uchitelle*
|
403
|
-
|
404
|
-
|
405
|
-
## Rails 6.1.1 (January 07, 2021) ##
|
406
|
-
|
407
|
-
* Fix fixtures loading when strict loading is enabled for the association.
|
408
|
-
|
409
|
-
*Alex Ghiculescu*
|
410
|
-
|
411
|
-
* Fix `where` with custom primary key for belongs_to association.
|
412
|
-
|
413
|
-
*Ryuta Kamizono*
|
414
|
-
|
415
|
-
* Fix `where` with aliased associations.
|
416
|
-
|
417
|
-
*Ryuta Kamizono*
|
418
|
-
|
419
|
-
* Fix `composed_of` with symbol mapping.
|
420
|
-
|
421
|
-
*Ryuta Kamizono*
|
422
|
-
|
423
|
-
* Don't skip money's type cast for pluck and calculations.
|
424
|
-
|
425
|
-
*Ryuta Kamizono*
|
426
|
-
|
427
|
-
* Fix `where` on polymorphic association with non Active Record object.
|
428
|
-
|
429
|
-
*Ryuta Kamizono*
|
430
|
-
|
431
|
-
* Make sure `db:prepare` works even the schema file doesn't exist.
|
432
|
-
|
433
|
-
*Rafael Mendonça França*
|
434
|
-
|
435
|
-
* Fix complicated `has_many :through` with nested where condition.
|
436
|
-
|
437
|
-
*Ryuta Kamizono*
|
438
|
-
|
439
|
-
* Handle STI models for `has_many dependent: :destroy_async`.
|
440
|
-
|
441
|
-
*Muhammad Usman*
|
442
|
-
|
443
|
-
* Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
|
444
|
-
|
445
|
-
Previously, passing `false` would trigger the option validation logic
|
446
|
-
to throw an error saying :polymorphic would not be a valid option.
|
447
|
-
|
448
|
-
*glaszig*
|
449
|
-
|
450
|
-
* Allow adding nonnamed expression indexes to be revertible.
|
451
|
-
|
452
|
-
Fixes #40732.
|
453
|
-
|
454
|
-
Previously, the following code would raise an error, when executed while rolling back,
|
455
|
-
and the index name should be specified explicitly. Now, the index name is inferred
|
456
|
-
automatically.
|
457
|
-
|
458
|
-
```ruby
|
459
|
-
add_index(:items, "to_tsvector('english', description)")
|
460
|
-
```
|
461
|
-
|
462
|
-
*fatkodima*
|
463
|
-
|
464
|
-
|
465
|
-
## Rails 6.1.0 (December 09, 2020) ##
|
466
|
-
|
467
|
-
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
468
|
-
|
469
|
-
Fixes #39065.
|
470
|
-
|
471
|
-
*Alex Ghiculescu*
|
472
|
-
|
473
|
-
* Change `attribute_for_inspect` to take `filter_attributes` in consideration.
|
474
|
-
|
475
|
-
*Rafael Mendonça França*
|
476
|
-
|
477
|
-
* Fix odd behavior of inverse_of with multiple belongs_to to same class.
|
478
|
-
|
479
|
-
Fixes #35204.
|
480
|
-
|
481
|
-
*Tomoyuki Kai*
|
482
|
-
|
483
|
-
* Build predicate conditions with objects that delegate `#id` and primary key:
|
484
|
-
|
485
|
-
```ruby
|
486
|
-
class AdminAuthor
|
487
|
-
delegate_missing_to :@author
|
488
|
-
|
489
|
-
def initialize(author)
|
490
|
-
@author = author
|
491
|
-
end
|
492
|
-
end
|
493
|
-
|
494
|
-
Post.where(author: AdminAuthor.new(author))
|
495
|
-
```
|
496
|
-
|
497
|
-
*Sean Doyle*
|
498
|
-
|
499
|
-
* Add `connected_to_many` API.
|
500
|
-
|
501
|
-
This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
|
502
|
-
|
503
|
-
Before:
|
504
|
-
|
505
|
-
AnimalsRecord.connected_to(role: :reading) do
|
506
|
-
MealsRecord.connected_to(role: :reading) do
|
507
|
-
Dog.first # read from animals replica
|
508
|
-
Dinner.first # read from meals replica
|
509
|
-
Person.first # read from primary writer
|
510
|
-
end
|
511
|
-
end
|
512
|
-
|
513
|
-
After:
|
514
|
-
|
515
|
-
ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
|
516
|
-
Dog.first # read from animals replica
|
517
|
-
Dinner.first # read from meals replica
|
518
|
-
Person.first # read from primary writer
|
519
|
-
end
|
520
|
-
|
521
|
-
*Eileen M. Uchitelle*, *John Crepezzi*
|
522
|
-
|
523
|
-
* Add option to raise or log for `ActiveRecord::StrictLoadingViolationError`.
|
524
|
-
|
525
|
-
Some applications may not want to raise an error in production if using `strict_loading`. This would allow an application to set strict loading to log for the production environment while still raising in development and test environments.
|
526
|
-
|
527
|
-
Set `config.active_record.action_on_strict_loading_violation` to `:log` errors instead of raising.
|
528
|
-
|
529
|
-
*Eileen M. Uchitelle*
|
530
|
-
|
531
|
-
* Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
|
532
|
-
|
533
|
-
Fixes #34255.
|
534
|
-
|
535
|
-
*Steven Weber*
|
536
|
-
|
537
|
-
* Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
|
538
|
-
|
539
|
-
Because the default behaviour when adding an index with multiple columns is to use all column names in the index name, this could frequently lead to overly long index names for polymorphic references which would fail the migration if it exceeded the database limit.
|
540
|
-
|
541
|
-
This change reduces the chance of that happening by using the reference name, e.g. `index_my_table_on_my_reference`.
|
542
|
-
|
543
|
-
Fixes #38655.
|
544
|
-
|
545
|
-
*Luke Redpath*
|
546
|
-
|
547
|
-
* MySQL: Uniqueness validator now respects default database collation,
|
548
|
-
no longer enforce case sensitive comparison by default.
|
549
|
-
|
550
|
-
*Ryuta Kamizono*
|
551
|
-
|
552
|
-
* Remove deprecated methods from `ActiveRecord::ConnectionAdapters::DatabaseLimits`.
|
553
|
-
|
554
|
-
`column_name_length`
|
555
|
-
`table_name_length`
|
556
|
-
`columns_per_table`
|
557
|
-
`indexes_per_table`
|
558
|
-
`columns_per_multicolumn_index`
|
559
|
-
`sql_query_length`
|
560
|
-
`joins_per_query`
|
561
|
-
|
562
|
-
*Rafael Mendonça França*
|
563
|
-
|
564
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?`.
|
565
|
-
|
566
|
-
*Rafael Mendonça França*
|
567
|
-
|
568
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?`.
|
569
|
-
|
570
|
-
*Rafael Mendonça França*
|
571
|
-
|
572
|
-
* Remove deprecated `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?`.
|
573
|
-
|
574
|
-
*Rafael Mendonça França*
|
575
|
-
|
576
|
-
* Remove deprecated `ActiveRecord::Base#update_attributes` and `ActiveRecord::Base#update_attributes!`.
|
577
|
-
|
578
|
-
*Rafael Mendonça França*
|
579
|
-
|
580
|
-
* Remove deprecated `migrations_path` argument in `ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version`.
|
581
|
-
|
582
|
-
*Rafael Mendonça França*
|
583
|
-
|
584
|
-
* Remove deprecated `config.active_record.sqlite3.represent_boolean_as_integer`.
|
585
|
-
|
586
|
-
*Rafael Mendonça França*
|
587
|
-
|
588
|
-
* `relation.create` does no longer leak scope to class level querying methods
|
589
|
-
in initialization block and callbacks.
|
590
|
-
|
591
|
-
Before:
|
592
|
-
|
593
|
-
User.where(name: "John").create do |john|
|
594
|
-
User.find_by(name: "David") # => nil
|
595
|
-
end
|
596
|
-
|
597
|
-
After:
|
598
|
-
|
599
|
-
User.where(name: "John").create do |john|
|
600
|
-
User.find_by(name: "David") # => #<User name: "David", ...>
|
601
|
-
end
|
602
|
-
|
603
|
-
*Ryuta Kamizono*
|
604
|
-
|
605
|
-
* Named scope chain does no longer leak scope to class level querying methods.
|
606
|
-
|
607
|
-
class User < ActiveRecord::Base
|
608
|
-
scope :david, -> { User.where(name: "David") }
|
609
|
-
end
|
610
|
-
|
611
|
-
Before:
|
612
|
-
|
613
|
-
User.where(name: "John").david
|
614
|
-
# SELECT * FROM users WHERE name = 'John' AND name = 'David'
|
615
|
-
|
616
|
-
After:
|
617
|
-
|
618
|
-
User.where(name: "John").david
|
619
|
-
# SELECT * FROM users WHERE name = 'David'
|
620
|
-
|
621
|
-
*Ryuta Kamizono*
|
622
|
-
|
623
|
-
* Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`.
|
624
|
-
|
625
|
-
`fetch`
|
626
|
-
`each`
|
627
|
-
`first`
|
628
|
-
`values`
|
629
|
-
`[]=`
|
630
|
-
|
631
|
-
*Rafael Mendonça França*
|
632
|
-
|
633
|
-
* `where.not` now generates NAND predicates instead of NOR.
|
634
|
-
|
635
|
-
Before:
|
636
|
-
|
637
|
-
User.where.not(name: "Jon", role: "admin")
|
638
|
-
# SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
|
639
|
-
|
640
|
-
After:
|
641
|
-
|
642
|
-
User.where.not(name: "Jon", role: "admin")
|
643
|
-
# SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
|
644
|
-
|
645
|
-
*Rafael Mendonça França*
|
646
|
-
|
647
|
-
* Remove deprecated `ActiveRecord::Result#to_hash` method.
|
648
|
-
|
649
|
-
*Rafael Mendonça França*
|
650
|
-
|
651
|
-
* Deprecate `ActiveRecord::Base.allow_unsafe_raw_sql`.
|
652
|
-
|
653
|
-
*Rafael Mendonça França*
|
654
|
-
|
655
|
-
* Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.
|
12
|
+
* The constant `ActiveRecord::ImmutableRelation` has been deprecated because
|
13
|
+
we want to reserve that name for a stronger sense of "immutable relation".
|
14
|
+
Please use `ActiveRecord::UnmodifiableRelation` instead.
|
656
15
|
|
657
|
-
*
|
658
|
-
|
659
|
-
* Allow users to silence the "Rails couldn't infer whether you are using multiple databases..."
|
660
|
-
message using `config.active_record.suppress_multiple_database_warning`.
|
661
|
-
|
662
|
-
*Omri Gabay*
|
663
|
-
|
664
|
-
* Connections can be granularly switched for abstract classes when `connected_to` is called.
|
16
|
+
*Xavier Noria*
|
665
17
|
|
666
|
-
|
18
|
+
* Add condensed `#inspect` for `ConnectionPool`, `AbstractAdapter`, and
|
19
|
+
`DatabaseConfig`.
|
667
20
|
|
668
|
-
|
21
|
+
*Hartley McGuire*
|
669
22
|
|
670
|
-
|
23
|
+
* Fixed a memory performance issue in Active Record attribute methods definition.
|
671
24
|
|
672
|
-
|
673
|
-
ActiveRecord::Base.connected_to(role: :reading) do
|
674
|
-
User.first # reads from default replica
|
675
|
-
Dog.first # reads from default replica
|
25
|
+
*Jean Boussier*
|
676
26
|
|
677
|
-
|
678
|
-
User.first # reads from default replica
|
679
|
-
Dog.first # reads from shard one primary
|
680
|
-
end
|
27
|
+
* Define the new Active Support notification event `start_transaction.active_record`.
|
681
28
|
|
682
|
-
|
683
|
-
|
29
|
+
This event is fired when database transactions or savepoints start, and
|
30
|
+
complements `transaction.active_record`, which is emitted when they finish.
|
684
31
|
|
685
|
-
|
686
|
-
User.first # reads from shard two primary
|
687
|
-
Dog.first # reads from default replica
|
688
|
-
end
|
689
|
-
end
|
690
|
-
```
|
32
|
+
The payload has the transaction (`:transaction`) and the connection (`:connection`).
|
691
33
|
|
692
|
-
*
|
34
|
+
*Xavier Noria*
|
693
35
|
|
694
|
-
*
|
36
|
+
* Fix an issue where the IDs reader method did not return expected results
|
37
|
+
for preloaded associations in models using composite primary keys.
|
695
38
|
|
696
|
-
*
|
39
|
+
*Jay Ang*
|
697
40
|
|
698
|
-
*
|
41
|
+
* The payload of `sql.active_record` Active Support notifications now has the current transaction in the `:transaction` key.
|
699
42
|
|
700
|
-
|
43
|
+
*Xavier Noria*
|
701
44
|
|
702
|
-
|
703
|
-
topic = Topic.first
|
704
|
-
topic.values_at(:title, :author_name)
|
705
|
-
# => ["Budget", "Jason"]
|
706
|
-
```
|
45
|
+
* The payload of `transaction.active_record` Active Support notifications now has the transaction the event is related to in the `:transaction` key.
|
707
46
|
|
708
|
-
|
47
|
+
*Xavier Noria*
|
709
48
|
|
710
|
-
|
49
|
+
* Define `ActiveRecord::Transaction#uuid`, which returns a UUID for the database transaction. This may be helpful when tracing database activity. These UUIDs are generated only on demand.
|
711
50
|
|
712
|
-
*
|
51
|
+
*Xavier Noria*
|
713
52
|
|
714
|
-
|
53
|
+
* Fix inference of association model on nested models with the same demodularized name.
|
715
54
|
|
716
|
-
|
55
|
+
E.g. with the following setup:
|
717
56
|
|
718
57
|
```ruby
|
719
|
-
class
|
720
|
-
|
721
|
-
published_at = article.published_at
|
722
|
-
where(published_at: published_at.beginning_of_year..published_at.end_of_year)
|
723
|
-
}
|
58
|
+
class Nested::Post < ApplicationRecord
|
59
|
+
has_one :post, through: :other
|
724
60
|
end
|
725
61
|
```
|
726
62
|
|
727
|
-
|
728
|
-
|
729
|
-
* `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
|
730
|
-
total number of rows affected, just like their non-batched counterparts.
|
731
|
-
|
732
|
-
```ruby
|
733
|
-
Person.in_batches.update_all("first_name = 'Eugene'") # => 42
|
734
|
-
Person.in_batches.delete_all # => 42
|
735
|
-
```
|
736
|
-
|
737
|
-
Fixes #40287.
|
738
|
-
|
739
|
-
*Eugene Kenny*
|
740
|
-
|
741
|
-
* Add support for PostgreSQL `interval` data type with conversion to
|
742
|
-
`ActiveSupport::Duration` when loading records from database and
|
743
|
-
serialization to ISO 8601 formatted duration string on save.
|
744
|
-
Add support to define a column in migrations and get it in a schema dump.
|
745
|
-
Optional column precision is supported.
|
746
|
-
|
747
|
-
To use this in 6.1, you need to place the next string to your model file:
|
63
|
+
Before, `#post` would infer the model as `Nested::Post`, but now it correctly infers `Post`.
|
748
64
|
|
749
|
-
|
65
|
+
*Joshua Young*
|
750
66
|
|
751
|
-
|
67
|
+
* PostgreSQL `Cidr#change?` detects the address prefix change.
|
752
68
|
|
753
|
-
|
754
|
-
|
755
|
-
Example:
|
756
|
-
|
757
|
-
create_table :events do |t|
|
758
|
-
t.string :name
|
759
|
-
t.interval :duration
|
760
|
-
end
|
69
|
+
*Taketo Takashima*
|
761
70
|
|
762
|
-
|
763
|
-
attribute :duration, :interval
|
764
|
-
end
|
71
|
+
* Change `BatchEnumerator#destroy_all` to return the total number of affected rows.
|
765
72
|
|
766
|
-
|
767
|
-
Event.last.duration # => 2 days
|
768
|
-
Event.last.duration.iso8601 # => "P2D"
|
769
|
-
Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
|
770
|
-
Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
|
73
|
+
Previously, it always returned `nil`.
|
771
74
|
|
772
|
-
*
|
75
|
+
*fatkodima*
|
773
76
|
|
774
|
-
*
|
77
|
+
* Support `touch_all` in batches.
|
775
78
|
|
776
79
|
```ruby
|
777
|
-
|
778
|
-
belongs_to :supplier, dependent: :destroy_async
|
779
|
-
end
|
80
|
+
Post.in_batches.touch_all
|
780
81
|
```
|
781
82
|
|
782
|
-
|
783
|
-
|
784
|
-
*DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
|
83
|
+
*fatkodima*
|
785
84
|
|
786
|
-
* Add
|
85
|
+
* Add support for `:if_not_exists` and `:force` options to `create_schema`.
|
787
86
|
|
788
|
-
*
|
87
|
+
*fatkodima*
|
789
88
|
|
790
|
-
* `
|
89
|
+
* Fix `index_errors` having incorrect index in association validation errors.
|
791
90
|
|
792
|
-
|
91
|
+
*lulalala*
|
793
92
|
|
794
|
-
|
93
|
+
* Add `index_errors: :nested_attributes_order` mode.
|
795
94
|
|
796
|
-
|
797
|
-
`ActiveRecord::StatementInvalid` when they encounter a connection error.
|
95
|
+
This indexes the association validation errors based on the order received by nested attributes setter, and respects the `reject_if` configuration. This enables API to provide enough information to the frontend to map the validation errors back to their respective form fields.
|
798
96
|
|
799
|
-
*
|
97
|
+
*lulalala*
|
800
98
|
|
801
|
-
* `
|
802
|
-
`ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
|
99
|
+
* Add `Rails.application.config.active_record.postgresql_adapter_decode_dates` to opt out of decoding dates automatically with the postgresql adapter. Defaults to true.
|
803
100
|
|
804
|
-
*
|
101
|
+
*Joé Dupuis*
|
805
102
|
|
806
|
-
*
|
103
|
+
* Association option `query_constraints` is deprecated in favor of `foreign_key`.
|
807
104
|
|
808
|
-
*
|
105
|
+
*Nikita Vasilevsky*
|
809
106
|
|
810
|
-
*
|
107
|
+
* Add `ENV["SKIP_TEST_DATABASE_TRUNCATE"]` flag to speed up multi-process test runs on large DBs when all tests run within default transaction.
|
811
108
|
|
812
|
-
|
109
|
+
This cuts ~10s from the test run of HEY when run by 24 processes against the 178 tables, since ~4,000 table truncates can then be skipped.
|
813
110
|
|
814
|
-
*
|
111
|
+
*DHH*
|
815
112
|
|
816
|
-
*
|
113
|
+
* Added support for recursive common table expressions.
|
817
114
|
|
818
115
|
```ruby
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
Comment.includes(:children).where("children.label": "child")
|
116
|
+
Post.with_recursive(
|
117
|
+
post_and_replies: [
|
118
|
+
Post.where(id: 42),
|
119
|
+
Post.joins('JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id'),
|
120
|
+
]
|
121
|
+
)
|
826
122
|
```
|
827
123
|
|
828
|
-
|
829
|
-
|
830
|
-
* Support storing demodulized class name for polymorphic type.
|
831
|
-
|
832
|
-
Before Rails 6.1, storing demodulized class name is supported only for STI type
|
833
|
-
by `store_full_sti_class` class attribute.
|
834
|
-
|
835
|
-
Now `store_full_class_name` class attribute can handle both STI and polymorphic types.
|
836
|
-
|
837
|
-
*Ryuta Kamizono*
|
124
|
+
Generates the following SQL:
|
838
125
|
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
```ruby
|
848
|
-
post = Post.select("UPPER(title) AS title").first
|
849
|
-
post.title # => "WELCOME TO THE WEBLOG"
|
850
|
-
post.body # => ActiveModel::MissingAttributeError
|
851
|
-
|
852
|
-
# Rails 6.0 (ignore the `select` values)
|
853
|
-
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
854
|
-
post.title # => "Welcome to the weblog"
|
855
|
-
post.body # => "Such a lovely day"
|
856
|
-
|
857
|
-
# Rails 6.1 (respect the `select` values)
|
858
|
-
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
859
|
-
post.title # => "WELCOME TO THE WEBLOG"
|
860
|
-
post.body # => ActiveModel::MissingAttributeError
|
126
|
+
```sql
|
127
|
+
WITH RECURSIVE "post_and_replies" AS (
|
128
|
+
(SELECT "posts".* FROM "posts" WHERE "posts"."id" = 42)
|
129
|
+
UNION ALL
|
130
|
+
(SELECT "posts".* FROM "posts" JOIN post_and_replies ON posts.in_reply_to_id = post_and_replies.id)
|
131
|
+
)
|
132
|
+
SELECT "posts".* FROM "posts"
|
861
133
|
```
|
862
134
|
|
863
|
-
*
|
135
|
+
*ClearlyClaire*
|
864
136
|
|
865
|
-
*
|
137
|
+
* `validate_constraint` can be called in a `change_table` block.
|
866
138
|
|
139
|
+
ex:
|
867
140
|
```ruby
|
868
|
-
|
869
|
-
|
141
|
+
change_table :products do |t|
|
142
|
+
t.check_constraint "price > discounted_price", name: "price_check", validate: false
|
143
|
+
t.validate_check_constraint "price_check"
|
870
144
|
end
|
871
|
-
|
872
|
-
# Rails 6.0
|
873
|
-
Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
|
874
|
-
|
875
|
-
# Rails 6.1
|
876
|
-
Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>
|
877
145
|
```
|
878
146
|
|
879
|
-
*
|
147
|
+
*Cody Cutrer*
|
880
148
|
|
881
|
-
*
|
149
|
+
* `PostgreSQLAdapter` now decodes columns of type date to `Date` instead of string.
|
882
150
|
|
151
|
+
Ex:
|
883
152
|
```ruby
|
884
|
-
|
885
|
-
|
886
|
-
end
|
887
|
-
|
888
|
-
Book.new.status # => "published"
|
153
|
+
ActiveRecord::Base.connection
|
154
|
+
.select_value("select '2024-01-01'::date").class #=> Date
|
889
155
|
```
|
890
156
|
|
891
|
-
*
|
892
|
-
|
893
|
-
* Deprecate YAML loading from legacy format older than Rails 5.0.
|
894
|
-
|
895
|
-
*Ryuta Kamizono*
|
896
|
-
|
897
|
-
* Added the setting `ActiveRecord::Base.immutable_strings_by_default`, which
|
898
|
-
allows you to specify that all string columns should be frozen unless
|
899
|
-
otherwise specified. This will reduce memory pressure for applications which
|
900
|
-
do not generally mutate string properties of Active Record objects.
|
157
|
+
*Joé Dupuis*
|
901
158
|
|
902
|
-
|
159
|
+
* Strict loading using `:n_plus_one_only` does not eagerly load child associations.
|
903
160
|
|
904
|
-
|
161
|
+
With this change, child associations are no longer eagerly loaded, to
|
162
|
+
match intended behavior and to prevent non-deterministic order issues caused
|
163
|
+
by calling methods like `first` or `last`. As `first` and `last` don't cause
|
164
|
+
an N+1 by themselves, calling child associations will no longer raise.
|
165
|
+
Fixes #49473.
|
905
166
|
|
906
|
-
|
907
|
-
|
908
|
-
* Support `relation.and` for intersection as Set theory.
|
167
|
+
Before:
|
909
168
|
|
910
169
|
```ruby
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
david_and_mary.and(mary_and_bob) # => [mary]
|
917
|
-
david_and_mary.or(mary_and_bob) # => [david, mary, bob]
|
170
|
+
person = Person.find(1)
|
171
|
+
person.strict_loading!(mode: :n_plus_one_only)
|
172
|
+
person.posts.first
|
173
|
+
# SELECT * FROM posts WHERE person_id = 1; -- non-deterministic order
|
174
|
+
person.posts.first.firm # raises ActiveRecord::StrictLoadingViolationError
|
918
175
|
```
|
919
176
|
|
920
|
-
|
921
|
-
|
922
|
-
* Merging conditions on the same column no longer maintain both conditions,
|
923
|
-
and will be consistently replaced by the latter condition in Rails 7.0.
|
924
|
-
To migrate to Rails 7.0's behavior, use `relation.merge(other, rewhere: true)`.
|
177
|
+
After:
|
925
178
|
|
926
179
|
```ruby
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
#
|
931
|
-
|
932
|
-
|
933
|
-
# Rails 6.1 with rewhere to migrate to Rails 7.0's behavior
|
934
|
-
Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
|
935
|
-
|
936
|
-
# Rails 7.0 (same behavior with IN clause, mergee side condition is consistently replaced)
|
937
|
-
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
938
|
-
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
|
180
|
+
person = Person.find(1)
|
181
|
+
person.strict_loading!(mode: :n_plus_one_only)
|
182
|
+
person.posts.first # this is 1+1, not N+1
|
183
|
+
# SELECT * FROM posts WHERE person_id = 1 ORDER BY id LIMIT 1;
|
184
|
+
person.posts.first.firm # no longer raises
|
939
185
|
```
|
940
186
|
|
941
|
-
*
|
942
|
-
|
943
|
-
* Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
|
187
|
+
*Reid Lynch*
|
944
188
|
|
945
|
-
|
189
|
+
* Allow `Sqlite3Adapter` to use `sqlite3` gem version `2.x`.
|
946
190
|
|
947
|
-
*
|
191
|
+
*Mike Dalessio*
|
948
192
|
|
949
|
-
|
950
|
-
`ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
|
951
|
-
was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
|
952
|
-
|
953
|
-
Usage:
|
193
|
+
* Allow `ActiveRecord::Base#pluck` to accept hash values.
|
954
194
|
|
955
195
|
```ruby
|
956
|
-
|
957
|
-
|
958
|
-
t.index "lower(name)", unique: true
|
959
|
-
end
|
196
|
+
# Before
|
197
|
+
Post.joins(:comments).pluck("posts.id", "comments.id", "comments.body")
|
960
198
|
|
961
|
-
|
199
|
+
# After
|
200
|
+
Post.joins(:comments).pluck(posts: [:id], comments: [:id, :body])
|
962
201
|
```
|
963
202
|
|
964
|
-
|
203
|
+
*fatkodima*
|
204
|
+
|
205
|
+
* Raise an `ActiveRecord::ActiveRecordError` error when the MySQL database returns an invalid version string.
|
965
206
|
|
966
|
-
*
|
207
|
+
*Kevin McPhillips*
|
967
208
|
|
968
|
-
*
|
209
|
+
* `ActiveRecord::Base.transaction` now yields an `ActiveRecord::Transaction` object.
|
969
210
|
|
970
|
-
|
211
|
+
This allows to register callbacks on it.
|
971
212
|
|
972
213
|
```ruby
|
973
|
-
|
974
|
-
|
214
|
+
Article.transaction do |transaction|
|
215
|
+
article.update(published: true)
|
216
|
+
transaction.after_commit do
|
217
|
+
PublishNotificationMailer.with(article: article).deliver_later
|
218
|
+
end
|
219
|
+
end
|
975
220
|
```
|
976
221
|
|
977
|
-
*
|
222
|
+
*Jean Boussier*
|
978
223
|
|
979
|
-
* Add `ActiveRecord::Base.
|
980
|
-
to enable/disable strict_loading mode by default for a model. The configuration's value is
|
981
|
-
inheritable by subclasses, but they can override that value and it will not impact parent class.
|
224
|
+
* Add `ActiveRecord::Base.current_transaction`.
|
982
225
|
|
983
|
-
|
226
|
+
Returns the current transaction, to allow registering callbacks on it.
|
984
227
|
|
985
228
|
```ruby
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
has_many :projects
|
229
|
+
Article.current_transaction.after_commit do
|
230
|
+
PublishNotificationMailer.with(article: article).deliver_later
|
990
231
|
end
|
991
|
-
|
992
|
-
dev = Developer.first
|
993
|
-
dev.projects.first
|
994
|
-
# => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.
|
995
232
|
```
|
996
233
|
|
997
|
-
*
|
998
|
-
|
999
|
-
* Deprecate passing an Active Record object to `quote`/`type_cast` directly.
|
1000
|
-
|
1001
|
-
*Ryuta Kamizono*
|
234
|
+
*Jean Boussier*
|
1002
235
|
|
1003
|
-
*
|
236
|
+
* Add `ActiveRecord.after_all_transactions_commit` callback.
|
1004
237
|
|
1005
|
-
|
238
|
+
Useful for code that may run either inside or outside a transaction and needs
|
239
|
+
to perform work after the state changes have been properly persisted.
|
1006
240
|
|
1007
241
|
```ruby
|
1008
|
-
|
242
|
+
def publish_article(article)
|
243
|
+
article.update(published: true)
|
244
|
+
ActiveRecord.after_all_transactions_commit do
|
245
|
+
PublishNotificationMailer.with(article: article).deliver_later
|
246
|
+
end
|
1009
247
|
end
|
1010
248
|
```
|
1011
249
|
|
1012
|
-
|
1013
|
-
|
1014
|
-
```ruby
|
1015
|
-
create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
1016
|
-
end
|
1017
|
-
```
|
250
|
+
In the above example, the block is either executed immediately if called outside
|
251
|
+
of a transaction, or called after the open transaction is committed.
|
1018
252
|
|
1019
|
-
|
253
|
+
If the transaction is rolled back, the block isn't called.
|
1020
254
|
|
1021
|
-
*
|
1022
|
-
See ActiveRecord::DelegatedType for the full description.
|
255
|
+
*Jean Boussier*
|
1023
256
|
|
1024
|
-
|
257
|
+
* Add the ability to ignore counter cache columns until they are backfilled.
|
1025
258
|
|
1026
|
-
|
259
|
+
Starting to use counter caches on existing large tables can be troublesome, because the column
|
260
|
+
values must be backfilled separately of the column addition (to not lock the table for too long)
|
261
|
+
and before the use of `:counter_cache` (otherwise methods like `size`/`any?`/etc, which use
|
262
|
+
counter caches internally, can produce incorrect results). People usually use database triggers
|
263
|
+
or callbacks on child associations while backfilling before introducing a counter cache
|
264
|
+
configuration to the association.
|
1027
265
|
|
1028
|
-
|
266
|
+
Now, to safely backfill the column, while keeping the column updated with child records added/removed, use:
|
1029
267
|
|
1030
268
|
```ruby
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
|
1035
|
-
# => {
|
1036
|
-
# [1, 1] => 50,
|
1037
|
-
# [2, 2] => 60
|
1038
|
-
# }
|
1039
|
-
|
1040
|
-
# use `uniq!(:group)` to deduplicate group fields.
|
1041
|
-
accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
|
1042
|
-
# => {
|
1043
|
-
# 1 => 50,
|
1044
|
-
# 2 => 60
|
1045
|
-
# }
|
269
|
+
class Comment < ApplicationRecord
|
270
|
+
belongs_to :post, counter_cache: { active: false }
|
271
|
+
end
|
1046
272
|
```
|
1047
273
|
|
1048
|
-
|
274
|
+
While the counter cache is not "active", the methods like `size`/`any?`/etc will not use it,
|
275
|
+
but get the results directly from the database. After the counter cache column is backfilled, simply
|
276
|
+
remove the `{ active: false }` part from the counter cache definition, and it will now be used by the
|
277
|
+
mentioned methods.
|
1049
278
|
|
1050
|
-
*
|
279
|
+
*fatkodima*
|
1051
280
|
|
1052
|
-
|
281
|
+
* Retry known idempotent SELECT queries on connection-related exceptions.
|
1053
282
|
|
1054
|
-
|
1055
|
-
|
283
|
+
SELECT queries we construct by walking the Arel tree and / or with known model attributes
|
284
|
+
are idempotent and can safely be retried in the case of a connection error. Previously,
|
285
|
+
adapters such as `TrilogyAdapter` would raise `ActiveRecord::ConnectionFailed: Trilogy::EOFError`
|
286
|
+
when encountering a connection error mid-request.
|
1056
287
|
|
1057
|
-
|
1058
|
-
accounts.merge(accounts.rewhere(id: 3))
|
1059
|
-
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
|
288
|
+
*Adrianna Chang*
|
1060
289
|
|
1061
|
-
|
1062
|
-
accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
|
1063
|
-
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
|
1064
|
-
```
|
290
|
+
* Allow association's `foreign_key` to be composite.
|
1065
291
|
|
1066
|
-
|
292
|
+
`query_constraints` option was the only way to configure a composite foreign key by passing an `Array`.
|
293
|
+
Now it's possible to pass an Array value as `foreign_key` to achieve the same behavior of an association.
|
1067
294
|
|
1068
|
-
*
|
295
|
+
*Nikita Vasilevsky*
|
1069
296
|
|
1070
|
-
|
1071
|
-
cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
|
1072
|
-
upon subsequent transactions by maintaining parity with the corresponding
|
1073
|
-
database record's `lock_version` column.
|
297
|
+
* Allow association's `primary_key` to be composite.
|
1074
298
|
|
1075
|
-
|
299
|
+
Association's `primary_key` can be composite when derived from associated model `primary_key` or `query_constraints`.
|
300
|
+
Now it's possible to explicitly set it as composite on the association.
|
1076
301
|
|
1077
|
-
*
|
302
|
+
*Nikita Vasilevsky*
|
1078
303
|
|
1079
|
-
*
|
304
|
+
* Add `config.active_record.permanent_connection_checkout` setting.
|
1080
305
|
|
1081
|
-
|
1082
|
-
david_and_mary = Author.where(id: david.id..mary.id)
|
306
|
+
Controls whether `ActiveRecord::Base.connection` raises an error, emits a deprecation warning, or neither.
|
1083
307
|
|
1084
|
-
|
1085
|
-
|
308
|
+
`ActiveRecord::Base.connection` checkouts a database connection from the pool and keeps it leased until the end of
|
309
|
+
the request or job. This behavior can be undesirable in environments that use many more threads or fibers than there
|
310
|
+
is available connections.
|
1086
311
|
|
1087
|
-
|
1088
|
-
|
312
|
+
This configuration can be used to track down and eliminate code that calls `ActiveRecord::Base.connection` and
|
313
|
+
migrate it to use `ActiveRecord::Base.with_connection` instead.
|
1089
314
|
|
1090
|
-
|
1091
|
-
david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]
|
1092
|
-
```
|
315
|
+
The default behavior remains unchanged, and there is currently no plans to change the default.
|
1093
316
|
|
1094
|
-
*
|
317
|
+
*Jean Boussier*
|
1095
318
|
|
1096
|
-
* Add
|
1097
|
-
set to expire and scoped with a purpose. This is particularly useful for things like password reset
|
1098
|
-
or email verification, where you want the bearer of the signed id to be able to interact with the
|
1099
|
-
underlying record, but usually only within a certain time period.
|
319
|
+
* Add dirties option to uncached.
|
1100
320
|
|
1101
|
-
|
1102
|
-
|
321
|
+
This adds a `dirties` option to `ActiveRecord::Base.uncached` and
|
322
|
+
`ActiveRecord::ConnectionAdapters::ConnectionPool#uncached`.
|
1103
323
|
|
1104
|
-
|
324
|
+
When set to `true` (the default), writes will clear all query caches belonging to the current thread.
|
325
|
+
When set to `false`, writes to the affected connection pool will not clear any query cache.
|
1105
326
|
|
1106
|
-
|
1107
|
-
User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
|
327
|
+
This is needed by Solid Cache so that cache writes do not clear query caches.
|
1108
328
|
|
1109
|
-
|
1110
|
-
User.find_signed signed_id, purpose: :password_reset # => User.first
|
329
|
+
*Donal McBreen*
|
1111
330
|
|
1112
|
-
|
1113
|
-
```
|
331
|
+
* Deprecate `ActiveRecord::Base.connection` in favor of `.lease_connection`.
|
1114
332
|
|
1115
|
-
|
333
|
+
The method has been renamed as `lease_connection` to better reflect that the returned
|
334
|
+
connection will be held for the duration of the request or job.
|
1116
335
|
|
1117
|
-
|
336
|
+
This deprecation is a soft deprecation, no warnings will be issued and there is no
|
337
|
+
current plan to remove the method.
|
1118
338
|
|
1119
|
-
*
|
339
|
+
*Jean Boussier*
|
1120
340
|
|
1121
|
-
*
|
341
|
+
* Deprecate `ActiveRecord::ConnectionAdapters::ConnectionPool#connection`.
|
1122
342
|
|
1123
|
-
|
343
|
+
The method has been renamed as `lease_connection` to better reflect that the returned
|
344
|
+
connection will be held for the duration of the request or job.
|
1124
345
|
|
1125
|
-
*
|
346
|
+
*Jean Boussier*
|
1126
347
|
|
1127
|
-
|
348
|
+
* Expose a generic fixture accessor for fixture names that may conflict with Minitest.
|
1128
349
|
|
1129
350
|
```ruby
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
posts.count
|
1134
|
-
# => { false => 10 }
|
1135
|
-
|
1136
|
-
# unscope both hidden columns
|
1137
|
-
posts.unscope(where: :hidden).count
|
1138
|
-
# => { false => 11, true => 1 }
|
1139
|
-
|
1140
|
-
# unscope only comments.hidden column
|
1141
|
-
posts.unscope(where: :"comments.hidden").count
|
1142
|
-
# => { false => 11 }
|
351
|
+
assert_equal "Ruby on Rails", web_sites(:rubyonrails).name
|
352
|
+
assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name
|
1143
353
|
```
|
1144
354
|
|
1145
|
-
*
|
1146
|
-
|
1147
|
-
* Fix `rewhere` to truly overwrite collided where clause by new where clause.
|
1148
|
-
|
1149
|
-
```ruby
|
1150
|
-
steve = Person.find_by(name: "Steve")
|
1151
|
-
david = Author.find_by(name: "David")
|
1152
|
-
|
1153
|
-
relation = Essay.where(writer: steve)
|
1154
|
-
|
1155
|
-
# Before
|
1156
|
-
relation.rewhere(writer: david).to_a # => []
|
355
|
+
*Jean Boussier*
|
1157
356
|
|
1158
|
-
|
1159
|
-
|
1160
|
-
```
|
357
|
+
* Using `Model.query_constraints` with a single non-primary-key column used to raise as expected, but with an
|
358
|
+
incorrect error message.
|
1161
359
|
|
1162
|
-
|
360
|
+
This has been fixed to raise with a more appropriate error message.
|
1163
361
|
|
1164
|
-
*
|
362
|
+
*Joshua Young*
|
1165
363
|
|
1166
|
-
|
1167
|
-
p Knot.create
|
1168
|
-
=> #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
|
1169
|
-
```
|
364
|
+
* Fix `has_one` association autosave setting the foreign key attribute when it is unchanged.
|
1170
365
|
|
1171
|
-
|
366
|
+
This behavior is also inconsistent with autosaving `belongs_to` and can have unintended side effects like raising
|
367
|
+
an `ActiveRecord::ReadonlyAttributeError` when the foreign key attribute is marked as read-only.
|
1172
368
|
|
1173
|
-
*
|
369
|
+
*Joshua Young*
|
1174
370
|
|
1175
|
-
|
371
|
+
* Remove deprecated behavior that would rollback a transaction block when exited using `return`, `break` or `throw`.
|
1176
372
|
|
1177
|
-
*
|
373
|
+
*Rafael Mendonça França*
|
1178
374
|
|
1179
|
-
|
375
|
+
* Deprecate `Rails.application.config.active_record.commit_transaction_on_non_local_return`.
|
1180
376
|
|
1181
|
-
*
|
377
|
+
*Rafael Mendonça França*
|
1182
378
|
|
1183
|
-
|
379
|
+
* Remove deprecated support to pass `rewhere` to `ActiveRecord::Relation#merge`.
|
1184
380
|
|
1185
|
-
*
|
381
|
+
*Rafael Mendonça França*
|
1186
382
|
|
1187
|
-
|
383
|
+
* Remove deprecated support to pass `deferrable: true` to `add_foreign_key`.
|
1188
384
|
|
1189
|
-
*
|
385
|
+
*Rafael Mendonça França*
|
1190
386
|
|
1191
|
-
|
387
|
+
* Remove deprecated support to quote `ActiveSupport::Duration`.
|
1192
388
|
|
1193
|
-
*
|
389
|
+
*Rafael Mendonça França*
|
1194
390
|
|
1195
|
-
* Remove
|
391
|
+
* Remove deprecated `#quote_bound_value`.
|
1196
392
|
|
1197
|
-
*
|
393
|
+
*Rafael Mendonça França*
|
1198
394
|
|
1199
|
-
*
|
395
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::ConnectionPool#connection_klass`.
|
1200
396
|
|
1201
|
-
|
397
|
+
*Rafael Mendonça França*
|
1202
398
|
|
1203
|
-
|
399
|
+
* Remove deprecated support to apply `#connection_pool_list`, `#active_connections?`, `#clear_active_connections!`,
|
400
|
+
`#clear_reloadable_connections!`, `#clear_all_connections!` and `#flush_idle_connections!` to the connections pools
|
401
|
+
for the current role when the `role` argument isn't provided.
|
1204
402
|
|
1205
|
-
*
|
403
|
+
*Rafael Mendonça França*
|
1206
404
|
|
1207
|
-
|
1208
|
-
index won't be added.
|
405
|
+
* Remove deprecated `#all_connection_pools`.
|
1209
406
|
|
1210
|
-
|
407
|
+
*Rafael Mendonça França*
|
1211
408
|
|
1212
|
-
|
1213
|
-
add_index :users, :account_id, if_not_exists: true
|
1214
|
-
```
|
409
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache#data_sources`.
|
1215
410
|
|
1216
|
-
|
1217
|
-
created within that migration so that if table and its indexes exist then there is no
|
1218
|
-
attempt to create them again.
|
411
|
+
*Rafael Mendonça França*
|
1219
412
|
|
1220
|
-
|
413
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SchemaCache.load_from`.
|
1221
414
|
|
1222
|
-
*
|
415
|
+
*Rafael Mendonça França*
|
1223
416
|
|
1224
|
-
|
417
|
+
* Remove deprecated `#all_foreign_keys_valid?` from database adapters.
|
1225
418
|
|
1226
|
-
*
|
419
|
+
*Rafael Mendonça França*
|
1227
420
|
|
1228
|
-
|
421
|
+
* Remove deprecated support to passing coder and class as second argument to `serialize`.
|
1229
422
|
|
1230
|
-
|
423
|
+
*Rafael Mendonça França*
|
1231
424
|
|
1232
|
-
|
425
|
+
* Remove deprecated support to `ActiveRecord::Base#read_attribute(:id)` to return the custom primary key value.
|
1233
426
|
|
1234
|
-
|
1235
|
-
Person.find_each(order: :desc) do |person|
|
1236
|
-
person.party_all_night!
|
1237
|
-
end
|
1238
|
-
```
|
427
|
+
*Rafael Mendonça França*
|
1239
428
|
|
1240
|
-
|
429
|
+
* Remove deprecated `TestFixtures.fixture_path`.
|
1241
430
|
|
1242
|
-
*
|
431
|
+
*Rafael Mendonça França*
|
1243
432
|
|
1244
|
-
|
433
|
+
* Remove deprecated behavior to support referring to a singular association by its plural name.
|
1245
434
|
|
1246
|
-
*
|
435
|
+
*Rafael Mendonça França*
|
1247
436
|
|
1248
|
-
*
|
437
|
+
* Deprecate `Rails.application.config.active_record.allow_deprecated_singular_associations_name`.
|
1249
438
|
|
1250
|
-
|
439
|
+
*Rafael Mendonça França*
|
1251
440
|
|
1252
|
-
|
441
|
+
* Remove deprecated support to passing `SchemaMigration` and `InternalMetadata` classes as arguments to
|
442
|
+
`ActiveRecord::MigrationContext`.
|
1253
443
|
|
1254
|
-
*
|
444
|
+
*Rafael Mendonça França*
|
1255
445
|
|
1256
|
-
|
446
|
+
* Remove deprecated `ActiveRecord::Migration.check_pending!` method.
|
1257
447
|
|
1258
|
-
*
|
448
|
+
*Rafael Mendonça França*
|
1259
449
|
|
1260
|
-
|
450
|
+
* Remove deprecated `ActiveRecord::LogSubscriber.runtime` method.
|
1261
451
|
|
1262
|
-
*
|
452
|
+
*Rafael Mendonça França*
|
1263
453
|
|
1264
|
-
|
454
|
+
* Remove deprecated `ActiveRecord::LogSubscriber.runtime=` method.
|
1265
455
|
|
1266
|
-
|
456
|
+
*Rafael Mendonça França*
|
1267
457
|
|
1268
|
-
|
458
|
+
* Remove deprecated `ActiveRecord::LogSubscriber.reset_runtime` method.
|
1269
459
|
|
1270
|
-
*
|
460
|
+
*Rafael Mendonça França*
|
1271
461
|
|
1272
|
-
|
462
|
+
* Remove deprecated support to define `explain` in the connection adapter with 2 arguments.
|
1273
463
|
|
1274
|
-
*
|
464
|
+
*Rafael Mendonça França*
|
1275
465
|
|
1276
|
-
*
|
466
|
+
* Remove deprecated `ActiveRecord::ActiveJobRequiredError`.
|
1277
467
|
|
1278
|
-
|
468
|
+
*Rafael Mendonça França*
|
1279
469
|
|
1280
|
-
|
470
|
+
* Remove deprecated `ActiveRecord::Base.clear_active_connections!`.
|
1281
471
|
|
1282
|
-
*
|
472
|
+
*Rafael Mendonça França*
|
1283
473
|
|
1284
|
-
|
474
|
+
* Remove deprecated `ActiveRecord::Base.clear_reloadable_connections!`.
|
1285
475
|
|
1286
|
-
|
476
|
+
*Rafael Mendonça França*
|
1287
477
|
|
1288
|
-
|
478
|
+
* Remove deprecated `ActiveRecord::Base.clear_all_connections!`.
|
1289
479
|
|
1290
|
-
|
1291
|
-
# config/database.yml
|
1292
|
-
production:
|
1293
|
-
primary:
|
1294
|
-
database: my_database
|
1295
|
-
primary_shard_one:
|
1296
|
-
database: my_database_shard_one
|
1297
|
-
```
|
480
|
+
*Rafael Mendonça França*
|
1298
481
|
|
1299
|
-
|
482
|
+
* Remove deprecated `ActiveRecord::Base.flush_idle_connections!`.
|
1300
483
|
|
1301
|
-
|
1302
|
-
class ApplicationRecord < ActiveRecord::Base
|
1303
|
-
self.abstract_class = true
|
484
|
+
*Rafael Mendonça França*
|
1304
485
|
|
1305
|
-
|
1306
|
-
default: { writing: :primary },
|
1307
|
-
shard_one: { writing: :primary_shard_one }
|
1308
|
-
}
|
1309
|
-
```
|
486
|
+
* Remove deprecated `name` argument from `ActiveRecord::Base.remove_connection`.
|
1310
487
|
|
1311
|
-
|
488
|
+
*Rafael Mendonça França*
|
1312
489
|
|
1313
|
-
|
1314
|
-
ActiveRecord::Base.connected_to(shard: :shard_one) do
|
1315
|
-
# Read from shard one
|
1316
|
-
end
|
1317
|
-
```
|
490
|
+
* Remove deprecated support to call `alias_attribute` with non-existent attribute names.
|
1318
491
|
|
1319
|
-
|
492
|
+
*Rafael Mendonça França*
|
1320
493
|
|
1321
|
-
|
494
|
+
* Remove deprecated `Rails.application.config.active_record.suppress_multiple_database_warning`.
|
1322
495
|
|
1323
|
-
*
|
496
|
+
*Rafael Mendonça França*
|
1324
497
|
|
1325
|
-
|
498
|
+
* Add `ActiveRecord::Encryption::MessagePackMessageSerializer`.
|
1326
499
|
|
1327
|
-
|
500
|
+
Serialize data to the MessagePack format, for efficient storage in binary columns.
|
1328
501
|
|
1329
|
-
|
1330
|
-
|
1331
|
-
db_config.spec_name
|
1332
|
-
```
|
502
|
+
The binary encoding requires around 30% less space than the base64 encoding
|
503
|
+
used by the default serializer.
|
1333
504
|
|
1334
|
-
|
505
|
+
*Donal McBreen*
|
1335
506
|
|
1336
|
-
|
1337
|
-
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", name: "primary")
|
1338
|
-
db_config.name
|
1339
|
-
```
|
507
|
+
* Add support for encrypting binary columns.
|
1340
508
|
|
1341
|
-
|
509
|
+
Ensure encryption and decryption pass `Type::Binary::Data` around for binary data.
|
1342
510
|
|
1343
|
-
|
511
|
+
Previously encrypting binary columns with the `ActiveRecord::Encryption::MessageSerializer`
|
512
|
+
incidentally worked for MySQL and SQLite, but not PostgreSQL.
|
1344
513
|
|
1345
|
-
|
1346
|
-
database. For example:
|
514
|
+
*Donal McBreen*
|
1347
515
|
|
1348
|
-
|
1349
|
-
rails db:create
|
1350
|
-
rails db:create:primary
|
1351
|
-
rails db:create:animals
|
1352
|
-
rails db:drop
|
1353
|
-
rails db:drop:primary
|
1354
|
-
rails db:drop:animals
|
1355
|
-
rails db:migrate
|
1356
|
-
rails db:migrate:primary
|
1357
|
-
rails db:migrate:animals
|
1358
|
-
```
|
516
|
+
* Deprecated `ENV["SCHEMA_CACHE"]` in favor of `schema_cache_path` in the database configuration.
|
1359
517
|
|
1360
|
-
|
1361
|
-
`rails db:test:prepare` can additionally operate on a single database. For example:
|
518
|
+
*Rafael Mendonça França*
|
1362
519
|
|
1363
|
-
|
1364
|
-
rails db:schema:dump
|
1365
|
-
rails db:schema:dump:primary
|
1366
|
-
rails db:schema:dump:animals
|
1367
|
-
rails db:schema:load
|
1368
|
-
rails db:schema:load:primary
|
1369
|
-
rails db:schema:load:animals
|
1370
|
-
rails db:structure:dump
|
1371
|
-
rails db:structure:dump:primary
|
1372
|
-
rails db:structure:dump:animals
|
1373
|
-
rails db:structure:load
|
1374
|
-
rails db:structure:load:primary
|
1375
|
-
rails db:structure:load:animals
|
1376
|
-
rails db:test:prepare
|
1377
|
-
rails db:test:prepare:primary
|
1378
|
-
rails db:test:prepare:animals
|
1379
|
-
```
|
520
|
+
* Add `ActiveRecord::Base.with_connection` as a shortcut for leasing a connection for a short duration.
|
1380
521
|
|
1381
|
-
|
522
|
+
The leased connection is yielded, and for the duration of the block, any call to `ActiveRecord::Base.connection`
|
523
|
+
will yield that same connection.
|
1382
524
|
|
1383
|
-
|
525
|
+
This is useful to perform a few database operations without causing a connection to be leased for the
|
526
|
+
entire duration of the request or job.
|
1384
527
|
|
1385
|
-
|
528
|
+
*Jean Boussier*
|
1386
529
|
|
1387
|
-
|
530
|
+
* Deprecate `config.active_record.warn_on_records_fetched_greater_than` now that `sql.active_record`
|
531
|
+
notification includes `:row_count` field.
|
1388
532
|
|
1389
|
-
|
1390
|
-
class Developer < ApplicationRecord
|
1391
|
-
has_many :projects, strict_loading: true
|
1392
|
-
end
|
533
|
+
*Jason Nochlin*
|
1393
534
|
|
1394
|
-
|
1395
|
-
|
1396
|
-
# => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.
|
1397
|
-
```
|
535
|
+
* The fix ensures that the association is joined using the appropriate join type
|
536
|
+
(either inner join or left outer join) based on the existing joins in the scope.
|
1398
537
|
|
1399
|
-
|
538
|
+
This prevents unintentional overrides of existing join types and ensures consistency in the generated SQL queries.
|
1400
539
|
|
1401
|
-
|
540
|
+
Example:
|
1402
541
|
|
1403
|
-
Raise an error if a parent record is marked as `strict_loading` and attempts to lazily load its associations. This is useful for finding places you may want to preload an association and avoid additional queries.
|
1404
542
|
|
1405
|
-
Usage:
|
1406
543
|
|
1407
544
|
```ruby
|
1408
|
-
|
1409
|
-
|
1410
|
-
# => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
|
545
|
+
# `associated` will use `LEFT JOIN` instead of using `JOIN`
|
546
|
+
Post.left_joins(:author).where.associated(:author)
|
1411
547
|
```
|
1412
548
|
|
1413
|
-
*
|
1414
|
-
|
1415
|
-
* Add support for PostgreSQL 11+ partitioned indexes when using `upsert_all`.
|
549
|
+
*Saleh Alhaddad*
|
1416
550
|
|
1417
|
-
|
551
|
+
* Fix an issue where `ActiveRecord::Encryption` configurations are not ready before the loading
|
552
|
+
of Active Record models, when an application is eager loaded. As a result, encrypted attributes
|
553
|
+
could be misconfigured in some cases.
|
1418
554
|
|
1419
|
-
*
|
555
|
+
*Maxime Réty*
|
1420
556
|
|
1421
|
-
|
1422
|
-
|
1423
|
-
Example Usage:
|
557
|
+
* Deprecate defining an `enum` with keyword arguments.
|
1424
558
|
|
1425
559
|
```ruby
|
1426
|
-
class
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
end
|
1431
|
-
```
|
560
|
+
class Function > ApplicationRecord
|
561
|
+
# BAD
|
562
|
+
enum color: [:red, :blue],
|
563
|
+
type: [:instance, :class]
|
1432
564
|
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
remove_column :posts, :title, if_exists: true
|
1437
|
-
end
|
565
|
+
# GOOD
|
566
|
+
enum :color, [:red, :blue]
|
567
|
+
enum :type, [:instance, :class]
|
1438
568
|
end
|
1439
569
|
```
|
1440
570
|
|
1441
|
-
*
|
571
|
+
*Hartley McGuire*
|
1442
572
|
|
1443
|
-
*
|
573
|
+
* Add `config.active_record.validate_migration_timestamps` option for validating migration timestamps.
|
1444
574
|
|
1445
|
-
|
575
|
+
When set, validates that the timestamp prefix for a migration is no more than a day ahead of
|
576
|
+
the timestamp associated with the current time. This is designed to prevent migrations prefixes
|
577
|
+
from being hand-edited to future timestamps, which impacts migration generation and other
|
578
|
+
migration commands.
|
1446
579
|
|
1447
|
-
*
|
580
|
+
*Adrianna Chang*
|
1448
581
|
|
1449
|
-
*
|
582
|
+
* Properly synchronize `Mysql2Adapter#active?` and `TrilogyAdapter#active?`.
|
1450
583
|
|
1451
|
-
|
584
|
+
As well as `disconnect!` and `verify!`.
|
1452
585
|
|
1453
|
-
|
586
|
+
This generally isn't a big problem as connections must not be shared between
|
587
|
+
threads, but is required when running transactional tests or system tests
|
588
|
+
and could lead to a SEGV.
|
1454
589
|
|
1455
|
-
*
|
1456
|
-
|
1457
|
-
* Allow schema cache path to be defined in the database configuration file.
|
590
|
+
*Jean Boussier*
|
1458
591
|
|
1459
|
-
|
592
|
+
* Support `:source_location` tag option for query log tags.
|
1460
593
|
|
1461
|
-
```
|
1462
|
-
|
1463
|
-
adapter: postgresql
|
1464
|
-
database: blog_development
|
1465
|
-
pool: 5
|
1466
|
-
schema_cache_path: tmp/schema/main.yml
|
594
|
+
```ruby
|
595
|
+
config.active_record.query_log_tags << :source_location
|
1467
596
|
```
|
1468
597
|
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
`#remove_connection` is deprecated in order to support returning a `DatabaseConfig` object instead of a `Hash`. Use `#remove_connection_pool`, `#remove_connection` will be removed in Rails 7.0.
|
598
|
+
Calculating the caller location is a costly operation and should be used primarily in development
|
599
|
+
(note, there is also a `config.active_record.verbose_query_logs` that serves the same purpose)
|
600
|
+
or occasionally on production for debugging purposes.
|
1474
601
|
|
1475
|
-
*
|
1476
|
-
|
1477
|
-
* Deprecate `#default_hash` and it's alias `#[]` on database configurations.
|
1478
|
-
|
1479
|
-
Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in Rails 7.0.
|
1480
|
-
|
1481
|
-
*Eileen M. Uchitelle*, *John Crepezzi*
|
1482
|
-
|
1483
|
-
* Add scale support to `ActiveRecord::Validations::NumericalityValidator`.
|
1484
|
-
|
1485
|
-
*Gannon McGibbon*
|
1486
|
-
|
1487
|
-
* Find orphans by looking for missing relations through chaining `where.missing`:
|
1488
|
-
|
1489
|
-
Before:
|
602
|
+
*fatkodima*
|
1490
603
|
|
1491
|
-
|
1492
|
-
Post.left_joins(:author).where(authors: { id: nil })
|
1493
|
-
```
|
604
|
+
* Add an option to `ActiveRecord::Encryption::Encryptor` to disable compression.
|
1494
605
|
|
1495
|
-
|
606
|
+
Allow compression to be disabled by setting `compress: false`
|
1496
607
|
|
1497
608
|
```ruby
|
1498
|
-
|
609
|
+
class User
|
610
|
+
encrypts :name, encryptor: ActiveRecord::Encryption::Encryptor.new(compress: false)
|
611
|
+
end
|
1499
612
|
```
|
1500
613
|
|
1501
|
-
*
|
1502
|
-
|
1503
|
-
* Ensure `:reading` connections always raise if a write is attempted.
|
1504
|
-
|
1505
|
-
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`.
|
1506
|
-
|
1507
|
-
*Eileen M. Uchitelle*
|
614
|
+
*Donal McBreen*
|
1508
615
|
|
1509
|
-
* Deprecate
|
616
|
+
* Deprecate passing strings to `ActiveRecord::Tasks::DatabaseTasks.cache_dump_filename`.
|
1510
617
|
|
1511
|
-
|
618
|
+
A `ActiveRecord::DatabaseConfigurations::DatabaseConfig` object should be passed instead.
|
1512
619
|
|
1513
|
-
*
|
620
|
+
*Rafael Mendonça França*
|
1514
621
|
|
1515
|
-
* Add `
|
1516
|
-
support for casting floats using a database columns' precision value.
|
622
|
+
* Add `row_count` field to `sql.active_record` notification.
|
1517
623
|
|
1518
|
-
|
624
|
+
This field returns the amount of rows returned by the query that emitted the notification.
|
1519
625
|
|
1520
|
-
|
1521
|
-
ActiveRecord::Relation#cache_key_with_version. This method will be used by
|
1522
|
-
ActionController::ConditionalGet to ensure that when collection cache versioning
|
1523
|
-
is enabled, requests using ConditionalGet don't return the same ETag header
|
1524
|
-
after a collection is modified.
|
626
|
+
This metric is useful in cases where one wants to detect queries with big result sets.
|
1525
627
|
|
1526
|
-
|
628
|
+
*Marvin Bitterlich*
|
1527
629
|
|
1528
|
-
|
630
|
+
* Consistently raise an `ArgumentError` when passing an invalid argument to a nested attributes association writer.
|
1529
631
|
|
1530
|
-
|
1531
|
-
with `DATABASE_URL` set.
|
632
|
+
Previously, this would only raise on collection associations and produce a generic error on singular associations.
|
1532
633
|
|
1533
|
-
|
634
|
+
Now, it will raise on both collection and singular associations.
|
1534
635
|
|
1535
|
-
*
|
636
|
+
*Joshua Young*
|
1536
637
|
|
1537
|
-
|
638
|
+
* Fix single quote escapes on default generated MySQL columns.
|
1538
639
|
|
1539
|
-
|
640
|
+
MySQL 5.7.5+ supports generated columns, which can be used to create a column that is computed from an expression.
|
1540
641
|
|
1541
|
-
|
1542
|
-
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
|
1543
|
-
@db_config.configuration_hash.merge!(idle_timeout: "0.02")
|
1544
|
-
```
|
642
|
+
Previously, the schema dump would output a string with double escapes for generated columns with single quotes in the default expression.
|
1545
643
|
|
1546
|
-
|
644
|
+
This would result in issues when importing the schema on a fresh instance of a MySQL database.
|
1547
645
|
|
1548
|
-
|
1549
|
-
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
|
1550
|
-
config = @db_config.configuration_hash.merge(idle_timeout: "0.02")
|
1551
|
-
db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)
|
1552
|
-
```
|
646
|
+
Now, the string will not be escaped and will be valid Ruby upon importing of the schema.
|
1553
647
|
|
1554
|
-
*
|
648
|
+
*Yash Kapadia*
|
1555
649
|
|
1556
|
-
*
|
650
|
+
* Fix Migrations with versions older than 7.1 validating options given to
|
651
|
+
`add_reference` and `t.references`.
|
1557
652
|
|
1558
|
-
*
|
653
|
+
*Hartley McGuire*
|
1559
654
|
|
1560
|
-
*
|
655
|
+
* Add `<role>_types` class method to `ActiveRecord::DelegatedType` so that the delegated types can be introspected.
|
1561
656
|
|
1562
|
-
*
|
657
|
+
*JP Rosevear*
|
1563
658
|
|
1564
|
-
*
|
659
|
+
* Make `schema_dump`, `query_cache`, `replica` and `database_tasks` configurable via `DATABASE_URL`.
|
1565
660
|
|
1566
|
-
|
1567
|
-
by default.
|
661
|
+
This wouldn't always work previously because boolean values would be interpreted as strings.
|
1568
662
|
|
1569
|
-
|
1570
|
-
|
663
|
+
e.g. `DATABASE_URL=postgres://localhost/foo?schema_dump=false` now properly disable dumping the schema
|
664
|
+
cache.
|
1571
665
|
|
1572
|
-
*
|
666
|
+
*Mike Coutermarsh*, *Jean Boussier*
|
1573
667
|
|
1574
|
-
*
|
668
|
+
* Introduce `ActiveRecord::Transactions::ClassMethods#set_callback`.
|
1575
669
|
|
1576
|
-
|
670
|
+
It is identical to `ActiveSupport::Callbacks::ClassMethods#set_callback`
|
671
|
+
but with support for `after_commit` and `after_rollback` callback options.
|
1577
672
|
|
1578
|
-
*
|
673
|
+
*Joshua Young*
|
1579
674
|
|
1580
|
-
|
675
|
+
* Make `ActiveRecord::Encryption::Encryptor` agnostic of the serialization format used for encrypted data.
|
1581
676
|
|
1582
|
-
|
677
|
+
Previously, the encryptor instance only allowed an encrypted value serialized as a `String` to be passed to the message serializer.
|
1583
678
|
|
1584
|
-
|
679
|
+
Now, the encryptor lets the configured `message_serializer` decide which types of serialized encrypted values are supported. A custom serialiser is therefore allowed to serialize `ActiveRecord::Encryption::Message` objects using a type other than `String`.
|
1585
680
|
|
1586
|
-
|
681
|
+
The default `ActiveRecord::Encryption::MessageSerializer` already ensures that only `String` objects are passed for deserialization.
|
1587
682
|
|
1588
|
-
*
|
683
|
+
*Maxime Réty*
|
1589
684
|
|
1590
|
-
|
685
|
+
* Fix `encrypted_attribute?` to take into account context properties passed to `encrypts`.
|
1591
686
|
|
1592
|
-
*
|
687
|
+
*Maxime Réty*
|
1593
688
|
|
1594
|
-
|
689
|
+
* The object returned by `explain` now responds to `pluck`, `first`,
|
690
|
+
`last`, `average`, `count`, `maximum`, `minimum`, and `sum`. Those
|
691
|
+
new methods run `EXPLAIN` on the corresponding queries:
|
1595
692
|
|
1596
|
-
|
693
|
+
```ruby
|
694
|
+
User.all.explain.count
|
695
|
+
# EXPLAIN SELECT COUNT(*) FROM `users`
|
696
|
+
# ...
|
1597
697
|
|
1598
|
-
|
698
|
+
User.all.explain.maximum(:id)
|
699
|
+
# EXPLAIN SELECT MAX(`users`.`id`) FROM `users`
|
700
|
+
# ...
|
701
|
+
```
|
1599
702
|
|
1600
|
-
*
|
703
|
+
*Petrik de Heus*
|
1601
704
|
|
1602
|
-
|
705
|
+
* Fixes an issue where `validates_associated` `:on` option wasn't respected
|
706
|
+
when validating associated records.
|
1603
707
|
|
1604
|
-
*
|
708
|
+
*Austen Madden*, *Alex Ghiculescu*, *Rafał Brize*
|
1605
709
|
|
1606
|
-
|
710
|
+
* Allow overriding SQLite defaults from `database.yml`.
|
1607
711
|
|
1608
|
-
|
712
|
+
Any PRAGMA configuration set under the `pragmas` key in the configuration
|
713
|
+
file takes precedence over Rails' defaults, and additional PRAGMAs can be
|
714
|
+
set as well.
|
1609
715
|
|
1610
|
-
|
716
|
+
```yaml
|
717
|
+
database: storage/development.sqlite3
|
718
|
+
timeout: 5000
|
719
|
+
pragmas:
|
720
|
+
journal_mode: off
|
721
|
+
temp_store: memory
|
722
|
+
```
|
1611
723
|
|
1612
|
-
*
|
724
|
+
*Stephen Margheim*
|
1613
725
|
|
1614
|
-
|
726
|
+
* Remove warning message when running SQLite in production, but leave it unconfigured.
|
1615
727
|
|
1616
|
-
|
1617
|
-
|
728
|
+
There are valid use cases for running SQLite in production. However, it must be done
|
729
|
+
with care, so instead of a warning most users won't see anyway, it's preferable to
|
730
|
+
leave the configuration commented out to force them to think about having the database
|
731
|
+
on a persistent volume etc.
|
1618
732
|
|
1619
|
-
|
733
|
+
*Jacopo Beschi*, *Jean Boussier*
|
1620
734
|
|
1621
|
-
|
1622
|
-
has_secure_token :auth_token
|
1623
|
-
```
|
735
|
+
* Add support for generated columns to the SQLite3 adapter.
|
1624
736
|
|
1625
|
-
|
737
|
+
Generated columns (both stored and dynamic) are supported since version 3.31.0 of SQLite.
|
738
|
+
This adds support for those to the SQLite3 adapter.
|
1626
739
|
|
1627
740
|
```ruby
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
741
|
+
create_table :users do |t|
|
742
|
+
t.string :name
|
743
|
+
t.virtual :name_upper, type: :string, as: 'UPPER(name)'
|
744
|
+
t.virtual :name_lower, type: :string, as: 'LOWER(name)', stored: true
|
745
|
+
end
|
1631
746
|
```
|
1632
747
|
|
1633
|
-
*
|
1634
|
-
|
1635
|
-
* Deprecate `DatabaseConfigurations#to_h`. These connection hashes are still available via `ActiveRecord::Base.configurations.configs_for`.
|
1636
|
-
|
1637
|
-
*Eileen Uchitelle*, *John Crepezzi*
|
1638
|
-
|
1639
|
-
* Add `DatabaseConfig#configuration_hash` to return database configuration hashes with symbol keys, and use all symbol-key configuration hashes internally. Deprecate `DatabaseConfig#config` which returns a String-keyed `Hash` with the same values.
|
1640
|
-
|
1641
|
-
*John Crepezzi*, *Eileen Uchitelle*
|
1642
|
-
|
1643
|
-
* Allow column names to be passed to `remove_index` positionally along with other options.
|
1644
|
-
|
1645
|
-
Passing other options can be necessary to make `remove_index` correctly reversible.
|
1646
|
-
|
1647
|
-
Before:
|
1648
|
-
|
1649
|
-
add_index :reports, :report_id # => works
|
1650
|
-
add_index :reports, :report_id, unique: true # => works
|
1651
|
-
remove_index :reports, :report_id # => works
|
1652
|
-
remove_index :reports, :report_id, unique: true # => ArgumentError
|
1653
|
-
|
1654
|
-
After:
|
1655
|
-
|
1656
|
-
remove_index :reports, :report_id, unique: true # => works
|
748
|
+
*Stephen Margheim*
|
1657
749
|
|
1658
|
-
|
750
|
+
* TrilogyAdapter: ignore `host` if `socket` parameter is set.
|
1659
751
|
|
1660
|
-
|
752
|
+
This allows to configure a connection on a UNIX socket via `DATABASE_URL`:
|
1661
753
|
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
*Eugene Kenny*
|
754
|
+
```
|
755
|
+
DATABASE_URL=trilogy://does-not-matter/my_db_production?socket=/var/run/mysql.sock
|
756
|
+
```
|
1667
757
|
|
1668
|
-
*
|
758
|
+
*Jean Boussier*
|
1669
759
|
|
1670
|
-
|
760
|
+
* Make `assert_queries_count`, `assert_no_queries`, `assert_queries_match`, and
|
761
|
+
`assert_no_queries_match` assertions public.
|
1671
762
|
|
1672
|
-
|
763
|
+
To assert the expected number of queries are made, Rails internally uses `assert_queries_count` and
|
764
|
+
`assert_no_queries`. To assert that specific SQL queries are made, `assert_queries_match` and
|
765
|
+
`assert_no_queries_match` are used. These assertions can now be used in applications as well.
|
1673
766
|
|
1674
|
-
|
767
|
+
```ruby
|
768
|
+
class ArticleTest < ActiveSupport::TestCase
|
769
|
+
test "queries are made" do
|
770
|
+
assert_queries_count(1) { Article.first }
|
771
|
+
end
|
1675
772
|
|
1676
|
-
|
773
|
+
test "creates a foreign key" do
|
774
|
+
assert_queries_match(/ADD FOREIGN KEY/i, include_schema: true) do
|
775
|
+
@connection.add_foreign_key(:comments, :posts)
|
776
|
+
end
|
777
|
+
end
|
778
|
+
end
|
779
|
+
```
|
1677
780
|
|
1678
|
-
*
|
781
|
+
*Petrik de Heus*, *fatkodima*
|
1679
782
|
|
1680
|
-
*
|
783
|
+
* Fix `has_secure_token` calls the setter method on initialize.
|
1681
784
|
|
1682
|
-
*
|
785
|
+
*Abeid Ahmed*
|
1683
786
|
|
1684
|
-
*
|
787
|
+
* When using a `DATABASE_URL`, allow for a configuration to map the protocol in the URL to a specific database
|
788
|
+
adapter. This allows decoupling the adapter the application chooses to use from the database connection details
|
789
|
+
set in the deployment environment.
|
1685
790
|
|
1686
|
-
|
791
|
+
```ruby
|
792
|
+
# ENV['DATABASE_URL'] = "mysql://localhost/example_database"
|
793
|
+
config.active_record.protocol_adapters.mysql = "trilogy"
|
794
|
+
# will connect to MySQL using the trilogy adapter
|
795
|
+
```
|
1687
796
|
|
1688
|
-
*
|
797
|
+
*Jean Boussier*, *Kevin McPhillips*
|
1689
798
|
|
1690
|
-
*
|
799
|
+
* In cases where MySQL returns `warning_count` greater than zero, but returns no warnings when
|
800
|
+
the `SHOW WARNINGS` query is executed, `ActiveRecord.db_warnings_action` proc will still be
|
801
|
+
called with a generic warning message rather than silently ignoring the warning(s).
|
1691
802
|
|
1692
|
-
|
803
|
+
*Kevin McPhillips*
|
1693
804
|
|
1694
|
-
|
805
|
+
* `DatabaseConfigurations#configs_for` accepts a symbol in the `name` parameter.
|
1695
806
|
|
1696
|
-
*
|
807
|
+
*Andrew Novoselac*
|
1697
808
|
|
1698
|
-
|
809
|
+
* Fix `where(field: values)` queries when `field` is a serialized attribute
|
810
|
+
(for example, when `field` uses `ActiveRecord::Base.serialize` or is a JSON
|
811
|
+
column).
|
1699
812
|
|
1700
|
-
*
|
813
|
+
*João Alves*
|
1701
814
|
|
1702
|
-
|
815
|
+
* Make the output of `ActiveRecord::Core#inspect` configurable.
|
1703
816
|
|
1704
|
-
|
817
|
+
By default, calling `inspect` on a record will yield a formatted string including just the `id`.
|
1705
818
|
|
1706
|
-
|
819
|
+
```ruby
|
820
|
+
Post.first.inspect #=> "#<Post id: 1>"
|
821
|
+
```
|
1707
822
|
|
1708
|
-
|
823
|
+
The attributes to be included in the output of `inspect` can be configured with
|
824
|
+
`ActiveRecord::Core#attributes_for_inspect`.
|
1709
825
|
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
826
|
+
```ruby
|
827
|
+
Post.attributes_for_inspect = [:id, :title]
|
828
|
+
Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!">"
|
829
|
+
```
|
1713
830
|
|
1714
|
-
|
831
|
+
With `attributes_for_inspect` set to `:all`, `inspect` will list all the record's attributes.
|
1715
832
|
|
1716
|
-
|
833
|
+
```ruby
|
834
|
+
Post.attributes_for_inspect = :all
|
835
|
+
Post.first.inspect #=> "#<Post id: 1, title: "Hello, World!", published_at: "2023-10-23 14:28:11 +0000">"
|
836
|
+
```
|
1717
837
|
|
1718
|
-
|
838
|
+
In `development` and `test` mode, `attributes_for_inspect` will be set to `:all` by default.
|
1719
839
|
|
1720
|
-
|
840
|
+
You can also call `full_inspect` to get an inspection with all the attributes.
|
1721
841
|
|
1722
|
-
|
842
|
+
The attributes in `attribute_for_inspect` will also be used for `pretty_print`.
|
1723
843
|
|
1724
|
-
*
|
844
|
+
*Andrew Novoselac*
|
1725
845
|
|
1726
|
-
|
846
|
+
* Don't mark attributes as changed when reassigned to `Float::INFINITY` or
|
847
|
+
`-Float::INFINITY`.
|
1727
848
|
|
1728
|
-
*
|
849
|
+
*Maicol Bentancor*
|
1729
850
|
|
1730
|
-
|
851
|
+
* Support the `RETURNING` clause for MariaDB.
|
1731
852
|
|
1732
|
-
*
|
853
|
+
*fatkodima*, *Nikolay Kondratyev*
|
1733
854
|
|
1734
|
-
|
855
|
+
* The SQLite3 adapter now implements the `supports_deferrable_constraints?` contract.
|
1735
856
|
|
1736
|
-
|
857
|
+
Allows foreign keys to be deferred by adding the `:deferrable` key to the `foreign_key` options.
|
1737
858
|
|
1738
|
-
|
859
|
+
```ruby
|
860
|
+
add_reference :person, :alias, foreign_key: { deferrable: :deferred }
|
861
|
+
add_reference :alias, :person, foreign_key: { deferrable: :deferred }
|
862
|
+
```
|
1739
863
|
|
1740
|
-
|
864
|
+
*Stephen Margheim*
|
1741
865
|
|
1742
|
-
|
866
|
+
* Add the `set_constraints` helper to PostgreSQL connections.
|
1743
867
|
|
1744
|
-
|
868
|
+
```ruby
|
869
|
+
Post.create!(user_id: -1) # => ActiveRecord::InvalidForeignKey
|
1745
870
|
|
1746
|
-
|
871
|
+
Post.transaction do
|
872
|
+
Post.connection.set_constraints(:deferred)
|
873
|
+
p = Post.create!(user_id: -1)
|
874
|
+
u = User.create!
|
875
|
+
p.user = u
|
876
|
+
p.save!
|
877
|
+
end
|
878
|
+
```
|
1747
879
|
|
1748
|
-
*
|
880
|
+
*Cody Cutrer*
|
1749
881
|
|
1750
|
-
|
882
|
+
* Include `ActiveModel::API` in `ActiveRecord::Base`.
|
1751
883
|
|
1752
|
-
*
|
884
|
+
*Sean Doyle*
|
1753
885
|
|
1754
|
-
|
886
|
+
* Ensure `#signed_id` outputs `url_safe` strings.
|
1755
887
|
|
1756
|
-
*
|
888
|
+
*Jason Meller*
|
1757
889
|
|
1758
|
-
*
|
890
|
+
* Add `nulls_last` and working `desc.nulls_first` for MySQL.
|
1759
891
|
|
1760
|
-
*
|
892
|
+
*Tristan Fellows*
|
1761
893
|
|
1762
|
-
* Allow
|
894
|
+
* Allow for more complex hash arguments for `order` which mimics `where` in `ActiveRecord::Relation`.
|
1763
895
|
|
1764
|
-
|
896
|
+
```ruby
|
897
|
+
Topic.includes(:posts).order(posts: { created_at: :desc })
|
898
|
+
```
|
1765
899
|
|
900
|
+
*Myles Boone*
|
1766
901
|
|
1767
|
-
Please check [
|
902
|
+
Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/activerecord/CHANGELOG.md) for previous changes.
|