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