activerecord 4.2.0 → 6.1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1221 -796
- data/MIT-LICENSE +4 -2
- data/README.rdoc +15 -14
- data/examples/performance.rb +33 -32
- data/examples/simple.rb +5 -4
- data/lib/active_record/aggregations.rb +267 -249
- data/lib/active_record/association_relation.rb +45 -7
- data/lib/active_record/associations/alias_tracker.rb +40 -43
- data/lib/active_record/associations/association.rb +172 -67
- data/lib/active_record/associations/association_scope.rb +105 -129
- data/lib/active_record/associations/belongs_to_association.rb +85 -59
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +13 -12
- data/lib/active_record/associations/builder/association.rb +57 -43
- data/lib/active_record/associations/builder/belongs_to.rb +74 -57
- data/lib/active_record/associations/builder/collection_association.rb +15 -33
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +57 -70
- data/lib/active_record/associations/builder/has_many.rb +13 -5
- data/lib/active_record/associations/builder/has_one.rb +44 -6
- data/lib/active_record/associations/builder/singular_association.rb +16 -10
- data/lib/active_record/associations/collection_association.rb +168 -279
- data/lib/active_record/associations/collection_proxy.rb +263 -155
- data/lib/active_record/associations/foreign_association.rb +33 -0
- data/lib/active_record/associations/has_many_association.rb +57 -84
- data/lib/active_record/associations/has_many_through_association.rb +70 -82
- data/lib/active_record/associations/has_one_association.rb +74 -47
- data/lib/active_record/associations/has_one_through_association.rb +20 -11
- data/lib/active_record/associations/join_dependency/join_association.rb +54 -73
- data/lib/active_record/associations/join_dependency/join_base.rb +10 -9
- data/lib/active_record/associations/join_dependency/join_part.rb +14 -14
- data/lib/active_record/associations/join_dependency.rb +175 -164
- data/lib/active_record/associations/preloader/association.rb +107 -112
- data/lib/active_record/associations/preloader/through_association.rb +85 -65
- data/lib/active_record/associations/preloader.rb +99 -96
- data/lib/active_record/associations/singular_association.rb +18 -45
- data/lib/active_record/associations/through_association.rb +49 -24
- data/lib/active_record/associations.rb +1845 -1597
- data/lib/active_record/attribute_assignment.rb +59 -185
- data/lib/active_record/attribute_methods/before_type_cast.rb +20 -7
- data/lib/active_record/attribute_methods/dirty.rb +168 -138
- data/lib/active_record/attribute_methods/primary_key.rb +93 -83
- data/lib/active_record/attribute_methods/query.rb +8 -10
- data/lib/active_record/attribute_methods/read.rb +19 -79
- data/lib/active_record/attribute_methods/serialization.rb +49 -24
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +59 -36
- data/lib/active_record/attribute_methods/write.rb +25 -56
- data/lib/active_record/attribute_methods.rb +153 -162
- data/lib/active_record/attributes.rb +234 -70
- data/lib/active_record/autosave_association.rb +157 -69
- data/lib/active_record/base.rb +49 -50
- data/lib/active_record/callbacks.rb +234 -79
- data/lib/active_record/coders/json.rb +3 -1
- data/lib/active_record/coders/yaml_column.rb +46 -13
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +887 -317
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +17 -41
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +301 -113
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +78 -24
- data/lib/active_record/connection_adapters/abstract/quoting.rb +187 -60
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +9 -7
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +157 -93
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +485 -253
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +79 -36
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +909 -263
- data/lib/active_record/connection_adapters/abstract/transaction.rb +254 -92
- data/lib/active_record/connection_adapters/abstract_adapter.rb +492 -221
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +580 -608
- data/lib/active_record/connection_adapters/column.rb +67 -40
- 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 +27 -0
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +196 -0
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +71 -0
- data/lib/active_record/connection_adapters/mysql/quoting.rb +96 -0
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +97 -0
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +103 -0
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +91 -0
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +271 -0
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +40 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +81 -199
- 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 +44 -11
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +78 -161
- data/lib/active_record/connection_adapters/postgresql/explain_pretty_printer.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +49 -57
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +9 -8
- data/lib/active_record/connection_adapters/postgresql/oid/bit_varying.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/bytea.rb +5 -2
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +8 -6
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +13 -1
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +17 -13
- data/lib/active_record/connection_adapters/postgresql/oid/decimal.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +6 -3
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +31 -20
- data/lib/active_record/connection_adapters/postgresql/oid/inet.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
- data/lib/active_record/connection_adapters/postgresql/oid/jsonb.rb +3 -11
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +7 -9
- data/lib/active_record/connection_adapters/postgresql/oid/{infinity.rb → oid.rb} +5 -3
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +32 -11
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +70 -34
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +4 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +67 -51
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +18 -4
- data/lib/active_record/connection_adapters/postgresql/oid/vector.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid/xml.rb +3 -1
- data/lib/active_record/connection_adapters/postgresql/oid.rb +25 -25
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +171 -48
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +27 -14
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +80 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +178 -108
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +49 -0
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +499 -293
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +44 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +11 -8
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +595 -382
- data/lib/active_record/connection_adapters/schema_cache.rb +191 -29
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +45 -0
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +146 -0
- data/lib/active_record/connection_adapters/sqlite3/explain_pretty_printer.rb +21 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +102 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +21 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_definitions.rb +19 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_dumper.rb +18 -0
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +170 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +322 -389
- data/lib/active_record/connection_adapters/statement_pool.rb +33 -13
- data/lib/active_record/connection_adapters.rb +52 -0
- data/lib/active_record/connection_handling.rb +314 -41
- data/lib/active_record/core.rb +488 -243
- data/lib/active_record/counter_cache.rb +71 -50
- data/lib/active_record/database_configurations/connection_url_resolver.rb +99 -0
- data/lib/active_record/database_configurations/database_config.rb +80 -0
- data/lib/active_record/database_configurations/hash_config.rb +96 -0
- data/lib/active_record/database_configurations/url_config.rb +53 -0
- data/lib/active_record/database_configurations.rb +273 -0
- data/lib/active_record/delegated_type.rb +209 -0
- data/lib/active_record/destroy_association_async_job.rb +36 -0
- data/lib/active_record/dynamic_matchers.rb +87 -106
- data/lib/active_record/enum.rb +212 -94
- data/lib/active_record/errors.rb +225 -54
- data/lib/active_record/explain.rb +27 -11
- data/lib/active_record/explain_registry.rb +4 -2
- data/lib/active_record/explain_subscriber.rb +11 -6
- data/lib/active_record/fixture_set/file.rb +33 -14
- 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 +152 -0
- data/lib/active_record/fixture_set/table_rows.rb +46 -0
- data/lib/active_record/fixtures.rb +273 -496
- data/lib/active_record/gem_version.rb +6 -4
- data/lib/active_record/inheritance.rb +175 -110
- data/lib/active_record/insert_all.rb +212 -0
- data/lib/active_record/integration.rb +121 -29
- data/lib/active_record/internal_metadata.rb +64 -0
- data/lib/active_record/legacy_yaml_adapter.rb +52 -0
- data/lib/active_record/locale/en.yml +3 -2
- data/lib/active_record/locking/optimistic.rb +103 -95
- data/lib/active_record/locking/pessimistic.rb +22 -6
- data/lib/active_record/log_subscriber.rb +93 -31
- data/lib/active_record/middleware/database_selector/resolver/session.rb +48 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
- data/lib/active_record/middleware/database_selector.rb +77 -0
- data/lib/active_record/migration/command_recorder.rb +185 -90
- data/lib/active_record/migration/compatibility.rb +298 -0
- data/lib/active_record/migration/join_table.rb +8 -7
- data/lib/active_record/migration.rb +685 -309
- data/lib/active_record/model_schema.rb +420 -113
- data/lib/active_record/nested_attributes.rb +265 -216
- data/lib/active_record/no_touching.rb +15 -2
- data/lib/active_record/null_relation.rb +24 -38
- data/lib/active_record/persistence.rb +574 -135
- data/lib/active_record/query_cache.rb +29 -23
- data/lib/active_record/querying.rb +50 -31
- data/lib/active_record/railtie.rb +175 -54
- data/lib/active_record/railties/console_sandbox.rb +3 -3
- data/lib/active_record/railties/controller_runtime.rb +34 -33
- data/lib/active_record/railties/databases.rake +533 -216
- data/lib/active_record/readonly_attributes.rb +9 -4
- data/lib/active_record/reflection.rb +485 -310
- data/lib/active_record/relation/batches/batch_enumerator.rb +85 -0
- data/lib/active_record/relation/batches.rb +217 -59
- data/lib/active_record/relation/calculations.rb +326 -244
- data/lib/active_record/relation/delegation.rb +76 -84
- data/lib/active_record/relation/finder_methods.rb +318 -256
- data/lib/active_record/relation/from_clause.rb +30 -0
- data/lib/active_record/relation/merger.rb +99 -84
- data/lib/active_record/relation/predicate_builder/array_handler.rb +26 -25
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +42 -0
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +19 -0
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +57 -0
- data/lib/active_record/relation/predicate_builder/range_handler.rb +22 -0
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +7 -1
- data/lib/active_record/relation/predicate_builder.rb +139 -96
- data/lib/active_record/relation/query_attribute.rb +50 -0
- data/lib/active_record/relation/query_methods.rb +757 -409
- data/lib/active_record/relation/record_fetch_warning.rb +51 -0
- data/lib/active_record/relation/spawn_methods.rb +23 -21
- data/lib/active_record/relation/where_clause.rb +239 -0
- data/lib/active_record/relation.rb +554 -342
- data/lib/active_record/result.rb +91 -47
- data/lib/active_record/runtime_registry.rb +6 -4
- data/lib/active_record/sanitization.rb +134 -122
- data/lib/active_record/schema.rb +21 -24
- data/lib/active_record/schema_dumper.rb +141 -92
- data/lib/active_record/schema_migration.rb +24 -26
- data/lib/active_record/scoping/default.rb +96 -82
- data/lib/active_record/scoping/named.rb +78 -36
- data/lib/active_record/scoping.rb +45 -27
- data/lib/active_record/secure_token.rb +48 -0
- data/lib/active_record/serialization.rb +8 -6
- data/lib/active_record/signed_id.rb +116 -0
- data/lib/active_record/statement_cache.rb +89 -36
- data/lib/active_record/store.rb +133 -43
- data/lib/active_record/suppressor.rb +61 -0
- data/lib/active_record/table_metadata.rb +81 -0
- data/lib/active_record/tasks/database_tasks.rb +366 -129
- data/lib/active_record/tasks/mysql_database_tasks.rb +68 -100
- data/lib/active_record/tasks/postgresql_database_tasks.rb +87 -39
- data/lib/active_record/tasks/sqlite_database_tasks.rb +44 -19
- data/lib/active_record/test_databases.rb +24 -0
- data/lib/active_record/test_fixtures.rb +291 -0
- data/lib/active_record/timestamp.rb +86 -43
- data/lib/active_record/touch_later.rb +65 -0
- data/lib/active_record/transactions.rb +181 -152
- data/lib/active_record/translation.rb +3 -1
- data/lib/active_record/type/adapter_specific_registry.rb +126 -0
- data/lib/active_record/type/date.rb +4 -41
- data/lib/active_record/type/date_time.rb +4 -38
- data/lib/active_record/type/decimal_without_scale.rb +6 -2
- data/lib/active_record/type/hash_lookup_type_map.rb +12 -5
- data/lib/active_record/type/internal/timezone.rb +17 -0
- data/lib/active_record/type/json.rb +30 -0
- data/lib/active_record/type/serialized.rb +33 -15
- data/lib/active_record/type/text.rb +2 -2
- data/lib/active_record/type/time.rb +21 -16
- data/lib/active_record/type/type_map.rb +16 -19
- data/lib/active_record/type/unsigned_integer.rb +9 -8
- data/lib/active_record/type.rb +84 -23
- data/lib/active_record/type_caster/connection.rb +33 -0
- data/lib/active_record/type_caster/map.rb +23 -0
- data/lib/active_record/type_caster.rb +9 -0
- data/lib/active_record/validations/absence.rb +25 -0
- data/lib/active_record/validations/associated.rb +12 -4
- data/lib/active_record/validations/length.rb +26 -0
- data/lib/active_record/validations/numericality.rb +35 -0
- data/lib/active_record/validations/presence.rb +14 -13
- data/lib/active_record/validations/uniqueness.rb +65 -48
- data/lib/active_record/validations.rb +39 -35
- data/lib/active_record/version.rb +3 -1
- data/lib/active_record.rb +44 -28
- data/lib/arel/alias_predication.rb +9 -0
- data/lib/arel/attributes/attribute.rb +41 -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 +42 -0
- data/lib/arel/delete_manager.rb +18 -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/insert_manager.rb +49 -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 +45 -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/full_outer_join.rb +8 -0
- data/lib/arel/nodes/function.rb +44 -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 +41 -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 +70 -0
- data/lib/arel/order_predications.rb +13 -0
- data/lib/arel/predications.rb +250 -0
- data/lib/arel/select_manager.rb +270 -0
- data/lib/arel/table.rb +118 -0
- data/lib/arel/tree_manager.rb +72 -0
- data/lib/arel/update_manager.rb +34 -0
- data/lib/arel/visitors/dot.rb +308 -0
- data/lib/arel/visitors/mysql.rb +93 -0
- data/lib/arel/visitors/postgresql.rb +120 -0
- data/lib/arel/visitors/sqlite.rb +38 -0
- data/lib/arel/visitors/to_sql.rb +899 -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 +54 -0
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +26 -0
- data/lib/rails/generators/active_record/application_record/templates/application_record.rb.tt +5 -0
- data/lib/rails/generators/active_record/migration/migration_generator.rb +43 -37
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +26 -0
- data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +13 -10
- data/lib/rails/generators/active_record/migration.rb +35 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +55 -22
- 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 +22 -0
- data/lib/rails/generators/active_record.rb +7 -5
- metadata +175 -65
- data/lib/active_record/associations/preloader/belongs_to.rb +0 -17
- data/lib/active_record/associations/preloader/collection_association.rb +0 -24
- data/lib/active_record/associations/preloader/has_many.rb +0 -17
- data/lib/active_record/associations/preloader/has_many_through.rb +0 -19
- data/lib/active_record/associations/preloader/has_one.rb +0 -23
- data/lib/active_record/associations/preloader/has_one_through.rb +0 -9
- data/lib/active_record/associations/preloader/singular_association.rb +0 -21
- data/lib/active_record/attribute.rb +0 -149
- data/lib/active_record/attribute_decorators.rb +0 -66
- data/lib/active_record/attribute_set/builder.rb +0 -86
- data/lib/active_record/attribute_set.rb +0 -77
- data/lib/active_record/connection_adapters/connection_specification.rb +0 -275
- data/lib/active_record/connection_adapters/mysql_adapter.rb +0 -491
- data/lib/active_record/connection_adapters/postgresql/array_parser.rb +0 -93
- data/lib/active_record/connection_adapters/postgresql/oid/float.rb +0 -21
- data/lib/active_record/connection_adapters/postgresql/oid/integer.rb +0 -11
- data/lib/active_record/connection_adapters/postgresql/oid/json.rb +0 -35
- data/lib/active_record/connection_adapters/postgresql/oid/time.rb +0 -11
- data/lib/active_record/railties/jdbcmysql_error.rb +0 -16
- data/lib/active_record/serializers/xml_serializer.rb +0 -193
- data/lib/active_record/type/big_integer.rb +0 -13
- data/lib/active_record/type/binary.rb +0 -50
- data/lib/active_record/type/boolean.rb +0 -30
- data/lib/active_record/type/decimal.rb +0 -40
- data/lib/active_record/type/decorator.rb +0 -14
- data/lib/active_record/type/float.rb +0 -19
- data/lib/active_record/type/integer.rb +0 -55
- data/lib/active_record/type/mutable.rb +0 -16
- data/lib/active_record/type/numeric.rb +0 -36
- data/lib/active_record/type/string.rb +0 -36
- data/lib/active_record/type/time_value.rb +0 -38
- data/lib/active_record/type/value.rb +0 -101
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb +0 -22
- data/lib/rails/generators/active_record/model/templates/model.rb +0 -10
- /data/lib/rails/generators/active_record/model/templates/{module.rb → module.rb.tt} +0 -0
data/CHANGELOG.md
CHANGED
@@ -1,1372 +1,1797 @@
|
|
1
|
-
|
2
|
-
will recreate tables even if they have dependent objects (like foreign keys).
|
3
|
-
`db/schema.rb` now uses `force: :cascade`. This makes it possible to
|
4
|
-
reload the schema when foreign keys are in place.
|
1
|
+
## Rails 6.1.7.1 (January 17, 2023) ##
|
5
2
|
|
6
|
-
|
3
|
+
* Make sanitize_as_sql_comment more strict
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
Though this method was likely never meant to take user input, it was
|
6
|
+
attempting sanitization. That sanitization could be bypassed with
|
7
|
+
carefully crafted input.
|
11
8
|
|
12
|
-
|
9
|
+
This commit makes the sanitization more robust by replacing any
|
10
|
+
occurrances of "/*" or "*/" with "/ *" or "* /". It also performs a
|
11
|
+
first pass to remove one surrounding comment to avoid compatibility
|
12
|
+
issues for users relying on the existing removal.
|
13
13
|
|
14
|
-
|
14
|
+
This also clarifies in the documentation of annotate that it should not
|
15
|
+
be provided user input.
|
15
16
|
|
16
|
-
|
17
|
+
[CVE-2023-22794]
|
17
18
|
|
18
|
-
|
19
|
+
* Added integer width check to PostgreSQL::Quoting
|
19
20
|
|
20
|
-
|
21
|
+
Given a value outside the range for a 64bit signed integer type
|
22
|
+
PostgreSQL will treat the column type as numeric. Comparing
|
23
|
+
integer values against numeric values can result in a slow
|
24
|
+
sequential scan.
|
21
25
|
|
22
|
-
This
|
26
|
+
This behavior is configurable via
|
27
|
+
ActiveRecord::Base.raise_int_wider_than_64bit which defaults to true.
|
23
28
|
|
24
|
-
|
29
|
+
[CVE-2022-44566]
|
25
30
|
|
26
|
-
|
27
|
-
options.
|
31
|
+
## Rails 6.1.7 (September 09, 2022) ##
|
28
32
|
|
29
|
-
|
33
|
+
* Symbol is allowed by default for YAML columns
|
30
34
|
|
31
|
-
|
35
|
+
*Étienne Barrié*
|
32
36
|
|
33
|
-
|
34
|
-
when a migration is rolled-back, edited and reapplied.
|
37
|
+
* Fix `ActiveRecord::Store` to serialize as a regular Hash
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
provide custom behavior after the schema has been loaded.
|
39
|
+
Previously it would serialize as an `ActiveSupport::HashWithIndifferentAccess`
|
40
|
+
which is wasteful and cause problem with YAML safe_load.
|
39
41
|
|
40
|
-
|
42
|
+
*Jean Boussier*
|
41
43
|
|
42
|
-
|
44
|
+
* Fix PG.connect keyword arguments deprecation warning on ruby 2.7
|
43
45
|
|
44
|
-
|
46
|
+
Fixes #44307.
|
45
47
|
|
46
|
-
*
|
48
|
+
*Nikita Vasilevsky*
|
47
49
|
|
48
|
-
|
50
|
+
## Rails 6.1.6.1 (July 12, 2022) ##
|
49
51
|
|
50
|
-
|
52
|
+
* Change ActiveRecord::Coders::YAMLColumn default to safe_load
|
51
53
|
|
52
|
-
|
54
|
+
This adds two new configuration options The configuration options are as
|
55
|
+
follows:
|
56
|
+
|
57
|
+
* `config.active_storage.use_yaml_unsafe_load`
|
58
|
+
|
59
|
+
When set to true, this configuration option tells Rails to use the old
|
60
|
+
"unsafe" YAML loading strategy, maintaining the existing behavior but leaving
|
61
|
+
the possible escalation vulnerability in place. Setting this option to true
|
62
|
+
is *not* recommended, but can aid in upgrading.
|
63
|
+
|
64
|
+
* `config.active_record.yaml_column_permitted_classes`
|
65
|
+
|
66
|
+
The "safe YAML" loading method does not allow all classes to be deserialized
|
67
|
+
by default. This option allows you to specify classes deemed "safe" in your
|
68
|
+
application. For example, if your application uses Symbol and Time in
|
69
|
+
serialized data, you can add Symbol and Time to the allowed list as follows:
|
70
|
+
|
71
|
+
```
|
72
|
+
config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
|
73
|
+
```
|
53
74
|
|
54
|
-
|
75
|
+
[CVE-2022-32224]
|
55
76
|
|
56
|
-
*Sean Griffin*
|
57
77
|
|
58
|
-
|
78
|
+
## Rails 6.1.6 (May 09, 2022) ##
|
59
79
|
|
60
|
-
|
80
|
+
* No changes.
|
61
81
|
|
62
|
-
* Fix preloading of associations with a scope containing joins along with
|
63
|
-
conditions on the joined association.
|
64
82
|
|
65
|
-
|
83
|
+
## Rails 6.1.5.1 (April 26, 2022) ##
|
66
84
|
|
67
|
-
*
|
85
|
+
* No changes.
|
68
86
|
|
69
|
-
*Cody Cutrer*
|
70
87
|
|
71
|
-
|
72
|
-
the owner has been saved so that the proxy is not cached without the
|
73
|
-
owner's id.
|
88
|
+
## Rails 6.1.5 (March 09, 2022) ##
|
74
89
|
|
75
|
-
|
90
|
+
* Fix `ActiveRecord::ConnectionAdapters::SchemaCache#deep_deduplicate` for Ruby 2.6.
|
76
91
|
|
77
|
-
|
92
|
+
Ruby 2.6 and 2.7 have slightly different implementations of the `String#-@` method.
|
93
|
+
In Ruby 2.6, the receiver of the `String#-@` method is modified under certain circumstances.
|
94
|
+
This was later identified as a bug (https://bugs.ruby-lang.org/issues/15926) and only
|
95
|
+
fixed in Ruby 2.7.
|
78
96
|
|
79
|
-
|
97
|
+
Before the changes in this commit, the
|
98
|
+
`ActiveRecord::ConnectionAdapters::SchemaCache#deep_deduplicate` method, which internally
|
99
|
+
calls the `String#-@` method, could also modify an input string argument in Ruby 2.6 --
|
100
|
+
changing a tainted, unfrozen string into a tainted, frozen string.
|
80
101
|
|
81
|
-
|
102
|
+
Fixes #43056
|
82
103
|
|
83
|
-
|
104
|
+
*Eric O'Hanlon*
|
84
105
|
|
85
|
-
|
106
|
+
* Fix migration compatibility to create SQLite references/belongs_to column as integer when
|
107
|
+
migration version is 6.0.
|
86
108
|
|
87
|
-
|
109
|
+
`reference`/`belongs_to` in migrations with version 6.0 were creating columns as
|
110
|
+
bigint instead of integer for the SQLite Adapter.
|
88
111
|
|
89
|
-
*
|
112
|
+
*Marcelo Lauxen*
|
90
113
|
|
91
|
-
*
|
92
|
-
`Relation` for performing queries and updates is the prefered API.
|
114
|
+
* Fix dbconsole for 3-tier config.
|
93
115
|
|
94
|
-
*
|
116
|
+
*Eileen M. Uchitelle*
|
95
117
|
|
96
|
-
*
|
97
|
-
even when using type decorators such as `serialize`.
|
118
|
+
* Better handle SQL queries with invalid encoding.
|
98
119
|
|
99
|
-
|
120
|
+
```ruby
|
121
|
+
Post.create(name: "broken \xC8 UTF-8")
|
122
|
+
```
|
100
123
|
|
101
|
-
|
102
|
-
|
124
|
+
Would cause all adapters to fail in a non controlled way in the code
|
125
|
+
responsible to detect write queries.
|
103
126
|
|
104
|
-
|
127
|
+
The query is now properly passed to the database connection, which might or might
|
128
|
+
not be able to handle it, but will either succeed or failed in a more correct way.
|
105
129
|
|
106
|
-
*
|
130
|
+
*Jean Boussier*
|
107
131
|
|
108
|
-
*
|
132
|
+
* Ignore persisted in-memory records when merging target lists.
|
109
133
|
|
110
|
-
*
|
134
|
+
*Kevin Sjöberg*
|
111
135
|
|
112
|
-
*
|
136
|
+
* Fix regression bug that caused ignoring additional conditions for preloading
|
137
|
+
`has_many` through relations.
|
113
138
|
|
114
|
-
|
139
|
+
Fixes #43132
|
115
140
|
|
116
|
-
*
|
141
|
+
*Alexander Pauly*
|
117
142
|
|
118
|
-
|
143
|
+
* Fix `ActiveRecord::InternalMetadata` to not be broken by
|
144
|
+
`config.active_record.record_timestamps = false`
|
119
145
|
|
120
|
-
|
146
|
+
Since the model always create the timestamp columns, it has to set them, otherwise it breaks
|
147
|
+
various DB management tasks.
|
121
148
|
|
122
|
-
|
123
|
-
# => ActiveRecord::UnknownAttributeError: unknown attribute 'name' for User.
|
149
|
+
Fixes #42983
|
124
150
|
|
125
|
-
*
|
151
|
+
*Jean Boussier*
|
126
152
|
|
127
|
-
* Fix
|
128
|
-
records are autosaved.
|
153
|
+
* Fix duplicate active record objects on `inverse_of`.
|
129
154
|
|
130
|
-
|
155
|
+
*Justin Carvalho*
|
131
156
|
|
132
|
-
|
157
|
+
* Fix duplicate objects stored in has many association after save.
|
133
158
|
|
134
|
-
|
135
|
-
management middleware.
|
159
|
+
Fixes #42549.
|
136
160
|
|
137
|
-
*
|
161
|
+
*Alex Ghiculescu*
|
138
162
|
|
139
|
-
*
|
163
|
+
* Fix performance regression in `CollectionAssocation#build`.
|
140
164
|
|
141
|
-
*
|
165
|
+
*Alex Ghiculescu*
|
166
|
+
|
167
|
+
* Fix retrieving default value for text column for MariaDB.
|
168
|
+
|
169
|
+
*fatkodima*
|
142
170
|
|
143
|
-
* Don't autosave unchanged has_one through records.
|
144
171
|
|
145
|
-
|
172
|
+
## Rails 6.1.4.7 (March 08, 2022) ##
|
146
173
|
|
147
|
-
*
|
174
|
+
* No changes.
|
148
175
|
|
149
|
-
*Yves Senn*
|
150
176
|
|
151
|
-
|
152
|
-
outside the schema search path.
|
177
|
+
## Rails 6.1.4.6 (February 11, 2022) ##
|
153
178
|
|
154
|
-
|
179
|
+
* No changes.
|
155
180
|
|
156
|
-
*Matthew Draper*, *Yves Senn*
|
157
181
|
|
158
|
-
|
159
|
-
committing it during the stack unwind. Previously, we could commit half-
|
160
|
-
completed work. This fix only works for Ruby 2.0+; on 1.9, we can't
|
161
|
-
distinguish a thread kill from an ordinary non-local (block) return, so must
|
162
|
-
default to committing.
|
182
|
+
## Rails 6.1.4.5 (February 11, 2022) ##
|
163
183
|
|
164
|
-
|
184
|
+
* No changes.
|
165
185
|
|
166
|
-
* A `NullRelation` should represent nothing. This fixes a bug where
|
167
|
-
`Comment.where(post_id: Post.none)` returned a non-empty result.
|
168
186
|
|
169
|
-
|
187
|
+
## Rails 6.1.4.4 (December 15, 2021) ##
|
170
188
|
|
171
|
-
|
189
|
+
* No changes.
|
172
190
|
|
173
|
-
* Include default column limits in schema.rb. Allows defaults to be changed
|
174
|
-
in the future without affecting old migrations that assumed old defaults.
|
175
191
|
|
176
|
-
|
192
|
+
## Rails 6.1.4.3 (December 14, 2021) ##
|
177
193
|
|
178
|
-
*
|
194
|
+
* No changes.
|
179
195
|
|
180
|
-
*Jeremy Kemper*
|
181
196
|
|
182
|
-
|
197
|
+
## Rails 6.1.4.2 (December 14, 2021) ##
|
183
198
|
|
184
|
-
|
199
|
+
* No changes.
|
185
200
|
|
186
|
-
* SQLite3Adapter now checks for views in `table_exists?`. Fixes #14041.
|
187
201
|
|
188
|
-
|
202
|
+
## Rails 6.1.4.1 (August 19, 2021) ##
|
189
203
|
|
190
|
-
*
|
191
|
-
has support for SQL views. Connection adapters should define this method.
|
204
|
+
* No changes.
|
192
205
|
|
193
|
-
*Yves Senn*
|
194
206
|
|
195
|
-
|
207
|
+
## Rails 6.1.4 (June 24, 2021) ##
|
196
208
|
|
197
|
-
|
209
|
+
* Do not try to rollback transactions that failed due to a `ActiveRecord::TransactionRollbackError`.
|
198
210
|
|
199
|
-
*
|
211
|
+
*Jamie McCarthy*
|
200
212
|
|
201
|
-
*
|
202
|
-
the database connection to the current environment.
|
213
|
+
* Raise an error if `pool_config` is `nil` in `set_pool_config`.
|
203
214
|
|
204
|
-
|
215
|
+
*Eileen M. Uchitelle*
|
205
216
|
|
206
|
-
|
217
|
+
* Fix compatibility with `psych >= 4`.
|
207
218
|
|
208
|
-
|
219
|
+
Starting in Psych 4.0.0 `YAML.load` behaves like `YAML.safe_load`. To preserve compatibility
|
220
|
+
Active Record's schema cache loader and `YAMLColumn` now uses `YAML.unsafe_load` if available.
|
209
221
|
|
210
|
-
|
211
|
-
database.yml. Otherwise, `SET NAMES utf8mb4` will use the default
|
212
|
-
collation for that charset (utf8mb4_general_ci) when you may have chosen
|
213
|
-
a different collation, like utf8mb4_unicode_ci.
|
222
|
+
*Jean Boussier*
|
214
223
|
|
215
|
-
|
216
|
-
is unlikely to affect you.
|
224
|
+
* Support using replicas when using `rails dbconsole`.
|
217
225
|
|
218
|
-
*
|
226
|
+
*Christopher Thornton*
|
219
227
|
|
220
|
-
*
|
228
|
+
* Restore connection pools after transactional tests.
|
221
229
|
|
222
|
-
*
|
230
|
+
*Eugene Kenny*
|
223
231
|
|
224
|
-
*
|
225
|
-
PostgreSQL.
|
232
|
+
* Change `upsert_all` to fails cleanly for MySQL when `:unique_by` is used.
|
226
233
|
|
227
|
-
*
|
234
|
+
*Bastian Bartmann*
|
228
235
|
|
229
|
-
|
236
|
+
* Fix user-defined `self.default_scope` to respect table alias.
|
230
237
|
|
231
|
-
*
|
232
|
-
passed as a lambda with an arity of one.
|
238
|
+
*Ryuta Kamizono*
|
233
239
|
|
234
|
-
|
240
|
+
* Clear `@cache_keys` cache after `update_all`, `delete_all`, `destroy_all`.
|
235
241
|
|
236
|
-
*
|
242
|
+
*Ryuta Kamizono*
|
237
243
|
|
238
|
-
*
|
244
|
+
* Changed Arel predications `contains` and `overlaps` to use
|
245
|
+
`quoted_node` so that PostgreSQL arrays are quoted properly.
|
239
246
|
|
240
|
-
|
247
|
+
*Bradley Priest*
|
241
248
|
|
242
|
-
|
249
|
+
* Fix `merge` when the `where` clauses have string contents.
|
243
250
|
|
244
|
-
*
|
245
|
-
`after_rollback`/`after_create` callbacks and prints them to the logs.
|
246
|
-
Future versions of Rails will not rescue these errors anymore and
|
247
|
-
just bubble them up like the other callbacks.
|
251
|
+
*Ryuta Kamizono*
|
248
252
|
|
249
|
-
|
253
|
+
* Fix rollback of parent destruction with nested `dependent: :destroy`.
|
250
254
|
|
251
|
-
|
255
|
+
*Jacopo Beschi*
|
252
256
|
|
253
|
-
|
254
|
-
config.active_record.raise_in_transactional_callbacks = true
|
257
|
+
* Fix binds logging for `"WHERE ... IN ..."` statements.
|
255
258
|
|
256
|
-
|
259
|
+
*Ricardo Díaz*
|
257
260
|
|
258
|
-
|
261
|
+
* Handle `false` in relation strict loading checks.
|
259
262
|
|
260
|
-
|
261
|
-
`
|
262
|
-
|
263
|
+
Previously when a model had strict loading set to true and then had a
|
264
|
+
relation set `strict_loading` to false the false wasn't considered when
|
265
|
+
deciding whether to raise/warn about strict loading.
|
263
266
|
|
264
|
-
|
267
|
+
```
|
268
|
+
class Dog < ActiveRecord::Base
|
269
|
+
self.strict_loading_by_default = true
|
265
270
|
|
266
|
-
|
271
|
+
has_many :treats, strict_loading: false
|
272
|
+
end
|
273
|
+
```
|
267
274
|
|
268
|
-
|
269
|
-
|
275
|
+
In the example, `dog.treats` would still raise even though
|
276
|
+
`strict_loading` was set to false. This is a bug affecting more than
|
277
|
+
Active Storage which is why I made this PR superseding #41461. We need
|
278
|
+
to fix this for all applications since the behavior is a little
|
279
|
+
surprising. I took the test from #41461 and the code suggestion from #41453
|
280
|
+
with some additions.
|
270
281
|
|
271
|
-
*
|
282
|
+
*Eileen M. Uchitelle*, *Radamés Roriz*
|
272
283
|
|
273
|
-
* Fix
|
284
|
+
* Fix numericality validator without precision.
|
274
285
|
|
275
|
-
|
286
|
+
*Ryuta Kamizono*
|
276
287
|
|
277
|
-
|
288
|
+
* Fix aggregate attribute on Enum types.
|
278
289
|
|
279
|
-
*
|
290
|
+
*Ryuta Kamizono*
|
280
291
|
|
281
|
-
|
292
|
+
* Fix `CREATE INDEX` statement generation for PostgreSQL.
|
282
293
|
|
283
|
-
*
|
294
|
+
*eltongo*
|
284
295
|
|
285
|
-
*
|
296
|
+
* Fix where clause on enum attribute when providing array of strings.
|
286
297
|
|
287
|
-
|
298
|
+
*Ryuta Kamizono*
|
288
299
|
|
289
|
-
|
300
|
+
* Fix `unprepared_statement` to work it when nesting.
|
290
301
|
|
291
|
-
|
292
|
-
index_exists? :articles, :title, name: "idx_title" # => `true`
|
293
|
-
index_exists? :articles, :body, name: "idx_title" # => `true`
|
302
|
+
*Ryuta Kamizono*
|
294
303
|
|
295
|
-
# After:
|
296
|
-
index_exists? :articles, :title, name: "idx_title" # => `true`
|
297
|
-
index_exists? :articles, :body, name: "idx_title" # => `false`
|
298
304
|
|
299
|
-
|
305
|
+
## Rails 6.1.3.2 (May 05, 2021) ##
|
300
306
|
|
301
|
-
*
|
302
|
-
Not passing the option is deprecated but the default is still `null: true`.
|
303
|
-
With Rails 5 this will change to `null: false`.
|
307
|
+
* No changes.
|
304
308
|
|
305
|
-
*Sean Griffin*
|
306
309
|
|
307
|
-
|
308
|
-
message now reflects whether that object is a new record or has been
|
309
|
-
destroyed.
|
310
|
+
## Rails 6.1.3.1 (March 26, 2021) ##
|
310
311
|
|
311
|
-
|
312
|
+
* No changes.
|
312
313
|
|
313
|
-
* Define `id_was` to get the previous value of the primary key.
|
314
314
|
|
315
|
-
|
316
|
-
Active Record will return the current value of the primary key. This
|
317
|
-
makes it impossible to correctly do an update operation if you change the
|
318
|
-
id.
|
315
|
+
## Rails 6.1.3 (February 17, 2021) ##
|
319
316
|
|
320
|
-
|
317
|
+
* Fix the MySQL adapter to always set the right collation and charset
|
318
|
+
to the connection session.
|
321
319
|
|
322
320
|
*Rafael Mendonça França*
|
323
321
|
|
324
|
-
*
|
325
|
-
|
326
|
-
require the `configuration` to act on as an argument.
|
322
|
+
* Fix MySQL adapter handling of time objects when prepared statements
|
323
|
+
are enabled.
|
327
324
|
|
328
|
-
*
|
325
|
+
*Rafael Mendonça França*
|
329
326
|
|
330
|
-
* Fix
|
331
|
-
|
327
|
+
* Fix scoping in enum fields using conditions that would generate
|
328
|
+
an `IN` clause.
|
332
329
|
|
333
|
-
|
330
|
+
*Ryuta Kamizono*
|
334
331
|
|
335
|
-
|
332
|
+
* Skip optimised #exist? query when #include? is called on a relation
|
333
|
+
with a having clause
|
336
334
|
|
337
|
-
|
335
|
+
Relations that have aliased select values AND a having clause that
|
336
|
+
references an aliased select value would generate an error when
|
337
|
+
#include? was called, due to an optimisation that would generate
|
338
|
+
call #exists? on the relation instead, which effectively alters
|
339
|
+
the select values of the query (and thus removes the aliased select
|
340
|
+
values), but leaves the having clause intact. Because the having
|
341
|
+
clause is then referencing an aliased column that is no longer
|
342
|
+
present in the simplified query, an ActiveRecord::InvalidStatement
|
343
|
+
error was raised.
|
338
344
|
|
339
|
-
|
345
|
+
An sample query affected by this problem:
|
340
346
|
|
341
|
-
|
347
|
+
```ruby
|
348
|
+
Author.select('COUNT(*) as total_posts', 'authors.*')
|
349
|
+
.joins(:posts)
|
350
|
+
.group(:id)
|
351
|
+
.having('total_posts > 2')
|
352
|
+
.include?(Author.first)
|
353
|
+
```
|
342
354
|
|
343
|
-
|
344
|
-
|
345
|
-
|
355
|
+
This change adds an addition check to the condition that skips the
|
356
|
+
simplified #exists? query, which simply checks for the presence of
|
357
|
+
a having clause.
|
346
358
|
|
347
|
-
|
359
|
+
Fixes #41417
|
348
360
|
|
349
|
-
*
|
361
|
+
*Michael Smart*
|
350
362
|
|
351
|
-
|
363
|
+
* Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
|
364
|
+
without Rails knowledge (e.g., if app gets kill -9d during long-running query or due to Rack::Timeout), app won't end
|
365
|
+
up in perpetual crash state for being inconsistent with Postgres.
|
352
366
|
|
353
|
-
*
|
367
|
+
*wbharding*, *Martin Tepper*
|
354
368
|
|
355
|
-
* Add support for PostgreSQL JSONB.
|
356
369
|
|
357
|
-
|
370
|
+
## Rails 6.1.2.1 (February 10, 2021) ##
|
358
371
|
|
359
|
-
|
360
|
-
t.jsonb :meta_data
|
361
|
-
end
|
372
|
+
* Fix possible DoS vector in PostgreSQL money type
|
362
373
|
|
363
|
-
|
374
|
+
Carefully crafted input can cause a DoS via the regular expressions used
|
375
|
+
for validating the money format in the PostgreSQL adapter. This patch
|
376
|
+
fixes the regexp.
|
364
377
|
|
365
|
-
|
378
|
+
Thanks to @dee-see from Hackerone for this patch!
|
366
379
|
|
367
|
-
|
380
|
+
[CVE-2021-22880]
|
368
381
|
|
369
|
-
*
|
370
|
-
`DROP DEFAULT` instead of a `DEFAULT NULL` query.
|
382
|
+
*Aaron Patterson*
|
371
383
|
|
372
|
-
Fixes #16261.
|
373
384
|
|
374
|
-
|
385
|
+
## Rails 6.1.2 (February 09, 2021) ##
|
375
386
|
|
376
|
-
*
|
377
|
-
and `add_reference`.
|
387
|
+
* Fix timestamp type for sqlite3.
|
378
388
|
|
379
|
-
|
389
|
+
*Eileen M. Uchitelle*
|
380
390
|
|
381
|
-
|
382
|
-
t.references :station, type: :uuid
|
383
|
-
end
|
391
|
+
* Make destroy async transactional.
|
384
392
|
|
385
|
-
|
393
|
+
An active record rollback could occur while enqueuing a job. In this
|
394
|
+
case the job would enqueue even though the database deletion
|
395
|
+
rolledback putting things in a funky state.
|
386
396
|
|
387
|
-
|
388
|
-
This matches the existing behavior of HABTM associations.
|
397
|
+
Now the jobs are only enqueued until after the db transaction has been committed.
|
389
398
|
|
390
|
-
|
399
|
+
*Cory Gwin*
|
391
400
|
|
392
|
-
|
401
|
+
* Fix malformed packet error in MySQL statement for connection configuration.
|
393
402
|
|
394
|
-
*
|
395
|
-
a class.
|
403
|
+
*robinroestenburg*
|
396
404
|
|
397
|
-
|
405
|
+
* Connection specification now passes the "url" key as a configuration for the
|
406
|
+
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
|
407
|
+
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
|
408
|
+
are assumed to be adapter specification urls.
|
398
409
|
|
399
|
-
|
410
|
+
Fixes #41137.
|
400
411
|
|
401
|
-
*
|
412
|
+
*Jonathan Bracy*
|
402
413
|
|
403
|
-
*
|
414
|
+
* Fix granular connection swapping when there are multiple abstract classes.
|
404
415
|
|
405
|
-
|
406
|
-
the second attribute. It will now return a hash as per previous versions.
|
416
|
+
*Eileen M. Uchitelle*
|
407
417
|
|
408
|
-
|
418
|
+
* Fix `find_by` with custom primary key for belongs_to association.
|
409
419
|
|
410
|
-
|
411
|
-
serialize :comment, JSON
|
412
|
-
end
|
420
|
+
*Ryuta Kamizono*
|
413
421
|
|
414
|
-
|
415
|
-
include ActiveModel::Model
|
416
|
-
attr_accessor :category, :text
|
417
|
-
end
|
422
|
+
* Add support for `rails console --sandbox` for multiple database applications.
|
418
423
|
|
419
|
-
|
420
|
-
post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
|
421
|
-
post.save!
|
424
|
+
*alpaca-tc*
|
422
425
|
|
423
|
-
|
424
|
-
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
|
426
|
+
* Fix `where` on polymorphic association with empty array.
|
425
427
|
|
426
|
-
|
427
|
-
post.comment # => "#<Comment:0x007f80ab48ff98>"
|
428
|
+
*Ryuta Kamizono*
|
428
429
|
|
429
|
-
|
430
|
-
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
|
430
|
+
* Fix preventing writes for `ApplicationRecord`.
|
431
431
|
|
432
|
-
|
433
|
-
new `ActiveRecord::Coders::JSON` coder which delegates its `dump/load` to
|
434
|
-
`ActiveSupport::JSON.encode/decode`. This ensures special objects are dumped
|
435
|
-
correctly using the `#as_json` hook.
|
432
|
+
*Eileen M. Uchitelle*
|
436
433
|
|
437
|
-
To keep the previous behaviour, supply a custom coder instead
|
438
|
-
([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
|
439
434
|
|
440
|
-
|
435
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
441
436
|
|
442
|
-
|
437
|
+
* Fix fixtures loading when strict loading is enabled for the association.
|
443
438
|
|
444
|
-
*
|
439
|
+
*Alex Ghiculescu*
|
445
440
|
|
446
|
-
|
441
|
+
* Fix `where` with custom primary key for belongs_to association.
|
447
442
|
|
448
|
-
*
|
443
|
+
*Ryuta Kamizono*
|
449
444
|
|
450
|
-
*
|
451
|
-
counter cache if one exists.
|
445
|
+
* Fix `where` with aliased associations.
|
452
446
|
|
453
|
-
*
|
447
|
+
*Ryuta Kamizono*
|
454
448
|
|
455
|
-
* Fix
|
456
|
-
primary key with default value of custom PostgreSQL function result.
|
449
|
+
* Fix `composed_of` with symbol mapping.
|
457
450
|
|
458
|
-
|
451
|
+
*Ryuta Kamizono*
|
459
452
|
|
460
|
-
|
453
|
+
* Don't skip money's type cast for pluck and calculations.
|
454
|
+
|
455
|
+
*Ryuta Kamizono*
|
456
|
+
|
457
|
+
* Fix `where` on polymorphic association with non Active Record object.
|
458
|
+
|
459
|
+
*Ryuta Kamizono*
|
460
|
+
|
461
|
+
* Make sure `db:prepare` works even the schema file doesn't exist.
|
462
|
+
|
463
|
+
*Rafael Mendonça França*
|
464
|
+
|
465
|
+
* Fix complicated `has_many :through` with nested where condition.
|
466
|
+
|
467
|
+
*Ryuta Kamizono*
|
468
|
+
|
469
|
+
* Handle STI models for `has_many dependent: :destroy_async`.
|
470
|
+
|
471
|
+
*Muhammad Usman*
|
472
|
+
|
473
|
+
* Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
|
474
|
+
|
475
|
+
Previously, passing `false` would trigger the option validation logic
|
476
|
+
to throw an error saying :polymorphic would not be a valid option.
|
477
|
+
|
478
|
+
*glaszig*
|
479
|
+
|
480
|
+
* Allow adding nonnamed expression indexes to be revertible.
|
481
|
+
|
482
|
+
Fixes #40732.
|
483
|
+
|
484
|
+
Previously, the following code would raise an error, when executed while rolling back,
|
485
|
+
and the index name should be specified explicitly. Now, the index name is inferred
|
486
|
+
automatically.
|
487
|
+
|
488
|
+
```ruby
|
489
|
+
add_index(:items, "to_tsvector('english', description)")
|
490
|
+
```
|
491
|
+
|
492
|
+
*fatkodima*
|
493
|
+
|
494
|
+
|
495
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
496
|
+
|
497
|
+
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
498
|
+
|
499
|
+
Fixes #39065.
|
500
|
+
|
501
|
+
*Alex Ghiculescu*
|
502
|
+
|
503
|
+
* Change `attribute_for_inspect` to take `filter_attributes` in consideration.
|
504
|
+
|
505
|
+
*Rafael Mendonça França*
|
506
|
+
|
507
|
+
* Fix odd behavior of inverse_of with multiple belongs_to to same class.
|
508
|
+
|
509
|
+
Fixes #35204.
|
510
|
+
|
511
|
+
*Tomoyuki Kai*
|
461
512
|
|
462
|
-
*
|
463
|
-
|
513
|
+
* Build predicate conditions with objects that delegate `#id` and primary key:
|
514
|
+
|
515
|
+
```ruby
|
516
|
+
class AdminAuthor
|
517
|
+
delegate_missing_to :@author
|
518
|
+
|
519
|
+
def initialize(author)
|
520
|
+
@author = author
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
Post.where(author: AdminAuthor.new(author))
|
525
|
+
```
|
526
|
+
|
527
|
+
*Sean Doyle*
|
528
|
+
|
529
|
+
* Add `connected_to_many` API.
|
530
|
+
|
531
|
+
This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
|
464
532
|
|
465
533
|
Before:
|
466
534
|
|
467
|
-
|
468
|
-
|
535
|
+
AnimalsRecord.connected_to(role: :reading) do
|
536
|
+
MealsRecord.connected_to(role: :reading) do
|
537
|
+
Dog.first # read from animals replica
|
538
|
+
Dinner.first # read from meals replica
|
539
|
+
Person.first # read from primary writer
|
540
|
+
end
|
541
|
+
end
|
469
542
|
|
470
543
|
After:
|
471
544
|
|
472
|
-
|
473
|
-
|
545
|
+
ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
|
546
|
+
Dog.first # read from animals replica
|
547
|
+
Dinner.first # read from meals replica
|
548
|
+
Person.first # read from primary writer
|
549
|
+
end
|
474
550
|
|
475
|
-
*Eileen M. Uchitelle
|
551
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
476
552
|
|
477
|
-
*
|
478
|
-
values for string columns. Otherwise, in some database, the string column
|
479
|
-
values will be coerced to a numeric allowing false or 0.seconds match any
|
480
|
-
string starting with a non-digit.
|
553
|
+
* Add option to raise or log for `ActiveRecord::StrictLoadingViolationError`.
|
481
554
|
|
482
|
-
|
555
|
+
Some applications may not want to raise an error in production if using `strict_loading`. This would allow an application to set strict loading to log for the production environment while still raising in development and test environments.
|
483
556
|
|
484
|
-
|
557
|
+
Set `config.active_record.action_on_strict_loading_violation` to `:log` errors instead of raising.
|
485
558
|
|
486
|
-
*
|
559
|
+
*Eileen M. Uchitelle*
|
560
|
+
|
561
|
+
* Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
|
487
562
|
|
488
|
-
|
489
|
-
API for presence validations on associations.
|
563
|
+
Fixes #34255.
|
490
564
|
|
491
|
-
*
|
565
|
+
*Steven Weber*
|
492
566
|
|
493
|
-
*
|
494
|
-
(Call to `count` generated invalid SQL.)
|
567
|
+
* Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
|
495
568
|
|
496
|
-
|
569
|
+
Because the default behaviour when adding an index with multiple columns is to use all column names in the index name, this could frequently lead to overly long index names for polymorphic references which would fail the migration if it exceeded the database limit.
|
497
570
|
|
498
|
-
|
571
|
+
This change reduces the chance of that happening by using the reference name, e.g. `index_my_table_on_my_reference`.
|
499
572
|
|
500
|
-
Fixes #
|
573
|
+
Fixes #38655.
|
501
574
|
|
502
|
-
*
|
575
|
+
*Luke Redpath*
|
503
576
|
|
504
|
-
*
|
577
|
+
* MySQL: Uniqueness validator now respects default database collation,
|
578
|
+
no longer enforce case sensitive comparison by default.
|
505
579
|
|
506
|
-
*
|
580
|
+
*Ryuta Kamizono*
|
581
|
+
|
582
|
+
* Remove deprecated methods from `ActiveRecord::ConnectionAdapters::DatabaseLimits`.
|
507
583
|
|
508
|
-
|
509
|
-
|
584
|
+
`column_name_length`
|
585
|
+
`table_name_length`
|
586
|
+
`columns_per_table`
|
587
|
+
`indexes_per_table`
|
588
|
+
`columns_per_multicolumn_index`
|
589
|
+
`sql_query_length`
|
590
|
+
`joins_per_query`
|
510
591
|
|
511
|
-
|
592
|
+
*Rafael Mendonça França*
|
512
593
|
|
513
|
-
|
594
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?`.
|
514
595
|
|
515
|
-
*
|
596
|
+
*Rafael Mendonça França*
|
597
|
+
|
598
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?`.
|
599
|
+
|
600
|
+
*Rafael Mendonça França*
|
601
|
+
|
602
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?`.
|
603
|
+
|
604
|
+
*Rafael Mendonça França*
|
605
|
+
|
606
|
+
* Remove deprecated `ActiveRecord::Base#update_attributes` and `ActiveRecord::Base#update_attributes!`.
|
607
|
+
|
608
|
+
*Rafael Mendonça França*
|
609
|
+
|
610
|
+
* Remove deprecated `migrations_path` argument in `ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version`.
|
611
|
+
|
612
|
+
*Rafael Mendonça França*
|
613
|
+
|
614
|
+
* Remove deprecated `config.active_record.sqlite3.represent_boolean_as_integer`.
|
615
|
+
|
616
|
+
*Rafael Mendonça França*
|
516
617
|
|
517
|
-
|
518
|
-
|
519
|
-
required.
|
618
|
+
* `relation.create` does no longer leak scope to class level querying methods
|
619
|
+
in initialization block and callbacks.
|
520
620
|
|
521
621
|
Before:
|
522
622
|
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
user.save
|
527
|
-
user.reload.name # => "Sean Griffin"
|
623
|
+
User.where(name: "John").create do |john|
|
624
|
+
User.find_by(name: "David") # => nil
|
625
|
+
end
|
528
626
|
|
529
627
|
After:
|
530
628
|
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
user.reload.name # => "Sean Griffin"
|
629
|
+
User.where(name: "John").create do |john|
|
630
|
+
User.find_by(name: "David") # => #<User name: "David", ...>
|
631
|
+
end
|
535
632
|
|
536
|
-
*
|
633
|
+
*Ryuta Kamizono*
|
537
634
|
|
538
|
-
*
|
539
|
-
is invalid.
|
635
|
+
* Named scope chain does no longer leak scope to class level querying methods.
|
540
636
|
|
541
|
-
|
637
|
+
class User < ActiveRecord::Base
|
638
|
+
scope :david, -> { User.where(name: "David") }
|
639
|
+
end
|
542
640
|
|
543
|
-
|
544
|
-
a part of `schema.rb`. This is supported by Mysql2Adapter, MysqlAdapter
|
545
|
-
and PostgreSQLAdapter.
|
641
|
+
Before:
|
546
642
|
|
547
|
-
|
548
|
-
|
643
|
+
User.where(name: "John").david
|
644
|
+
# SELECT * FROM users WHERE name = 'John' AND name = 'David'
|
549
645
|
|
550
|
-
|
646
|
+
After:
|
551
647
|
|
552
|
-
|
553
|
-
|
554
|
-
remove_foreign_key :articles, :authors
|
648
|
+
User.where(name: "John").david
|
649
|
+
# SELECT * FROM users WHERE name = 'David'
|
555
650
|
|
556
|
-
*
|
651
|
+
*Ryuta Kamizono*
|
557
652
|
|
558
|
-
*
|
559
|
-
key. `'id'` will no longer be part of the attributes hash.
|
653
|
+
* Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`.
|
560
654
|
|
561
|
-
|
655
|
+
`fetch`
|
656
|
+
`each`
|
657
|
+
`first`
|
658
|
+
`values`
|
659
|
+
`[]=`
|
562
660
|
|
563
|
-
*
|
564
|
-
broken and inconsistent.
|
661
|
+
*Rafael Mendonça França*
|
565
662
|
|
566
|
-
|
663
|
+
* `where.not` now generates NAND predicates instead of NOR.
|
567
664
|
|
568
|
-
|
665
|
+
Before:
|
569
666
|
|
570
|
-
|
667
|
+
User.where.not(name: "Jon", role: "admin")
|
668
|
+
# SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
|
571
669
|
|
572
|
-
|
670
|
+
After:
|
573
671
|
|
574
|
-
|
575
|
-
|
576
|
-
this would only occur if the old value was 0.
|
672
|
+
User.where.not(name: "Jon", role: "admin")
|
673
|
+
# SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
|
577
674
|
|
578
|
-
|
675
|
+
*Rafael Mendonça França*
|
579
676
|
|
580
|
-
|
581
|
-
model.number = '5wibble'
|
582
|
-
model.number_changed? # => true
|
677
|
+
* Remove deprecated `ActiveRecord::Result#to_hash` method.
|
583
678
|
|
584
|
-
|
679
|
+
*Rafael Mendonça França*
|
585
680
|
|
586
|
-
|
681
|
+
* Deprecate `ActiveRecord::Base.allow_unsafe_raw_sql`.
|
587
682
|
|
588
|
-
*
|
589
|
-
|
590
|
-
|
683
|
+
*Rafael Mendonça França*
|
684
|
+
|
685
|
+
* Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.
|
591
686
|
|
592
|
-
*
|
687
|
+
*Rafael Mendonça França*
|
593
688
|
|
594
|
-
*
|
595
|
-
|
689
|
+
* Allow users to silence the "Rails couldn't infer whether you are using multiple databases..."
|
690
|
+
message using `config.active_record.suppress_multiple_database_warning`.
|
596
691
|
|
597
|
-
*
|
692
|
+
*Omri Gabay*
|
598
693
|
|
599
|
-
*
|
694
|
+
* Connections can be granularly switched for abstract classes when `connected_to` is called.
|
600
695
|
|
601
|
-
|
696
|
+
This change allows `connected_to` to switch a `role` and/or `shard` for a single abstract class instead of all classes globally. Applications that want to use the new feature need to set `config.active_record.legacy_connection_handling` to `false` in their application configuration.
|
602
697
|
|
603
|
-
|
698
|
+
Example usage:
|
604
699
|
|
605
|
-
|
700
|
+
Given an application we have a `User` model that inherits from `ApplicationRecord` and a `Dog` model that inherits from `AnimalsRecord`. `AnimalsRecord` and `ApplicationRecord` have writing and reading connections as well as shard `default`, `one`, and `two`.
|
606
701
|
|
607
|
-
|
702
|
+
```ruby
|
703
|
+
ActiveRecord::Base.connected_to(role: :reading) do
|
704
|
+
User.first # reads from default replica
|
705
|
+
Dog.first # reads from default replica
|
608
706
|
|
609
|
-
|
707
|
+
AnimalsRecord.connected_to(role: :writing, shard: :one) do
|
708
|
+
User.first # reads from default replica
|
709
|
+
Dog.first # reads from shard one primary
|
710
|
+
end
|
610
711
|
|
611
|
-
|
612
|
-
|
712
|
+
User.first # reads from default replica
|
713
|
+
Dog.first # reads from default replica
|
613
714
|
|
614
|
-
|
715
|
+
ApplicationRecord.connected_to(role: :writing, shard: :two) do
|
716
|
+
User.first # reads from shard two primary
|
717
|
+
Dog.first # reads from default replica
|
718
|
+
end
|
719
|
+
end
|
720
|
+
```
|
615
721
|
|
616
|
-
*
|
722
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
617
723
|
|
618
|
-
*
|
619
|
-
through association are new.
|
724
|
+
* Allow double-dash comment syntax when querying read-only databases
|
620
725
|
|
621
|
-
*
|
726
|
+
*James Adam*
|
622
727
|
|
623
|
-
* `
|
624
|
-
Serialized attributes on ActiveRecord models will no longer save when
|
625
|
-
unchanged.
|
728
|
+
* Add `values_at` method.
|
626
729
|
|
627
|
-
|
730
|
+
Returns an array containing the values associated with the given methods.
|
628
731
|
|
629
|
-
|
732
|
+
```ruby
|
733
|
+
topic = Topic.first
|
734
|
+
topic.values_at(:title, :author_name)
|
735
|
+
# => ["Budget", "Jason"]
|
736
|
+
```
|
630
737
|
|
631
|
-
|
632
|
-
name.
|
738
|
+
Similar to `Hash#values_at` but on an Active Record instance.
|
633
739
|
|
634
|
-
|
740
|
+
*Guillaume Briday*
|
635
741
|
|
636
|
-
|
742
|
+
* Fix `read_attribute_before_type_cast` to consider attribute aliases.
|
637
743
|
|
638
|
-
*
|
744
|
+
*Marcelo Lauxen*
|
639
745
|
|
640
|
-
|
746
|
+
* Support passing record to uniqueness validator `:conditions` callable:
|
641
747
|
|
642
|
-
|
748
|
+
```ruby
|
749
|
+
class Article < ApplicationRecord
|
750
|
+
validates_uniqueness_of :title, conditions: ->(article) {
|
751
|
+
published_at = article.published_at
|
752
|
+
where(published_at: published_at.beginning_of_year..published_at.end_of_year)
|
753
|
+
}
|
754
|
+
end
|
755
|
+
```
|
643
756
|
|
644
|
-
*
|
757
|
+
*Eliot Sykes*
|
645
758
|
|
646
|
-
* `
|
647
|
-
|
759
|
+
* `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
|
760
|
+
total number of rows affected, just like their non-batched counterparts.
|
648
761
|
|
649
|
-
|
762
|
+
```ruby
|
763
|
+
Person.in_batches.update_all("first_name = 'Eugene'") # => 42
|
764
|
+
Person.in_batches.delete_all # => 42
|
765
|
+
```
|
650
766
|
|
651
|
-
|
767
|
+
Fixes #40287.
|
652
768
|
|
653
|
-
*
|
769
|
+
*Eugene Kenny*
|
654
770
|
|
655
|
-
|
771
|
+
* Add support for PostgreSQL `interval` data type with conversion to
|
772
|
+
`ActiveSupport::Duration` when loading records from database and
|
773
|
+
serialization to ISO 8601 formatted duration string on save.
|
774
|
+
Add support to define a column in migrations and get it in a schema dump.
|
775
|
+
Optional column precision is supported.
|
656
776
|
|
657
|
-
|
777
|
+
To use this in 6.1, you need to place the next string to your model file:
|
658
778
|
|
659
|
-
|
660
|
-
`primary_key_prefix_type` configuration.
|
779
|
+
attribute :duration, :interval
|
661
780
|
|
662
|
-
|
781
|
+
To keep old behavior until 7.0 is released:
|
663
782
|
|
664
|
-
|
783
|
+
attribute :duration, :string
|
665
784
|
|
666
|
-
|
785
|
+
Example:
|
667
786
|
|
668
|
-
|
787
|
+
create_table :events do |t|
|
788
|
+
t.string :name
|
789
|
+
t.interval :duration
|
790
|
+
end
|
669
791
|
|
670
|
-
|
792
|
+
class Event < ApplicationRecord
|
793
|
+
attribute :duration, :interval
|
794
|
+
end
|
671
795
|
|
672
|
-
|
796
|
+
Event.create!(name: 'Rock Fest', duration: 2.days)
|
797
|
+
Event.last.duration # => 2 days
|
798
|
+
Event.last.duration.iso8601 # => "P2D"
|
799
|
+
Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
|
800
|
+
Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
|
673
801
|
|
674
|
-
|
675
|
-
updated.
|
802
|
+
*Andrey Novikov*
|
676
803
|
|
677
|
-
|
804
|
+
* Allow associations supporting the `dependent:` key to take `dependent: :destroy_async`.
|
678
805
|
|
679
|
-
|
806
|
+
```ruby
|
807
|
+
class Account < ActiveRecord::Base
|
808
|
+
belongs_to :supplier, dependent: :destroy_async
|
809
|
+
end
|
810
|
+
```
|
680
811
|
|
681
|
-
|
682
|
-
`proper_table_name` instance method on `ActiveRecord::Migration` instead.
|
812
|
+
`:destroy_async` will enqueue a job to destroy associated records in the background.
|
683
813
|
|
684
|
-
*
|
814
|
+
*DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
|
685
815
|
|
686
|
-
*
|
687
|
-
existing column.
|
816
|
+
* Add `SKIP_TEST_DATABASE` environment variable to disable modifying the test database when `rails db:create` and `rails db:drop` are called.
|
688
817
|
|
689
|
-
|
818
|
+
*Jason Schweier*
|
690
819
|
|
691
|
-
|
820
|
+
* `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
|
692
821
|
|
693
|
-
|
694
|
-
It will return a null object in Rails 5.0
|
822
|
+
Ensure that `connects_to` can only be called from `ActiveRecord::Base` or abstract classes. This protects the application from opening duplicate or too many connections.
|
695
823
|
|
696
|
-
*
|
824
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
697
825
|
|
698
|
-
*
|
826
|
+
* All connection adapters `execute` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
827
|
+
`ActiveRecord::StatementInvalid` when they encounter a connection error.
|
699
828
|
|
700
|
-
*
|
829
|
+
*Jean Boussier*
|
701
830
|
|
702
|
-
*
|
703
|
-
|
831
|
+
* `Mysql2Adapter#quote_string` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
832
|
+
`ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
|
704
833
|
|
705
|
-
*
|
834
|
+
*Jean Boussier*
|
706
835
|
|
707
|
-
*
|
836
|
+
* Add support for check constraints that are `NOT VALID` via `validate: false` (PostgreSQL-only).
|
708
837
|
|
709
|
-
*
|
838
|
+
*Alex Robbin*
|
710
839
|
|
711
|
-
*
|
840
|
+
* Ensure the default configuration is considered primary or first for an environment
|
712
841
|
|
713
|
-
|
842
|
+
If a multiple database application provides a configuration named primary, that will be treated as default. In applications that do not have a primary entry, the default database configuration will be the first configuration for an environment.
|
714
843
|
|
715
|
-
*
|
844
|
+
*Eileen M. Uchitelle*
|
716
845
|
|
717
|
-
|
846
|
+
* Allow `where` references association names as joined table name aliases.
|
718
847
|
|
719
|
-
|
720
|
-
|
848
|
+
```ruby
|
849
|
+
class Comment < ActiveRecord::Base
|
850
|
+
enum label: [:default, :child]
|
851
|
+
has_many :children, class_name: "Comment", foreign_key: :parent_id
|
852
|
+
end
|
721
853
|
|
722
|
-
|
854
|
+
# ... FROM comments LEFT OUTER JOIN comments children ON ... WHERE children.label = 1
|
855
|
+
Comment.includes(:children).where("children.label": "child")
|
856
|
+
```
|
723
857
|
|
724
|
-
*
|
858
|
+
*Ryuta Kamizono*
|
725
859
|
|
726
|
-
|
860
|
+
* Support storing demodulized class name for polymorphic type.
|
727
861
|
|
728
|
-
|
729
|
-
|
862
|
+
Before Rails 6.1, storing demodulized class name is supported only for STI type
|
863
|
+
by `store_full_sti_class` class attribute.
|
730
864
|
|
731
|
-
|
865
|
+
Now `store_full_class_name` class attribute can handle both STI and polymorphic types.
|
732
866
|
|
733
|
-
*
|
867
|
+
*Ryuta Kamizono*
|
734
868
|
|
735
|
-
* `
|
869
|
+
* Deprecate `rails db:structure:{load, dump}` tasks and extend
|
870
|
+
`rails db:schema:{load, dump}` tasks to work with either `:ruby` or `:sql` format,
|
871
|
+
depending on `config.active_record.schema_format` configuration value.
|
736
872
|
|
737
|
-
*
|
873
|
+
*fatkodima*
|
738
874
|
|
739
|
-
*
|
740
|
-
Fixing regression case, where redefining the same `has_and_belongs_to_many`
|
741
|
-
definition into a subclass would raise.
|
875
|
+
* Respect the `select` values for eager loading.
|
742
876
|
|
743
|
-
|
877
|
+
```ruby
|
878
|
+
post = Post.select("UPPER(title) AS title").first
|
879
|
+
post.title # => "WELCOME TO THE WEBLOG"
|
880
|
+
post.body # => ActiveModel::MissingAttributeError
|
744
881
|
|
745
|
-
|
882
|
+
# Rails 6.0 (ignore the `select` values)
|
883
|
+
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
884
|
+
post.title # => "Welcome to the weblog"
|
885
|
+
post.body # => "Such a lovely day"
|
746
886
|
|
747
|
-
|
748
|
-
|
749
|
-
|
887
|
+
# Rails 6.1 (respect the `select` values)
|
888
|
+
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
889
|
+
post.title # => "WELCOME TO THE WEBLOG"
|
890
|
+
post.body # => ActiveModel::MissingAttributeError
|
891
|
+
```
|
750
892
|
|
751
|
-
|
893
|
+
*Ryuta Kamizono*
|
752
894
|
|
753
|
-
|
895
|
+
* Allow attribute's default to be configured but keeping its own type.
|
754
896
|
|
755
|
-
|
897
|
+
```ruby
|
898
|
+
class Post < ActiveRecord::Base
|
899
|
+
attribute :written_at, default: -> { Time.now.utc }
|
900
|
+
end
|
756
901
|
|
757
|
-
|
902
|
+
# Rails 6.0
|
903
|
+
Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
|
758
904
|
|
759
|
-
|
905
|
+
# Rails 6.1
|
906
|
+
Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>
|
907
|
+
```
|
760
908
|
|
761
|
-
*
|
762
|
-
on a NullRelation should return a Hash.
|
909
|
+
*Ryuta Kamizono*
|
763
910
|
|
764
|
-
|
911
|
+
* Allow default to be configured for Enum.
|
765
912
|
|
766
|
-
|
767
|
-
|
913
|
+
```ruby
|
914
|
+
class Book < ActiveRecord::Base
|
915
|
+
enum status: [:proposed, :written, :published], _default: :published
|
916
|
+
end
|
768
917
|
|
769
|
-
|
918
|
+
Book.new.status # => "published"
|
919
|
+
```
|
770
920
|
|
771
|
-
*
|
921
|
+
*Ryuta Kamizono*
|
772
922
|
|
773
|
-
|
923
|
+
* Deprecate YAML loading from legacy format older than Rails 5.0.
|
774
924
|
|
775
|
-
*
|
925
|
+
*Ryuta Kamizono*
|
776
926
|
|
777
|
-
*
|
927
|
+
* Added the setting `ActiveRecord::Base.immutable_strings_by_default`, which
|
928
|
+
allows you to specify that all string columns should be frozen unless
|
929
|
+
otherwise specified. This will reduce memory pressure for applications which
|
930
|
+
do not generally mutate string properties of Active Record objects.
|
778
931
|
|
779
|
-
|
780
|
-
record will only be touched if the record was modified. This makes it
|
781
|
-
consistent with timestamp updating on the record itself.
|
932
|
+
*Sean Griffin*, *Ryuta Kamizono*
|
782
933
|
|
783
|
-
|
934
|
+
* Deprecate `map!` and `collect!` on `ActiveRecord::Result`.
|
784
935
|
|
785
|
-
*
|
786
|
-
table inside a schema.
|
936
|
+
*Ryuta Kamizono*
|
787
937
|
|
788
|
-
|
938
|
+
* Support `relation.and` for intersection as Set theory.
|
789
939
|
|
790
|
-
|
940
|
+
```ruby
|
941
|
+
david_and_mary = Author.where(id: [david, mary])
|
942
|
+
mary_and_bob = Author.where(id: [mary, bob])
|
791
943
|
|
792
|
-
|
793
|
-
in all cases. Fixes inconsistencies when column types are sent outside of
|
794
|
-
`ActiveRecord`, such as for XML Serialization.
|
944
|
+
david_and_mary.merge(mary_and_bob) # => [mary, bob]
|
795
945
|
|
796
|
-
|
946
|
+
david_and_mary.and(mary_and_bob) # => [mary]
|
947
|
+
david_and_mary.or(mary_and_bob) # => [david, mary, bob]
|
948
|
+
```
|
797
949
|
|
798
|
-
*
|
799
|
-
extension names in PostgreSQL when migrating.
|
950
|
+
*Ryuta Kamizono*
|
800
951
|
|
801
|
-
|
952
|
+
* Merging conditions on the same column no longer maintain both conditions,
|
953
|
+
and will be consistently replaced by the latter condition in Rails 7.0.
|
954
|
+
To migrate to Rails 7.0's behavior, use `relation.merge(other, rewhere: true)`.
|
802
955
|
|
803
|
-
|
804
|
-
|
956
|
+
```ruby
|
957
|
+
# Rails 6.1 (IN clause is replaced by merger side equality condition)
|
958
|
+
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
805
959
|
|
806
|
-
|
960
|
+
# Rails 6.1 (both conflict conditions exists, deprecated)
|
961
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
|
807
962
|
|
808
|
-
|
963
|
+
# Rails 6.1 with rewhere to migrate to Rails 7.0's behavior
|
964
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
|
809
965
|
|
810
|
-
|
966
|
+
# Rails 7.0 (same behavior with IN clause, mergee side condition is consistently replaced)
|
967
|
+
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
968
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
|
969
|
+
```
|
811
970
|
|
812
|
-
*
|
813
|
-
or `offset`.
|
971
|
+
*Ryuta Kamizono*
|
814
972
|
|
815
|
-
|
816
|
-
records to be deleted.
|
973
|
+
* Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
|
817
974
|
|
818
|
-
|
975
|
+
*Peter Fry*
|
819
976
|
|
820
|
-
|
977
|
+
* Resolve issue with insert_all unique_by option when used with expression index.
|
821
978
|
|
822
|
-
|
823
|
-
|
979
|
+
When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
|
980
|
+
`ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
|
981
|
+
was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
|
824
982
|
|
825
|
-
|
983
|
+
Usage:
|
826
984
|
|
827
|
-
|
985
|
+
```ruby
|
986
|
+
create_table :books, id: :integer, force: true do |t|
|
987
|
+
t.column :name, :string
|
988
|
+
t.index "lower(name)", unique: true
|
989
|
+
end
|
828
990
|
|
829
|
-
|
830
|
-
|
991
|
+
Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
|
992
|
+
```
|
831
993
|
|
832
|
-
Fixes #
|
994
|
+
Fixes #39516.
|
833
995
|
|
834
|
-
*
|
996
|
+
*Austen Madden*
|
835
997
|
|
836
|
-
*
|
837
|
-
strings in column names as equal.
|
998
|
+
* Add basic support for CHECK constraints to database migrations.
|
838
999
|
|
839
|
-
|
840
|
-
placeholders for them in the generated SQL statement, which can make PostgreSQL
|
841
|
-
throw a `StatementInvalid` exception.
|
1000
|
+
Usage:
|
842
1001
|
|
843
|
-
|
1002
|
+
```ruby
|
1003
|
+
add_check_constraint :products, "price > 0", name: "price_check"
|
1004
|
+
remove_check_constraint :products, name: "price_check"
|
1005
|
+
```
|
844
1006
|
|
845
|
-
*
|
846
|
-
attributes defined in parent classes.
|
1007
|
+
*fatkodima*
|
847
1008
|
|
848
|
-
|
1009
|
+
* Add `ActiveRecord::Base.strict_loading_by_default` and `ActiveRecord::Base.strict_loading_by_default=`
|
1010
|
+
to enable/disable strict_loading mode by default for a model. The configuration's value is
|
1011
|
+
inheritable by subclasses, but they can override that value and it will not impact parent class.
|
849
1012
|
|
850
|
-
|
1013
|
+
Usage:
|
851
1014
|
|
852
|
-
|
1015
|
+
```ruby
|
1016
|
+
class Developer < ApplicationRecord
|
1017
|
+
self.strict_loading_by_default = true
|
853
1018
|
|
854
|
-
|
1019
|
+
has_many :projects
|
1020
|
+
end
|
855
1021
|
|
856
|
-
|
1022
|
+
dev = Developer.first
|
1023
|
+
dev.projects.first
|
1024
|
+
# => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.
|
1025
|
+
```
|
857
1026
|
|
858
|
-
*
|
1027
|
+
*bogdanvlviv*
|
859
1028
|
|
860
|
-
|
861
|
-
PostgreSQL and are used by internal system catalogs. These field types
|
862
|
-
can sometimes show up in structure-sniffing queries that feature internal system
|
863
|
-
structures or with certain PostgreSQL extensions.
|
1029
|
+
* Deprecate passing an Active Record object to `quote`/`type_cast` directly.
|
864
1030
|
|
865
|
-
*
|
1031
|
+
*Ryuta Kamizono*
|
866
1032
|
|
867
|
-
*
|
868
|
-
NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`
|
1033
|
+
* Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic.
|
869
1034
|
|
870
1035
|
Before:
|
871
1036
|
|
872
|
-
|
873
|
-
|
1037
|
+
```ruby
|
1038
|
+
create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
|
1039
|
+
end
|
1040
|
+
```
|
874
1041
|
|
875
1042
|
After:
|
876
1043
|
|
877
|
-
|
878
|
-
|
1044
|
+
```ruby
|
1045
|
+
create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
1046
|
+
end
|
1047
|
+
```
|
879
1048
|
|
880
|
-
*
|
1049
|
+
*Ryuta Kamizono*
|
881
1050
|
|
882
|
-
*
|
1051
|
+
* Added delegated type as an alternative to single-table inheritance for representing class hierarchies.
|
1052
|
+
See ActiveRecord::DelegatedType for the full description.
|
883
1053
|
|
884
|
-
|
1054
|
+
*DHH*
|
885
1055
|
|
886
|
-
|
1056
|
+
* Deprecate aggregations with group by duplicated fields.
|
887
1057
|
|
888
|
-
|
889
|
-
associations without replacement. These operations happen before instances
|
890
|
-
are created. The current behavior is unexpected and can result in broken
|
891
|
-
behavior.
|
1058
|
+
To migrate to Rails 7.0's behavior, use `uniq!(:group)` to deduplicate group fields.
|
892
1059
|
|
893
|
-
|
1060
|
+
```ruby
|
1061
|
+
accounts = Account.group(:firm_id)
|
894
1062
|
|
895
|
-
|
1063
|
+
# duplicated group fields, deprecated.
|
1064
|
+
accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
|
1065
|
+
# => {
|
1066
|
+
# [1, 1] => 50,
|
1067
|
+
# [2, 2] => 60
|
1068
|
+
# }
|
896
1069
|
|
897
|
-
|
1070
|
+
# use `uniq!(:group)` to deduplicate group fields.
|
1071
|
+
accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
|
1072
|
+
# => {
|
1073
|
+
# 1 => 50,
|
1074
|
+
# 2 => 60
|
1075
|
+
# }
|
1076
|
+
```
|
898
1077
|
|
899
|
-
|
900
|
-
size calculation if the collection is not cached or loaded.
|
1078
|
+
*Ryuta Kamizono*
|
901
1079
|
|
902
|
-
|
1080
|
+
* Deprecate duplicated query annotations.
|
903
1081
|
|
904
|
-
|
1082
|
+
To migrate to Rails 7.0's behavior, use `uniq!(:annotate)` to deduplicate query annotations.
|
905
1083
|
|
906
|
-
|
907
|
-
|
1084
|
+
```ruby
|
1085
|
+
accounts = Account.where(id: [1, 2]).annotate("david and mary")
|
908
1086
|
|
909
|
-
|
1087
|
+
# duplicated annotations, deprecated.
|
1088
|
+
accounts.merge(accounts.rewhere(id: 3))
|
1089
|
+
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
|
910
1090
|
|
911
|
-
|
1091
|
+
# use `uniq!(:annotate)` to deduplicate annotations.
|
1092
|
+
accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
|
1093
|
+
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
|
1094
|
+
```
|
912
1095
|
|
913
|
-
|
914
|
-
using namespaced models.
|
1096
|
+
*Ryuta Kamizono*
|
915
1097
|
|
916
|
-
|
1098
|
+
* Resolve conflict between counter cache and optimistic locking.
|
917
1099
|
|
918
|
-
|
1100
|
+
Bump an Active Record instance's lock version after updating its counter
|
1101
|
+
cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
|
1102
|
+
upon subsequent transactions by maintaining parity with the corresponding
|
1103
|
+
database record's `lock_version` column.
|
919
1104
|
|
920
|
-
|
921
|
-
In 4.0 series it is delegated to `Array#join`.
|
1105
|
+
Fixes #16449.
|
922
1106
|
|
923
|
-
*
|
1107
|
+
*Aaron Lipman*
|
924
1108
|
|
925
|
-
*
|
1109
|
+
* Support merging option `:rewhere` to allow mergee side condition to be replaced exactly.
|
926
1110
|
|
927
|
-
|
928
|
-
|
929
|
-
to log that nil value. This only occurs when updating a record
|
930
|
-
that already has a non-nil value in that column since an initial nil
|
931
|
-
value isn't included in the SQL anyway (at least, when dirty checking
|
932
|
-
is enabled.) The column's new value will now be logged as `<NULL binary data>`
|
933
|
-
to parallel the existing `<N bytes of binary data>` for non-nil values.
|
1111
|
+
```ruby
|
1112
|
+
david_and_mary = Author.where(id: david.id..mary.id)
|
934
1113
|
|
935
|
-
|
1114
|
+
# both conflict conditions exists
|
1115
|
+
david_and_mary.merge(Author.where(id: bob)) # => []
|
936
1116
|
|
937
|
-
|
938
|
-
|
1117
|
+
# mergee side condition is replaced by rewhere
|
1118
|
+
david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
|
939
1119
|
|
940
|
-
|
1120
|
+
# mergee side condition is replaced by rewhere option
|
1121
|
+
david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]
|
1122
|
+
```
|
941
1123
|
|
942
|
-
*
|
1124
|
+
*Ryuta Kamizono*
|
943
1125
|
|
944
|
-
*
|
1126
|
+
* Add support for finding records based on signed ids, which are tamper-proof, verified ids that can be
|
1127
|
+
set to expire and scoped with a purpose. This is particularly useful for things like password reset
|
1128
|
+
or email verification, where you want the bearer of the signed id to be able to interact with the
|
1129
|
+
underlying record, but usually only within a certain time period.
|
945
1130
|
|
946
|
-
|
947
|
-
|
1131
|
+
```ruby
|
1132
|
+
signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
|
948
1133
|
|
949
|
-
|
1134
|
+
User.find_signed signed_id # => nil, since the purpose does not match
|
950
1135
|
|
951
|
-
|
1136
|
+
travel 16.minutes
|
1137
|
+
User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
|
952
1138
|
|
953
|
-
|
1139
|
+
travel_back
|
1140
|
+
User.find_signed signed_id, purpose: :password_reset # => User.first
|
954
1141
|
|
955
|
-
|
1142
|
+
User.find_signed! "bad data" # => ActiveSupport::MessageVerifier::InvalidSignature
|
1143
|
+
```
|
956
1144
|
|
957
|
-
*
|
1145
|
+
*DHH*
|
958
1146
|
|
959
|
-
*
|
1147
|
+
* Support `ALGORITHM = INSTANT` DDL option for index operations on MySQL.
|
960
1148
|
|
961
|
-
*
|
1149
|
+
*Ryuta Kamizono*
|
962
1150
|
|
963
|
-
*
|
964
|
-
on Reflections. This causes a problem when rails loads fixtures, because it
|
965
|
-
uses the reflections to set database with fixtures.
|
1151
|
+
* Fix index creation to preserve index comment in bulk change table on MySQL.
|
966
1152
|
|
967
|
-
|
1153
|
+
*Ryuta Kamizono*
|
968
1154
|
|
969
|
-
|
1155
|
+
* Allow `unscope` to be aware of table name qualified values.
|
970
1156
|
|
971
|
-
|
972
|
-
Additionally display a warning message to make the user aware.
|
1157
|
+
It is possible to unscope only the column in the specified table.
|
973
1158
|
|
974
|
-
|
1159
|
+
```ruby
|
1160
|
+
posts = Post.joins(:comments).group(:"posts.hidden")
|
1161
|
+
posts = posts.where("posts.hidden": false, "comments.hidden": false)
|
975
1162
|
|
976
|
-
|
977
|
-
|
1163
|
+
posts.count
|
1164
|
+
# => { false => 10 }
|
978
1165
|
|
979
|
-
|
1166
|
+
# unscope both hidden columns
|
1167
|
+
posts.unscope(where: :hidden).count
|
1168
|
+
# => { false => 11, true => 1 }
|
980
1169
|
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
1170
|
+
# unscope only comments.hidden column
|
1171
|
+
posts.unscope(where: :"comments.hidden").count
|
1172
|
+
# => { false => 11 }
|
1173
|
+
```
|
985
1174
|
|
986
|
-
|
1175
|
+
*Ryuta Kamizono*, *Slava Korolev*
|
987
1176
|
|
988
|
-
|
1177
|
+
* Fix `rewhere` to truly overwrite collided where clause by new where clause.
|
989
1178
|
|
990
|
-
|
1179
|
+
```ruby
|
1180
|
+
steve = Person.find_by(name: "Steve")
|
1181
|
+
david = Author.find_by(name: "David")
|
991
1182
|
|
992
|
-
|
1183
|
+
relation = Essay.where(writer: steve)
|
993
1184
|
|
994
|
-
|
1185
|
+
# Before
|
1186
|
+
relation.rewhere(writer: david).to_a # => []
|
995
1187
|
|
996
|
-
|
1188
|
+
# After
|
1189
|
+
relation.rewhere(writer: david).to_a # => [david]
|
1190
|
+
```
|
997
1191
|
|
998
|
-
|
1192
|
+
*Ryuta Kamizono*
|
999
1193
|
|
1000
|
-
|
1194
|
+
* Inspect time attributes with subsec and time zone offset.
|
1001
1195
|
|
1002
|
-
|
1003
|
-
|
1196
|
+
```ruby
|
1197
|
+
p Knot.create
|
1198
|
+
=> #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
|
1199
|
+
```
|
1004
1200
|
|
1005
|
-
|
1006
|
-
`has_many :through` uses this association, then the scope adjustment is
|
1007
|
-
unexpectedly neglected.
|
1201
|
+
*akinomaeni*, *Jonathan Hefner*
|
1008
1202
|
|
1009
|
-
|
1203
|
+
* Deprecate passing a column to `type_cast`.
|
1010
1204
|
|
1011
|
-
*
|
1205
|
+
*Ryuta Kamizono*
|
1012
1206
|
|
1013
|
-
*
|
1207
|
+
* Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.
|
1014
1208
|
|
1015
|
-
*
|
1209
|
+
*Ryuta Kamizono*
|
1016
1210
|
|
1017
|
-
*
|
1211
|
+
* Support bulk insert/upsert on relation to preserve scope values.
|
1018
1212
|
|
1019
|
-
|
1213
|
+
*Josef Šimánek*, *Ryuta Kamizono*
|
1020
1214
|
|
1021
|
-
|
1215
|
+
* Preserve column comment value on changing column name on MySQL.
|
1022
1216
|
|
1023
|
-
*
|
1217
|
+
*Islam Taha*
|
1024
1218
|
|
1025
|
-
|
1219
|
+
* Add support for `if_exists` option for removing an index.
|
1026
1220
|
|
1027
|
-
|
1221
|
+
The `remove_index` method can take an `if_exists` option. If this is set to true an error won't be raised if the index doesn't exist.
|
1028
1222
|
|
1029
|
-
*
|
1030
|
-
LIKE statement.
|
1223
|
+
*Eileen M. Uchitelle*
|
1031
1224
|
|
1032
|
-
|
1225
|
+
* Remove ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base.
|
1033
1226
|
|
1034
|
-
|
1035
|
-
def self.search(term)
|
1036
|
-
where("title LIKE ?", sanitize_sql_like(term))
|
1037
|
-
end
|
1038
|
-
end
|
1227
|
+
*Ryuta Kamizono*
|
1039
1228
|
|
1040
|
-
|
1041
|
-
# => Query looks like "... title LIKE '20\% \_reduction\_' ..."
|
1229
|
+
* Prevent `build_association` from `touching` a parent record if the record isn't persisted for `has_one` associations.
|
1042
1230
|
|
1043
|
-
|
1231
|
+
Fixes #38219.
|
1044
1232
|
|
1045
|
-
*
|
1233
|
+
*Josh Brody*
|
1046
1234
|
|
1047
|
-
|
1235
|
+
* Add support for `if_not_exists` option for adding index.
|
1048
1236
|
|
1049
|
-
|
1237
|
+
The `add_index` method respects `if_not_exists` option. If it is set to true
|
1238
|
+
index won't be added.
|
1050
1239
|
|
1051
|
-
|
1240
|
+
Usage:
|
1052
1241
|
|
1053
|
-
|
1242
|
+
```ruby
|
1243
|
+
add_index :users, :account_id, if_not_exists: true
|
1244
|
+
```
|
1054
1245
|
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
# => true
|
1246
|
+
The `if_not_exists` option passed to `create_table` also gets propagated to indexes
|
1247
|
+
created within that migration so that if table and its indexes exist then there is no
|
1248
|
+
attempt to create them again.
|
1059
1249
|
|
1060
|
-
|
1250
|
+
*Prathamesh Sonpatki*
|
1061
1251
|
|
1062
|
-
|
1252
|
+
* Add `ActiveRecord::Base#previously_new_record?` to show if a record was new before the last save.
|
1063
1253
|
|
1064
|
-
*
|
1065
|
-
generates an SQL statement containing each id of the collection:
|
1254
|
+
*Tom Ward*
|
1066
1255
|
|
1067
|
-
|
1256
|
+
* Support descending order for `find_each`, `find_in_batches`, and `in_batches`.
|
1068
1257
|
|
1069
|
-
|
1070
|
-
AND `model`.`id` IN (1, 2, 3...)
|
1258
|
+
Batch processing methods allow you to work with the records in batches, greatly reducing memory consumption, but records are always batched from oldest id to newest.
|
1071
1259
|
|
1072
|
-
|
1260
|
+
This change allows reversing the order, batching from newest to oldest. This is useful when you need to process newer batches of records first.
|
1261
|
+
|
1262
|
+
Pass `order: :desc` to yield batches in descending order. The default remains `order: :asc`.
|
1263
|
+
|
1264
|
+
```ruby
|
1265
|
+
Person.find_each(order: :desc) do |person|
|
1266
|
+
person.party_all_night!
|
1267
|
+
end
|
1268
|
+
```
|
1269
|
+
|
1270
|
+
*Alexey Vasiliev*
|
1271
|
+
|
1272
|
+
* Fix `insert_all` with enum values.
|
1273
|
+
|
1274
|
+
Fixes #38716.
|
1275
|
+
|
1276
|
+
*Joel Blum*
|
1277
|
+
|
1278
|
+
* Add support for `db:rollback:name` for multiple database applications.
|
1279
|
+
|
1280
|
+
Multiple database applications will now raise if `db:rollback` is call and recommend using the `db:rollback:[NAME]` to rollback migrations.
|
1281
|
+
|
1282
|
+
*Eileen M. Uchitelle*
|
1283
|
+
|
1284
|
+
* `Relation#pick` now uses already loaded results instead of making another query.
|
1285
|
+
|
1286
|
+
*Eugene Kenny*
|
1287
|
+
|
1288
|
+
* Deprecate using `return`, `break` or `throw` to exit a transaction block after writes.
|
1289
|
+
|
1290
|
+
*Dylan Thacker-Smith*
|
1291
|
+
|
1292
|
+
* Dump the schema or structure of a database when calling `db:migrate:name`.
|
1293
|
+
|
1294
|
+
In previous versions of Rails, `rails db:migrate` would dump the schema of the database. In Rails 6, that holds true (`rails db:migrate` dumps all databases' schemas), but `rails db:migrate:name` does not share that behavior.
|
1295
|
+
|
1296
|
+
Going forward, calls to `rails db:migrate:name` will dump the schema (or structure) of the database being migrated.
|
1297
|
+
|
1298
|
+
*Kyle Thompson*
|
1299
|
+
|
1300
|
+
* Reset the `ActiveRecord::Base` connection after `rails db:migrate:name`.
|
1301
|
+
|
1302
|
+
When `rails db:migrate` has finished, it ensures the `ActiveRecord::Base` connection is reset to its original configuration. Going forward, `rails db:migrate:name` will have the same behavior.
|
1303
|
+
|
1304
|
+
*Kyle Thompson*
|
1305
|
+
|
1306
|
+
* Disallow calling `connected_to` on subclasses of `ActiveRecord::Base`.
|
1307
|
+
|
1308
|
+
Behavior has not changed here but the previous API could be misleading to people who thought it would switch connections for only that class. `connected_to` switches the context from which we are getting connections, not the connections themselves.
|
1309
|
+
|
1310
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1311
|
+
|
1312
|
+
* Add support for horizontal sharding to `connects_to` and `connected_to`.
|
1313
|
+
|
1314
|
+
Applications can now connect to multiple shards and switch between their shards in an application. Note that the shard swapping is still a manual process as this change does not include an API for automatic shard swapping.
|
1315
|
+
|
1316
|
+
Usage:
|
1317
|
+
|
1318
|
+
Given the following configuration:
|
1319
|
+
|
1320
|
+
```yaml
|
1321
|
+
# config/database.yml
|
1322
|
+
production:
|
1323
|
+
primary:
|
1324
|
+
database: my_database
|
1325
|
+
primary_shard_one:
|
1326
|
+
database: my_database_shard_one
|
1327
|
+
```
|
1328
|
+
|
1329
|
+
Connect to multiple shards:
|
1330
|
+
|
1331
|
+
```ruby
|
1332
|
+
class ApplicationRecord < ActiveRecord::Base
|
1333
|
+
self.abstract_class = true
|
1334
|
+
|
1335
|
+
connects_to shards: {
|
1336
|
+
default: { writing: :primary },
|
1337
|
+
shard_one: { writing: :primary_shard_one }
|
1338
|
+
}
|
1339
|
+
```
|
1340
|
+
|
1341
|
+
Swap between shards in your controller / model code:
|
1342
|
+
|
1343
|
+
```ruby
|
1344
|
+
ActiveRecord::Base.connected_to(shard: :shard_one) do
|
1345
|
+
# Read from shard one
|
1346
|
+
end
|
1347
|
+
```
|
1348
|
+
|
1349
|
+
The horizontal sharding API also supports read replicas. See guides for more details.
|
1350
|
+
|
1351
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1352
|
+
|
1353
|
+
* Deprecate `spec_name` in favor of `name` on database configurations.
|
1354
|
+
|
1355
|
+
The accessors for `spec_name` on `configs_for` and `DatabaseConfig` are deprecated. Please use `name` instead.
|
1356
|
+
|
1357
|
+
Deprecated behavior:
|
1358
|
+
|
1359
|
+
```ruby
|
1360
|
+
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
|
1361
|
+
db_config.spec_name
|
1362
|
+
```
|
1363
|
+
|
1364
|
+
New behavior:
|
1365
|
+
|
1366
|
+
```ruby
|
1367
|
+
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "development", name: "primary")
|
1368
|
+
db_config.name
|
1369
|
+
```
|
1370
|
+
|
1371
|
+
*Eileen M. Uchitelle*
|
1372
|
+
|
1373
|
+
* Add additional database-specific rake tasks for multi-database users.
|
1374
|
+
|
1375
|
+
Previously, `rails db:create`, `rails db:drop`, and `rails db:migrate` were the only rails tasks that could operate on a single
|
1376
|
+
database. For example:
|
1073
1377
|
|
1074
|
-
|
1378
|
+
```
|
1379
|
+
rails db:create
|
1380
|
+
rails db:create:primary
|
1381
|
+
rails db:create:animals
|
1382
|
+
rails db:drop
|
1383
|
+
rails db:drop:primary
|
1384
|
+
rails db:drop:animals
|
1385
|
+
rails db:migrate
|
1386
|
+
rails db:migrate:primary
|
1387
|
+
rails db:migrate:animals
|
1388
|
+
```
|
1389
|
+
|
1390
|
+
With these changes, `rails db:schema:dump`, `rails db:schema:load`, `rails db:structure:dump`, `rails db:structure:load` and
|
1391
|
+
`rails db:test:prepare` can additionally operate on a single database. For example:
|
1392
|
+
|
1393
|
+
```
|
1394
|
+
rails db:schema:dump
|
1395
|
+
rails db:schema:dump:primary
|
1396
|
+
rails db:schema:dump:animals
|
1397
|
+
rails db:schema:load
|
1398
|
+
rails db:schema:load:primary
|
1399
|
+
rails db:schema:load:animals
|
1400
|
+
rails db:structure:dump
|
1401
|
+
rails db:structure:dump:primary
|
1402
|
+
rails db:structure:dump:animals
|
1403
|
+
rails db:structure:load
|
1404
|
+
rails db:structure:load:primary
|
1405
|
+
rails db:structure:load:animals
|
1406
|
+
rails db:test:prepare
|
1407
|
+
rails db:test:prepare:primary
|
1408
|
+
rails db:test:prepare:animals
|
1409
|
+
```
|
1410
|
+
|
1411
|
+
*Kyle Thompson*
|
1412
|
+
|
1413
|
+
* Add support for `strict_loading` mode on association declarations.
|
1414
|
+
|
1415
|
+
Raise an error if attempting to load a record from an association that has been marked as `strict_loading` unless it was explicitly eager loaded.
|
1416
|
+
|
1417
|
+
Usage:
|
1418
|
+
|
1419
|
+
```ruby
|
1420
|
+
class Developer < ApplicationRecord
|
1421
|
+
has_many :projects, strict_loading: true
|
1422
|
+
end
|
1423
|
+
|
1424
|
+
dev = Developer.first
|
1425
|
+
dev.projects.first
|
1426
|
+
# => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.
|
1427
|
+
```
|
1428
|
+
|
1429
|
+
*Kevin Deisz*
|
1430
|
+
|
1431
|
+
* Add support for `strict_loading` mode to prevent lazy loading of records.
|
1432
|
+
|
1433
|
+
Raise an error if a parent record is marked as `strict_loading` and attempts to lazily load its associations. This is useful for finding places you may want to preload an association and avoid additional queries.
|
1434
|
+
|
1435
|
+
Usage:
|
1436
|
+
|
1437
|
+
```ruby
|
1438
|
+
dev = Developer.strict_loading.first
|
1439
|
+
dev.audit_logs.to_a
|
1440
|
+
# => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
|
1441
|
+
```
|
1075
1442
|
|
1076
1443
|
*Eileen M. Uchitelle*, *Aaron Patterson*
|
1077
1444
|
|
1078
|
-
*
|
1079
|
-
|
1445
|
+
* Add support for PostgreSQL 11+ partitioned indexes when using `upsert_all`.
|
1446
|
+
|
1447
|
+
*Sebastián Palma*
|
1448
|
+
|
1449
|
+
* Adds support for `if_not_exists` to `add_column` and `if_exists` to `remove_column`.
|
1080
1450
|
|
1081
|
-
|
1451
|
+
Applications can set their migrations to ignore exceptions raised when adding a column that already exists or when removing a column that does not exist.
|
1082
1452
|
|
1083
|
-
|
1453
|
+
Example Usage:
|
1084
1454
|
|
1085
|
-
|
1455
|
+
```ruby
|
1456
|
+
class AddColumnTitle < ActiveRecord::Migration[6.1]
|
1457
|
+
def change
|
1458
|
+
add_column :posts, :title, :string, if_not_exists: true
|
1459
|
+
end
|
1460
|
+
end
|
1461
|
+
```
|
1086
1462
|
|
1087
|
-
|
1463
|
+
```ruby
|
1464
|
+
class RemoveColumnTitle < ActiveRecord::Migration[6.1]
|
1465
|
+
def change
|
1466
|
+
remove_column :posts, :title, if_exists: true
|
1467
|
+
end
|
1468
|
+
end
|
1469
|
+
```
|
1088
1470
|
|
1089
|
-
*
|
1471
|
+
*Eileen M. Uchitelle*
|
1090
1472
|
|
1091
|
-
*
|
1092
|
-
unknown OIDs.
|
1473
|
+
* Regexp-escape table name for MS SQL Server.
|
1093
1474
|
|
1094
|
-
|
1475
|
+
Add `Regexp.escape` to one method in ActiveRecord, so that table names with regular expression characters in them work as expected. Since MS SQL Server uses "[" and "]" to quote table and column names, and those characters are regular expression characters, methods like `pluck` and `select` fail in certain cases when used with the MS SQL Server adapter.
|
1095
1476
|
|
1096
|
-
*
|
1477
|
+
*Larry Reid*
|
1097
1478
|
|
1098
|
-
*
|
1479
|
+
* Store advisory locks on their own named connection.
|
1099
1480
|
|
1100
|
-
|
1481
|
+
Previously advisory locks were taken out against a connection when a migration started. This works fine in single database applications but doesn't work well when migrations need to open new connections which results in the lock getting dropped.
|
1101
1482
|
|
1102
|
-
|
1483
|
+
In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdvisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
|
1103
1484
|
|
1104
|
-
*
|
1485
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1105
1486
|
|
1106
|
-
|
1487
|
+
* Allow schema cache path to be defined in the database configuration file.
|
1107
1488
|
|
1108
|
-
|
1489
|
+
For example:
|
1109
1490
|
|
1110
|
-
|
1111
|
-
|
1491
|
+
```yaml
|
1492
|
+
development:
|
1493
|
+
adapter: postgresql
|
1494
|
+
database: blog_development
|
1495
|
+
pool: 5
|
1496
|
+
schema_cache_path: tmp/schema/main.yml
|
1497
|
+
```
|
1112
1498
|
|
1113
|
-
|
1499
|
+
*Katrina Owen*
|
1114
1500
|
|
1115
|
-
|
1501
|
+
* Deprecate `#remove_connection` in favor of `#remove_connection_pool` when called on the handler.
|
1116
1502
|
|
1117
|
-
|
1503
|
+
`#remove_connection` is deprecated in order to support returning a `DatabaseConfig` object instead of a `Hash`. Use `#remove_connection_pool`, `#remove_connection` will be removed in Rails 7.0.
|
1118
1504
|
|
1119
|
-
|
1505
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1120
1506
|
|
1121
|
-
|
1507
|
+
* Deprecate `#default_hash` and it's alias `#[]` on database configurations.
|
1122
1508
|
|
1123
|
-
|
1509
|
+
Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in Rails 7.0.
|
1124
1510
|
|
1125
|
-
|
1511
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1126
1512
|
|
1127
|
-
|
1513
|
+
* Add scale support to `ActiveRecord::Validations::NumericalityValidator`.
|
1128
1514
|
|
1129
|
-
*
|
1130
|
-
could previously have incorrectly accrued additional conditions (e.g. as a result of
|
1131
|
-
a previous query). `CollectionProxy` now always defers to the association scope's
|
1132
|
-
`arel` method so the (incorrect) inherited one should be entirely concealed.
|
1515
|
+
*Gannon McGibbon*
|
1133
1516
|
|
1134
|
-
|
1517
|
+
* Find orphans by looking for missing relations through chaining `where.missing`:
|
1135
1518
|
|
1136
|
-
|
1519
|
+
Before:
|
1137
1520
|
|
1138
|
-
|
1521
|
+
```ruby
|
1522
|
+
Post.left_joins(:author).where(authors: { id: nil })
|
1523
|
+
```
|
1139
1524
|
|
1140
|
-
|
1525
|
+
After:
|
1141
1526
|
|
1142
|
-
|
1527
|
+
```ruby
|
1528
|
+
Post.where.missing(:author)
|
1529
|
+
```
|
1143
1530
|
|
1144
|
-
*
|
1531
|
+
*Tom Rossi*
|
1145
1532
|
|
1146
|
-
*
|
1533
|
+
* Ensure `:reading` connections always raise if a write is attempted.
|
1147
1534
|
|
1148
|
-
|
1535
|
+
Now Rails will raise an `ActiveRecord::ReadOnlyError` if any connection on the reading handler attempts to make a write. If your reading role needs to write you should name the role something other than `:reading`.
|
1149
1536
|
|
1150
|
-
*
|
1537
|
+
*Eileen M. Uchitelle*
|
1151
1538
|
|
1152
|
-
*
|
1153
|
-
deprecated in 4.1) from relative to absolute.
|
1539
|
+
* Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
|
1154
1540
|
|
1155
|
-
|
1156
|
-
`sqlite3:///my/path` with `sqlite3:my/path`.
|
1541
|
+
`"primary"` has been deprecated as the `connection_specification_name` for `ActiveRecord::Base` in favor of using `"ActiveRecord::Base"`. This change affects calls to `ActiveRecord::Base.connection_handler.retrieve_connection` and `ActiveRecord::Base.connection_handler.remove_connection`. If you're calling these methods with `"primary"`, please switch to `"ActiveRecord::Base"`.
|
1157
1542
|
|
1158
|
-
*
|
1543
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1159
1544
|
|
1160
|
-
*
|
1545
|
+
* Add `ActiveRecord::Validations::NumericalityValidator` with
|
1546
|
+
support for casting floats using a database columns' precision value.
|
1161
1547
|
|
1162
|
-
|
1548
|
+
*Gannon McGibbon*
|
1163
1549
|
|
1164
|
-
|
1550
|
+
* Enforce fresh ETag header after a collection's contents change by adding
|
1551
|
+
ActiveRecord::Relation#cache_key_with_version. This method will be used by
|
1552
|
+
ActionController::ConditionalGet to ensure that when collection cache versioning
|
1553
|
+
is enabled, requests using ConditionalGet don't return the same ETag header
|
1554
|
+
after a collection is modified.
|
1165
1555
|
|
1166
|
-
|
1556
|
+
Fixes #38078.
|
1167
1557
|
|
1168
|
-
*
|
1558
|
+
*Aaron Lipman*
|
1169
1559
|
|
1170
|
-
|
1560
|
+
* Skip test database when running `db:create` or `db:drop` in development
|
1561
|
+
with `DATABASE_URL` set.
|
1171
1562
|
|
1172
|
-
*
|
1563
|
+
*Brian Buchalter*
|
1173
1564
|
|
1174
|
-
|
1565
|
+
* Don't allow mutations on the database configurations hash.
|
1175
1566
|
|
1176
|
-
|
1177
|
-
The column types stay the same except for enum columns. They no longer have
|
1178
|
-
`nil` as type but `enum`.
|
1567
|
+
Freeze the configurations hash to disallow directly changing it. If applications need to change the hash, for example to create databases for parallelization, they should use the `DatabaseConfig` object directly.
|
1179
1568
|
|
1180
|
-
|
1569
|
+
Before:
|
1181
1570
|
|
1182
|
-
|
1571
|
+
```ruby
|
1572
|
+
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
|
1573
|
+
@db_config.configuration_hash.merge!(idle_timeout: "0.02")
|
1574
|
+
```
|
1183
1575
|
|
1184
|
-
|
1185
|
-
column.
|
1576
|
+
After:
|
1186
1577
|
|
1187
|
-
|
1578
|
+
```ruby
|
1579
|
+
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
|
1580
|
+
config = @db_config.configuration_hash.merge(idle_timeout: "0.02")
|
1581
|
+
db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)
|
1582
|
+
```
|
1188
1583
|
|
1189
|
-
*
|
1584
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1190
1585
|
|
1191
|
-
*
|
1192
|
-
custom primary key that did not save due to validation error.
|
1586
|
+
* Remove `:connection_id` from the `sql.active_record` notification.
|
1193
1587
|
|
1194
|
-
|
1588
|
+
*Aaron Patterson*, *Rafael Mendonça França*
|
1195
1589
|
|
1196
|
-
|
1590
|
+
* The `:name` key will no longer be returned as part of `DatabaseConfig#configuration_hash`. Please use `DatabaseConfig#owner_name` instead.
|
1197
1591
|
|
1198
|
-
*
|
1592
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1199
1593
|
|
1200
|
-
|
1594
|
+
* ActiveRecord's `belongs_to_required_by_default` flag can now be set per model.
|
1201
1595
|
|
1202
|
-
|
1596
|
+
You can now opt-out/opt-in specific models from having their associations required
|
1597
|
+
by default.
|
1203
1598
|
|
1204
|
-
|
1599
|
+
This change is meant to ease the process of migrating all your models to have
|
1600
|
+
their association required.
|
1205
1601
|
|
1206
|
-
|
1207
|
-
would commit the transaction.
|
1602
|
+
*Edouard Chin*
|
1208
1603
|
|
1209
|
-
|
1210
|
-
required.
|
1604
|
+
* The `connection_config` method has been deprecated, please use `connection_db_config` instead which will return a `DatabaseConfigurations::DatabaseConfig` instead of a `Hash`.
|
1211
1605
|
|
1212
|
-
|
1606
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1213
1607
|
|
1214
|
-
|
1215
|
-
t.index :zip
|
1216
|
-
end
|
1217
|
-
# => CREATE TEMPORARY TABLE temp (INDEX (zip)) AS SELECT id, name, zip FROM a_really_complicated_query
|
1608
|
+
* Retain explicit selections on the base model after applying `includes` and `joins`.
|
1218
1609
|
|
1219
|
-
|
1610
|
+
Resolves #34889.
|
1220
1611
|
|
1221
|
-
*
|
1222
|
-
`ActiveRecord::Base.pluralize_table_names` is `false`.
|
1612
|
+
*Patrick Rebsch*
|
1223
1613
|
|
1224
|
-
|
1614
|
+
* The `database` kwarg is deprecated without replacement because it can't be used for sharding and creates an issue if it's used during a request. Applications that need to create new connections should use `connects_to` instead.
|
1225
1615
|
|
1226
|
-
*
|
1616
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1227
1617
|
|
1228
|
-
*
|
1618
|
+
* Allow attributes to be fetched from Arel node groupings.
|
1229
1619
|
|
1230
|
-
|
1620
|
+
*Jeff Emminger*, *Gannon McGibbon*
|
1231
1621
|
|
1232
|
-
|
1233
|
-
Photo.last.touch(:signed_at, :sealed_at)
|
1622
|
+
* A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgreSQL `options`.
|
1234
1623
|
|
1235
|
-
*
|
1624
|
+
*Joshua Flanagan*
|
1236
1625
|
|
1237
|
-
* `
|
1238
|
-
migration table exists.
|
1626
|
+
* Calling methods like `establish_connection` with a `Hash` which is invalid (eg: no `adapter`) will now raise an error the same way as connections defined in `config/database.yml`.
|
1239
1627
|
|
1240
|
-
|
1628
|
+
*John Crepezzi*
|
1241
1629
|
|
1242
|
-
|
1630
|
+
* Specifying `implicit_order_column` now subsorts the records by primary key if available to ensure deterministic results.
|
1243
1631
|
|
1244
|
-
*
|
1245
|
-
of waiting until they disconnect by themselves. Before this change,
|
1246
|
-
a suitably constructed series of short-lived threads could starve
|
1247
|
-
the connection pool, without ever having more than a couple alive at
|
1248
|
-
the same time.
|
1632
|
+
*Paweł Urbanek*
|
1249
1633
|
|
1250
|
-
|
1634
|
+
* `where(attr => [])` now loads an empty result without making a query.
|
1251
1635
|
|
1252
|
-
*
|
1253
|
-
pointing to pg_class, and thus only sequence objects, are considered.
|
1636
|
+
*John Hawthorn*
|
1254
1637
|
|
1255
|
-
|
1638
|
+
* Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
|
1256
1639
|
|
1257
|
-
*
|
1640
|
+
*Hiroyuki Ishii*
|
1258
1641
|
|
1259
|
-
|
1642
|
+
* Add support for `belongs_to` to `has_many` inversing.
|
1260
1643
|
|
1261
|
-
*
|
1644
|
+
*Gannon McGibbon*
|
1262
1645
|
|
1263
|
-
*
|
1646
|
+
* Allow length configuration for `has_secure_token` method. The minimum length
|
1647
|
+
is set at 24 characters.
|
1264
1648
|
|
1265
|
-
|
1649
|
+
Before:
|
1266
1650
|
|
1267
|
-
|
1268
|
-
|
1651
|
+
```ruby
|
1652
|
+
has_secure_token :auth_token
|
1653
|
+
```
|
1269
1654
|
|
1270
|
-
|
1655
|
+
After:
|
1271
1656
|
|
1272
|
-
|
1657
|
+
```ruby
|
1658
|
+
has_secure_token :default_token # 24 characters
|
1659
|
+
has_secure_token :auth_token, length: 36 # 36 characters
|
1660
|
+
has_secure_token :invalid_token, length: 12 # => ActiveRecord::SecureToken::MinimumLengthError
|
1661
|
+
```
|
1273
1662
|
|
1274
|
-
*
|
1663
|
+
*Bernardo de Araujo*
|
1275
1664
|
|
1276
|
-
|
1665
|
+
* Deprecate `DatabaseConfigurations#to_h`. These connection hashes are still available via `ActiveRecord::Base.configurations.configs_for`.
|
1277
1666
|
|
1278
|
-
*
|
1667
|
+
*Eileen Uchitelle*, *John Crepezzi*
|
1279
1668
|
|
1280
|
-
*
|
1281
|
-
Call `.id` on the object first.
|
1669
|
+
* Add `DatabaseConfig#configuration_hash` to return database configuration hashes with symbol keys, and use all symbol-key configuration hashes internally. Deprecate `DatabaseConfig#config` which returns a String-keyed `Hash` with the same values.
|
1282
1670
|
|
1283
|
-
*
|
1671
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
1672
|
+
|
1673
|
+
* Allow column names to be passed to `remove_index` positionally along with other options.
|
1674
|
+
|
1675
|
+
Passing other options can be necessary to make `remove_index` correctly reversible.
|
1676
|
+
|
1677
|
+
Before:
|
1678
|
+
|
1679
|
+
add_index :reports, :report_id # => works
|
1680
|
+
add_index :reports, :report_id, unique: true # => works
|
1681
|
+
remove_index :reports, :report_id # => works
|
1682
|
+
remove_index :reports, :report_id, unique: true # => ArgumentError
|
1683
|
+
|
1684
|
+
After:
|
1685
|
+
|
1686
|
+
remove_index :reports, :report_id, unique: true # => works
|
1687
|
+
|
1688
|
+
*Eugene Kenny*
|
1689
|
+
|
1690
|
+
* Allow bulk `ALTER` statements to drop and recreate indexes with the same name.
|
1691
|
+
|
1692
|
+
*Eugene Kenny*
|
1693
|
+
|
1694
|
+
* `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
|
1695
|
+
|
1696
|
+
*Eugene Kenny*
|
1697
|
+
|
1698
|
+
* Call `while_preventing_writes` directly from `connected_to`.
|
1699
|
+
|
1700
|
+
In some cases application authors want to use the database switching middleware and make explicit calls with `connected_to`. It's possible for an app to turn off writes and not turn them back on by the time we call `connected_to(role: :writing)`.
|
1701
|
+
|
1702
|
+
This change allows apps to fix this by assuming if a role is writing we want to allow writes, except in the case it's explicitly turned off.
|
1703
|
+
|
1704
|
+
*Eileen M. Uchitelle*
|
1705
|
+
|
1706
|
+
* Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
|
1284
1707
|
|
1285
|
-
*
|
1286
|
-
|
1708
|
+
*Kir Shatrov*
|
1709
|
+
|
1710
|
+
* Stop trying to read yaml file fixtures when loading Active Record fixtures.
|
1711
|
+
|
1712
|
+
*Gannon McGibbon*
|
1713
|
+
|
1714
|
+
* Deprecate `.reorder(nil)` with `.first` / `.first!` taking non-deterministic result.
|
1715
|
+
|
1716
|
+
To continue taking non-deterministic result, use `.take` / `.take!` instead.
|
1287
1717
|
|
1288
1718
|
*Ryuta Kamizono*
|
1289
1719
|
|
1290
|
-
*
|
1720
|
+
* Preserve user supplied joins order as much as possible.
|
1291
1721
|
|
1292
|
-
|
1722
|
+
Fixes #36761, #34328, #24281, #12953.
|
1293
1723
|
|
1294
|
-
*
|
1295
|
-
`where` values without needing to wrap in UPPER/LOWER sql functions.
|
1724
|
+
*Ryuta Kamizono*
|
1296
1725
|
|
1297
|
-
|
1726
|
+
* Allow `matches_regex` and `does_not_match_regexp` on the MySQL Arel visitor.
|
1298
1727
|
|
1299
|
-
*
|
1300
|
-
Previously after save related callbacks, such as `#after_commit`, were triggered when the has_one
|
1301
|
-
object did not get saved to the db.
|
1728
|
+
*James Pearson*
|
1302
1729
|
|
1303
|
-
|
1730
|
+
* Allow specifying fixtures to be ignored by setting `ignore` in YAML file's '_fixture' section.
|
1304
1731
|
|
1305
|
-
*
|
1732
|
+
*Tongfei Gao*
|
1306
1733
|
|
1307
|
-
|
1734
|
+
* Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
|
1308
1735
|
|
1309
|
-
|
1736
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
1310
1737
|
|
1311
|
-
|
1738
|
+
* Add a warning for enum elements with 'not_' prefix.
|
1312
1739
|
|
1313
|
-
|
1314
|
-
|
1740
|
+
class Foo
|
1741
|
+
enum status: [:sent, :not_sent]
|
1742
|
+
end
|
1315
1743
|
|
1316
|
-
*
|
1744
|
+
*Edu Depetris*
|
1317
1745
|
|
1318
|
-
*
|
1319
|
-
joins are involved.
|
1746
|
+
* Make currency symbols optional for money column type in PostgreSQL.
|
1320
1747
|
|
1321
|
-
|
1748
|
+
*Joel Schneider*
|
1322
1749
|
|
1323
|
-
|
1750
|
+
* Add support for beginless ranges, introduced in Ruby 2.7.
|
1324
1751
|
|
1325
|
-
*
|
1326
|
-
any enum attribute is always evaluated as 0 during uniqueness validation.
|
1752
|
+
*Josh Goodall*
|
1327
1753
|
|
1328
|
-
|
1754
|
+
* Add `database_exists?` method to connection adapters to check if a database exists.
|
1329
1755
|
|
1330
|
-
*
|
1756
|
+
*Guilherme Mansur*
|
1331
1757
|
|
1332
|
-
*
|
1333
|
-
`has_and_belongs_to_many` associations *and* on `has_many :through`
|
1334
|
-
associations. Before this change, `before_add` callbacks would be fired
|
1335
|
-
before the record was saved on `has_and_belongs_to_many` associations, but
|
1336
|
-
*not* on `has_many :through` associations.
|
1758
|
+
* Loading the schema for a model that has no `table_name` raises a `TableNotSpecified` error.
|
1337
1759
|
|
1338
|
-
|
1760
|
+
*Guilherme Mansur*, *Eugene Kenny*
|
1339
1761
|
|
1340
|
-
* Fix
|
1341
|
-
private method defined on its ancestors.
|
1762
|
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
1342
1763
|
|
1343
|
-
Fixes #
|
1764
|
+
Fixes #36022.
|
1344
1765
|
|
1345
|
-
*
|
1766
|
+
*Ryuta Kamizono*
|
1346
1767
|
|
1347
|
-
*
|
1768
|
+
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
1348
1769
|
|
1349
|
-
|
1770
|
+
Fixes #36465.
|
1771
|
+
|
1772
|
+
*Jeff Doering*
|
1773
|
+
|
1774
|
+
* Add support for multiple databases to `rails db:abort_if_pending_migrations`.
|
1775
|
+
|
1776
|
+
*Mark Lee*
|
1777
|
+
|
1778
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
1779
|
+
|
1780
|
+
*Martin R. Schuster*
|
1781
|
+
|
1782
|
+
* Fix invalid schema when primary key column has a comment.
|
1350
1783
|
|
1351
|
-
|
1352
|
-
book.save!
|
1353
|
-
book.title # => "12345"
|
1784
|
+
Fixes #29966.
|
1354
1785
|
|
1355
|
-
*
|
1786
|
+
*Guilherme Goettems Schneider*
|
1356
1787
|
|
1357
|
-
*
|
1358
|
-
We currently map PostgreSQL ranges to Ruby ranges. This conversion is not fully
|
1359
|
-
possible because the Ruby range does not support excluded beginnings.
|
1788
|
+
* Fix table comment also being applied to the primary key column.
|
1360
1789
|
|
1361
|
-
|
1362
|
-
deprecated. For subtypes where we don't know how to increment (e.g. `#succ`
|
1363
|
-
is not defined) it will raise an `ArgumentException` for ranges with excluding
|
1364
|
-
beginnings.
|
1790
|
+
*Guilherme Goettems Schneider*
|
1365
1791
|
|
1366
|
-
|
1792
|
+
* Allow generated `create_table` migrations to include or skip timestamps.
|
1367
1793
|
|
1368
|
-
*
|
1794
|
+
*Michael Duchemin*
|
1369
1795
|
|
1370
|
-
*Yves Senn*
|
1371
1796
|
|
1372
|
-
Please check [
|
1797
|
+
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activerecord/CHANGELOG.md) for previous changes.
|