activerecord 4.2.0 → 6.0.5.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +852 -801
- data/MIT-LICENSE +4 -2
- data/README.rdoc +14 -13
- data/examples/performance.rb +33 -32
- data/examples/simple.rb +5 -4
- data/lib/active_record/advisory_lock_base.rb +18 -0
- data/lib/active_record/aggregations.rb +267 -249
- data/lib/active_record/association_relation.rb +26 -6
- data/lib/active_record/associations/alias_tracker.rb +29 -36
- data/lib/active_record/associations/association.rb +137 -55
- data/lib/active_record/associations/association_scope.rb +110 -132
- data/lib/active_record/associations/belongs_to_association.rb +67 -54
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +8 -12
- data/lib/active_record/associations/builder/association.rb +27 -40
- data/lib/active_record/associations/builder/belongs_to.rb +69 -55
- data/lib/active_record/associations/builder/collection_association.rb +10 -29
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +58 -70
- data/lib/active_record/associations/builder/has_many.rb +8 -4
- data/lib/active_record/associations/builder/has_one.rb +46 -5
- data/lib/active_record/associations/builder/singular_association.rb +16 -10
- data/lib/active_record/associations/collection_association.rb +150 -275
- data/lib/active_record/associations/collection_proxy.rb +253 -152
- data/lib/active_record/associations/foreign_association.rb +20 -0
- data/lib/active_record/associations/has_many_association.rb +35 -84
- data/lib/active_record/associations/has_many_through_association.rb +62 -80
- data/lib/active_record/associations/has_one_association.rb +62 -49
- data/lib/active_record/associations/has_one_through_association.rb +20 -11
- data/lib/active_record/associations/join_dependency/join_association.rb +43 -78
- 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 +159 -162
- data/lib/active_record/associations/preloader/association.rb +102 -113
- data/lib/active_record/associations/preloader/through_association.rb +85 -65
- data/lib/active_record/associations/preloader.rb +96 -95
- 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 +1737 -1596
- data/lib/active_record/attribute_assignment.rb +57 -185
- data/lib/active_record/attribute_decorators.rb +39 -17
- data/lib/active_record/attribute_methods/before_type_cast.rb +14 -5
- data/lib/active_record/attribute_methods/dirty.rb +174 -134
- data/lib/active_record/attribute_methods/primary_key.rb +90 -84
- data/lib/active_record/attribute_methods/query.rb +6 -5
- data/lib/active_record/attribute_methods/read.rb +20 -77
- data/lib/active_record/attribute_methods/serialization.rb +40 -21
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +61 -37
- data/lib/active_record/attribute_methods/write.rb +33 -56
- data/lib/active_record/attribute_methods.rb +124 -143
- data/lib/active_record/attributes.rb +213 -74
- data/lib/active_record/autosave_association.rb +125 -54
- data/lib/active_record/base.rb +60 -49
- data/lib/active_record/callbacks.rb +101 -76
- data/lib/active_record/coders/json.rb +3 -1
- data/lib/active_record/coders/yaml_column.rb +36 -13
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +810 -291
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +26 -8
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +253 -108
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +83 -24
- data/lib/active_record/connection_adapters/abstract/quoting.rb +171 -53
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +6 -4
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +74 -47
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +383 -239
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +79 -36
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +736 -235
- data/lib/active_record/connection_adapters/abstract/transaction.rb +190 -87
- data/lib/active_record/connection_adapters/abstract_adapter.rb +487 -192
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +536 -600
- data/lib/active_record/connection_adapters/column.rb +56 -43
- data/lib/active_record/connection_adapters/connection_specification.rb +174 -153
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +29 -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 +81 -0
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +71 -0
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +95 -0
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +88 -0
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +268 -0
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +31 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +59 -196
- data/lib/active_record/connection_adapters/postgresql/column.rb +21 -11
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +71 -115
- 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 +5 -1
- 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/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/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 +9 -5
- 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 +23 -25
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +144 -47
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +27 -14
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +76 -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 +465 -291
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +36 -0
- data/lib/active_record/connection_adapters/postgresql/utils.rb +11 -8
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +565 -363
- data/lib/active_record/connection_adapters/schema_cache.rb +72 -25
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +37 -0
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +119 -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 +17 -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 +137 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +299 -364
- data/lib/active_record/connection_adapters/statement_pool.rb +33 -13
- data/lib/active_record/connection_handling.rb +167 -41
- data/lib/active_record/core.rb +277 -233
- data/lib/active_record/counter_cache.rb +71 -50
- data/lib/active_record/database_configurations/database_config.rb +37 -0
- data/lib/active_record/database_configurations/hash_config.rb +50 -0
- data/lib/active_record/database_configurations/url_config.rb +78 -0
- data/lib/active_record/database_configurations.rb +233 -0
- data/lib/active_record/define_callbacks.rb +22 -0
- data/lib/active_record/dynamic_matchers.rb +87 -106
- data/lib/active_record/enum.rb +172 -89
- data/lib/active_record/errors.rb +189 -53
- data/lib/active_record/explain.rb +22 -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 +35 -9
- data/lib/active_record/fixture_set/model_metadata.rb +33 -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 +225 -497
- data/lib/active_record/gem_version.rb +6 -4
- data/lib/active_record/inheritance.rb +158 -115
- data/lib/active_record/insert_all.rb +179 -0
- data/lib/active_record/integration.rb +123 -29
- data/lib/active_record/internal_metadata.rb +53 -0
- data/lib/active_record/legacy_yaml_adapter.rb +48 -0
- data/lib/active_record/locale/en.yml +3 -2
- data/lib/active_record/locking/optimistic.rb +99 -98
- data/lib/active_record/locking/pessimistic.rb +18 -6
- data/lib/active_record/log_subscriber.rb +76 -33
- data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +87 -0
- data/lib/active_record/middleware/database_selector.rb +74 -0
- data/lib/active_record/migration/command_recorder.rb +166 -91
- data/lib/active_record/migration/compatibility.rb +244 -0
- data/lib/active_record/migration/join_table.rb +8 -7
- data/lib/active_record/migration.rb +636 -290
- data/lib/active_record/model_schema.rb +344 -112
- data/lib/active_record/nested_attributes.rb +265 -215
- data/lib/active_record/no_touching.rb +15 -2
- data/lib/active_record/null_relation.rb +24 -38
- data/lib/active_record/persistence.rb +559 -125
- data/lib/active_record/query_cache.rb +19 -23
- data/lib/active_record/querying.rb +44 -30
- data/lib/active_record/railtie.rb +166 -47
- data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
- data/lib/active_record/railties/console_sandbox.rb +2 -0
- data/lib/active_record/railties/controller_runtime.rb +34 -33
- data/lib/active_record/railties/databases.rake +341 -202
- data/lib/active_record/readonly_attributes.rb +5 -4
- data/lib/active_record/reflection.rb +461 -302
- data/lib/active_record/relation/batches/batch_enumerator.rb +69 -0
- data/lib/active_record/relation/batches.rb +206 -55
- data/lib/active_record/relation/calculations.rb +270 -249
- data/lib/active_record/relation/delegation.rb +76 -84
- data/lib/active_record/relation/finder_methods.rb +287 -255
- data/lib/active_record/relation/from_clause.rb +30 -0
- data/lib/active_record/relation/merger.rb +86 -68
- data/lib/active_record/relation/predicate_builder/array_handler.rb +27 -25
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +43 -0
- data/lib/active_record/relation/predicate_builder/base_handler.rb +18 -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 +53 -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 +112 -92
- data/lib/active_record/relation/query_attribute.rb +50 -0
- data/lib/active_record/relation/query_methods.rb +612 -392
- data/lib/active_record/relation/record_fetch_warning.rb +51 -0
- data/lib/active_record/relation/spawn_methods.rb +18 -17
- data/lib/active_record/relation/where_clause.rb +189 -0
- data/lib/active_record/relation/where_clause_factory.rb +33 -0
- data/lib/active_record/relation.rb +533 -340
- data/lib/active_record/result.rb +79 -43
- data/lib/active_record/runtime_registry.rb +6 -4
- data/lib/active_record/sanitization.rb +144 -121
- data/lib/active_record/schema.rb +21 -24
- data/lib/active_record/schema_dumper.rb +112 -93
- data/lib/active_record/schema_migration.rb +24 -20
- data/lib/active_record/scoping/default.rb +98 -82
- data/lib/active_record/scoping/named.rb +91 -33
- data/lib/active_record/scoping.rb +45 -27
- data/lib/active_record/secure_token.rb +40 -0
- data/lib/active_record/serialization.rb +5 -5
- data/lib/active_record/statement_cache.rb +73 -36
- data/lib/active_record/store.rb +127 -42
- data/lib/active_record/suppressor.rb +61 -0
- data/lib/active_record/table_metadata.rb +90 -0
- data/lib/active_record/tasks/database_tasks.rb +309 -99
- data/lib/active_record/tasks/mysql_database_tasks.rb +58 -89
- data/lib/active_record/tasks/postgresql_database_tasks.rb +81 -31
- data/lib/active_record/tasks/sqlite_database_tasks.rb +37 -16
- data/lib/active_record/test_databases.rb +23 -0
- data/lib/active_record/test_fixtures.rb +243 -0
- data/lib/active_record/timestamp.rb +86 -41
- data/lib/active_record/touch_later.rb +65 -0
- data/lib/active_record/transactions.rb +222 -146
- 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 +29 -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 +77 -23
- data/lib/active_record/type_caster/connection.rb +34 -0
- data/lib/active_record/type_caster/map.rb +20 -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/presence.rb +14 -13
- data/lib/active_record/validations/uniqueness.rb +43 -46
- data/lib/active_record/validations.rb +38 -35
- data/lib/active_record/version.rb +3 -1
- data/lib/active_record.rb +44 -21
- data/lib/arel/alias_predication.rb +9 -0
- data/lib/arel/attributes/attribute.rb +37 -0
- data/lib/arel/attributes.rb +22 -0
- data/lib/arel/collectors/bind.rb +24 -0
- data/lib/arel/collectors/composite.rb +31 -0
- data/lib/arel/collectors/plain_string.rb +20 -0
- data/lib/arel/collectors/sql_string.rb +20 -0
- data/lib/arel/collectors/substitute_binds.rb +28 -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 +52 -0
- data/lib/arel/nodes/bind_param.rb +36 -0
- data/lib/arel/nodes/case.rb +55 -0
- data/lib/arel/nodes/casted.rb +50 -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 +18 -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 +8 -0
- data/lib/arel/nodes/in.rb +8 -0
- data/lib/arel/nodes/infix_operation.rb +80 -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 +50 -0
- data/lib/arel/nodes/node_expression.rb +13 -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 +16 -0
- data/lib/arel/nodes/string_join.rb +11 -0
- data/lib/arel/nodes/table_alias.rb +27 -0
- data/lib/arel/nodes/terminal.rb +16 -0
- data/lib/arel/nodes/true.rb +16 -0
- data/lib/arel/nodes/unary.rb +45 -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 +68 -0
- data/lib/arel/order_predications.rb +13 -0
- data/lib/arel/predications.rb +256 -0
- data/lib/arel/select_manager.rb +271 -0
- data/lib/arel/table.rb +110 -0
- data/lib/arel/tree_manager.rb +72 -0
- data/lib/arel/update_manager.rb +34 -0
- data/lib/arel/visitors/depth_first.rb +203 -0
- data/lib/arel/visitors/dot.rb +296 -0
- data/lib/arel/visitors/ibm_db.rb +34 -0
- data/lib/arel/visitors/informix.rb +62 -0
- data/lib/arel/visitors/mssql.rb +156 -0
- data/lib/arel/visitors/mysql.rb +83 -0
- data/lib/arel/visitors/oracle.rb +158 -0
- data/lib/arel/visitors/oracle12.rb +65 -0
- data/lib/arel/visitors/postgresql.rb +109 -0
- data/lib/arel/visitors/sqlite.rb +38 -0
- data/lib/arel/visitors/to_sql.rb +888 -0
- data/lib/arel/visitors/visitor.rb +45 -0
- data/lib/arel/visitors/where_sql.rb +22 -0
- data/lib/arel/visitors.rb +20 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/arel.rb +62 -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 +42 -37
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +24 -0
- data/lib/rails/generators/active_record/migration/templates/{migration.rb → migration.rb.tt} +11 -8
- data/lib/rails/generators/active_record/migration.rb +30 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +18 -22
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +22 -0
- data/lib/rails/generators/active_record.rb +7 -5
- metadata +174 -63
- 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_set/builder.rb +0 -86
- data/lib/active_record/attribute_set.rb +0 -77
- 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,1423 @@
|
|
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.0.5.1 (July 12, 2022) ##
|
5
2
|
|
6
|
-
|
3
|
+
* Change ActiveRecord::Coders::YAMLColumn default to safe_load
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
This adds two new configuration options The configuration options are as
|
6
|
+
follows:
|
7
|
+
|
8
|
+
* `config.active_storage.use_yaml_unsafe_load`
|
9
|
+
|
10
|
+
When set to true, this configuration option tells Rails to use the old
|
11
|
+
"unsafe" YAML loading strategy, maintaining the existing behavior but leaving
|
12
|
+
the possible escalation vulnerability in place. Setting this option to true
|
13
|
+
is *not* recommended, but can aid in upgrading.
|
14
|
+
|
15
|
+
* `config.active_record.yaml_column_permitted_classes`
|
16
|
+
|
17
|
+
The "safe YAML" loading method does not allow all classes to be deserialized
|
18
|
+
by default. This option allows you to specify classes deemed "safe" in your
|
19
|
+
application. For example, if your application uses Symbol and Time in
|
20
|
+
serialized data, you can add Symbol and Time to the allowed list as follows:
|
21
|
+
|
22
|
+
```
|
23
|
+
config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time]
|
24
|
+
```
|
11
25
|
|
12
|
-
|
26
|
+
[CVE-2022-32224]
|
13
27
|
|
14
|
-
*Yves Senn*
|
15
28
|
|
16
|
-
|
29
|
+
## Rails 6.0.5 (May 09, 2022) ##
|
17
30
|
|
18
|
-
|
31
|
+
* No changes.
|
19
32
|
|
20
|
-
* Add `foreign_type` option to `has_one` and `has_many` association macros.
|
21
33
|
|
22
|
-
|
34
|
+
## Rails 6.0.4.8 (April 26, 2022) ##
|
23
35
|
|
24
|
-
|
36
|
+
* No changes.
|
25
37
|
|
26
|
-
* `add_timestamps` and `remove_timestamps` now properly reversible with
|
27
|
-
options.
|
28
38
|
|
29
|
-
|
39
|
+
## Rails 6.0.4.7 (March 08, 2022) ##
|
30
40
|
|
31
|
-
*
|
41
|
+
* No changes.
|
32
42
|
|
33
|
-
Manual synchronization using `bin/rake db:test:prepare` is required
|
34
|
-
when a migration is rolled-back, edited and reapplied.
|
35
43
|
|
36
|
-
|
37
|
-
to synchronize the schema. Plugins can use this task as a hook to
|
38
|
-
provide custom behavior after the schema has been loaded.
|
44
|
+
## Rails 6.0.4.6 (February 11, 2022) ##
|
39
45
|
|
40
|
-
|
46
|
+
* No changes.
|
41
47
|
|
42
|
-
Fixes #17171, #15787.
|
43
48
|
|
44
|
-
|
49
|
+
## Rails 6.0.4.5 (February 11, 2022) ##
|
45
50
|
|
46
|
-
*
|
51
|
+
* No changes.
|
47
52
|
|
48
|
-
Fixes #16928.
|
49
53
|
|
50
|
-
|
54
|
+
## Rails 6.0.4.4 (December 15, 2021) ##
|
51
55
|
|
52
|
-
*
|
56
|
+
* No changes.
|
53
57
|
|
54
|
-
Fixes #12856
|
55
58
|
|
56
|
-
|
59
|
+
## Rails 6.0.4.3 (December 14, 2021) ##
|
57
60
|
|
58
|
-
*
|
61
|
+
* No changes.
|
59
62
|
|
60
|
-
*Yves Senn*
|
61
63
|
|
62
|
-
|
63
|
-
conditions on the joined association.
|
64
|
+
## Rails 6.0.4.2 (December 14, 2021) ##
|
64
65
|
|
65
|
-
|
66
|
+
* No changes.
|
66
67
|
|
67
|
-
* Add `Table#name` to match `TableDefinition#name`.
|
68
68
|
|
69
|
-
|
69
|
+
## Rails 6.0.4.1 (August 19, 2021) ##
|
70
70
|
|
71
|
-
*
|
72
|
-
the owner has been saved so that the proxy is not cached without the
|
73
|
-
owner's id.
|
71
|
+
* No changes.
|
74
72
|
|
75
|
-
*Ben Woosley*
|
76
73
|
|
77
|
-
|
74
|
+
## Rails 6.0.4 (June 15, 2021) ##
|
78
75
|
|
79
|
-
|
76
|
+
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
80
77
|
|
81
|
-
|
78
|
+
Fixes #39065.
|
82
79
|
|
83
|
-
|
80
|
+
*Alex Ghiculescu*
|
84
81
|
|
85
|
-
|
82
|
+
* Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
|
86
83
|
|
87
|
-
|
84
|
+
Fixes #34255.
|
88
85
|
|
89
|
-
*
|
86
|
+
*Steven Weber*
|
90
87
|
|
91
|
-
*
|
92
|
-
`Relation` for performing queries and updates is the prefered API.
|
88
|
+
* Reset statement cache for association if `table_name` is changed.
|
93
89
|
|
94
|
-
|
90
|
+
Fixes #36453.
|
95
91
|
|
96
|
-
*
|
97
|
-
even when using type decorators such as `serialize`.
|
92
|
+
*Ryuta Kamizono*
|
98
93
|
|
99
|
-
|
94
|
+
* Type cast extra select for eager loading.
|
100
95
|
|
101
|
-
*
|
102
|
-
in an endless loop.
|
96
|
+
*Ryuta Kamizono*
|
103
97
|
|
104
|
-
|
98
|
+
* Prevent collection associations from being autosaved multiple times.
|
105
99
|
|
106
|
-
|
100
|
+
Fixes #39173.
|
107
101
|
|
108
|
-
*
|
102
|
+
*Eugene Kenny*
|
109
103
|
|
110
|
-
|
104
|
+
* Resolve issue with insert_all unique_by option when used with expression index.
|
111
105
|
|
112
|
-
|
106
|
+
When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
|
107
|
+
`ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
|
108
|
+
was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
|
113
109
|
|
114
|
-
|
110
|
+
Usage:
|
115
111
|
|
116
|
-
|
112
|
+
```ruby
|
113
|
+
create_table :books, id: :integer, force: true do |t|
|
114
|
+
t.column :name, :string
|
115
|
+
t.index "lower(name)", unique: true
|
116
|
+
end
|
117
117
|
|
118
|
-
|
118
|
+
Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
|
119
|
+
```
|
119
120
|
|
120
|
-
|
121
|
+
Fixes #39516.
|
121
122
|
|
122
|
-
|
123
|
-
# => ActiveRecord::UnknownAttributeError: unknown attribute 'name' for User.
|
123
|
+
*Austen Madden*
|
124
124
|
|
125
|
-
|
125
|
+
* Fix preloading for polymorphic association with custom scope.
|
126
126
|
|
127
|
-
*
|
128
|
-
records are autosaved.
|
127
|
+
*Ryuta Kamizono*
|
129
128
|
|
130
|
-
|
129
|
+
* Allow relations with different SQL comments in the `or` method.
|
131
130
|
|
132
|
-
*
|
131
|
+
*Takumi Shotoku*
|
133
132
|
|
134
|
-
*
|
135
|
-
management middleware.
|
133
|
+
* Resolve conflict between counter cache and optimistic locking.
|
136
134
|
|
137
|
-
|
135
|
+
Bump an Active Record instance's lock version after updating its counter
|
136
|
+
cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
|
137
|
+
upon subsequent transactions by maintaining parity with the corresponding
|
138
|
+
database record's `lock_version` column.
|
138
139
|
|
139
|
-
|
140
|
+
Fixes #16449.
|
140
141
|
|
141
|
-
*Aaron
|
142
|
+
*Aaron Lipman*
|
142
143
|
|
143
|
-
*
|
144
|
+
* Fix through association with source/through scope which has joins.
|
144
145
|
|
145
|
-
*
|
146
|
+
*Ryuta Kamizono*
|
146
147
|
|
147
|
-
*
|
148
|
+
* Fix through association to respect source scope for includes/preload.
|
148
149
|
|
149
|
-
*
|
150
|
+
*Ryuta Kamizono*
|
150
151
|
|
151
|
-
*
|
152
|
-
outside the schema search path.
|
152
|
+
* Fix eager load with Arel joins to maintain the original joins order.
|
153
153
|
|
154
|
-
|
154
|
+
*Ryuta Kamizono*
|
155
155
|
|
156
|
-
|
156
|
+
* Fix group by count with eager loading + order + limit/offset.
|
157
157
|
|
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.
|
158
|
+
*Ryuta Kamizono*
|
163
159
|
|
164
|
-
|
160
|
+
* Fix left joins order when merging multiple left joins from different associations.
|
165
161
|
|
166
|
-
*
|
167
|
-
`Comment.where(post_id: Post.none)` returned a non-empty result.
|
162
|
+
*Ryuta Kamizono*
|
168
163
|
|
169
|
-
|
164
|
+
* Fix index creation to preserve index comment in bulk change table on MySQL.
|
170
165
|
|
171
|
-
*
|
166
|
+
*Ryuta Kamizono*
|
172
167
|
|
173
|
-
*
|
174
|
-
|
168
|
+
* Change `remove_foreign_key` to not check `:validate` option if database
|
169
|
+
doesn't support the feature.
|
175
170
|
|
176
|
-
*
|
171
|
+
*Ryuta Kamizono*
|
177
172
|
|
178
|
-
*
|
173
|
+
* Fix the result of aggregations to maintain duplicated "group by" fields.
|
179
174
|
|
180
|
-
*
|
175
|
+
*Ryuta Kamizono*
|
181
176
|
|
182
|
-
*
|
177
|
+
* Do not return duplicated records when using preload.
|
183
178
|
|
184
|
-
*
|
179
|
+
*Bogdan Gusiev*
|
185
180
|
|
186
|
-
* SQLite3Adapter now checks for views in `table_exists?`. Fixes #14041.
|
187
181
|
|
188
|
-
|
182
|
+
## Rails 6.0.3.7 (May 05, 2021) ##
|
189
183
|
|
190
|
-
*
|
191
|
-
has support for SQL views. Connection adapters should define this method.
|
184
|
+
* No changes.
|
192
185
|
|
193
|
-
*Yves Senn*
|
194
186
|
|
195
|
-
|
187
|
+
## Rails 6.0.3.6 (March 26, 2021) ##
|
196
188
|
|
197
|
-
|
189
|
+
* No changes.
|
198
190
|
|
199
|
-
*Yves Senn*
|
200
191
|
|
201
|
-
|
202
|
-
the database connection to the current environment.
|
192
|
+
## Rails 6.0.3.5 (February 10, 2021) ##
|
203
193
|
|
204
|
-
|
194
|
+
* Fix possible DoS vector in PostgreSQL money type
|
205
195
|
|
206
|
-
|
196
|
+
Carefully crafted input can cause a DoS via the regular expressions used
|
197
|
+
for validating the money format in the PostgreSQL adapter. This patch
|
198
|
+
fixes the regexp.
|
207
199
|
|
208
|
-
|
200
|
+
Thanks to @dee-see from Hackerone for this patch!
|
209
201
|
|
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.
|
202
|
+
[CVE-2021-22880]
|
214
203
|
|
215
|
-
|
216
|
-
is unlikely to affect you.
|
204
|
+
*Aaron Patterson*
|
217
205
|
|
218
|
-
*Jeremy Kemper*
|
219
206
|
|
220
|
-
|
207
|
+
## Rails 6.0.3.4 (October 07, 2020) ##
|
221
208
|
|
222
|
-
|
209
|
+
* No changes.
|
223
210
|
|
224
|
-
* Fix a regression where whitespaces were stripped from DISTINCT queries in
|
225
|
-
PostgreSQL.
|
226
211
|
|
227
|
-
|
212
|
+
## Rails 6.0.3.3 (September 09, 2020) ##
|
228
213
|
|
229
|
-
|
214
|
+
* No changes.
|
230
215
|
|
231
|
-
* Fix has_many :through relation merging failing when dynamic conditions are
|
232
|
-
passed as a lambda with an arity of one.
|
233
216
|
|
234
|
-
|
217
|
+
## Rails 6.0.3.2 (June 17, 2020) ##
|
235
218
|
|
236
|
-
|
219
|
+
* No changes.
|
237
220
|
|
238
|
-
* Fix `Relation#exists?` to work with polymorphic associations.
|
239
221
|
|
240
|
-
|
222
|
+
## Rails 6.0.3.1 (May 18, 2020) ##
|
241
223
|
|
242
|
-
|
224
|
+
* No changes.
|
243
225
|
|
244
|
-
* Currently, Active Record rescues any errors raised within
|
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.
|
248
226
|
|
249
|
-
|
227
|
+
## Rails 6.0.3 (May 06, 2020) ##
|
250
228
|
|
251
|
-
|
229
|
+
* Recommend applications don't use the `database` kwarg in `connected_to`
|
252
230
|
|
253
|
-
|
254
|
-
config.active_record.raise_in_transactional_callbacks = true
|
231
|
+
The database kwarg in `connected_to` was meant to be used for one-off scripts but is often used in requests. This is really dangerous because it re-establishes a connection every time. It's deprecated in 6.1 and will be removed in 6.2 without replacement. This change soft deprecates it in 6.0 by removing documentation.
|
255
232
|
|
256
|
-
|
233
|
+
*Eileen M. Uchitelle*
|
257
234
|
|
258
|
-
|
235
|
+
* Fix support for PostgreSQL 11+ partitioned indexes.
|
259
236
|
|
260
|
-
*
|
261
|
-
`enum`) with the same name as a global method are incorrectly overridden
|
262
|
-
when subclassing.
|
237
|
+
*Sebastián Palma*
|
263
238
|
|
264
|
-
|
239
|
+
* Add support for beginless ranges, introduced in Ruby 2.7.
|
265
240
|
|
266
|
-
*
|
241
|
+
*Josh Goodall*
|
267
242
|
|
268
|
-
*
|
269
|
-
well.
|
243
|
+
* Fix insert_all with enum values
|
270
244
|
|
271
|
-
|
245
|
+
Fixes #38716.
|
272
246
|
|
273
|
-
*
|
247
|
+
*Joel Blum*
|
274
248
|
|
275
|
-
|
249
|
+
* Regexp-escape table name for MS SQL
|
276
250
|
|
277
|
-
|
251
|
+
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.
|
278
252
|
|
279
|
-
*
|
253
|
+
*Larry Reid*
|
280
254
|
|
281
|
-
|
255
|
+
* Store advisory locks on their own named connection.
|
282
256
|
|
283
|
-
|
257
|
+
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.
|
284
258
|
|
285
|
-
|
259
|
+
In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
|
286
260
|
|
287
|
-
|
261
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
288
262
|
|
289
|
-
|
263
|
+
* Ensure `:reading` connections always raise if a write is attempted.
|
290
264
|
|
291
|
-
|
292
|
-
index_exists? :articles, :title, name: "idx_title" # => `true`
|
293
|
-
index_exists? :articles, :body, name: "idx_title" # => `true`
|
265
|
+
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`.
|
294
266
|
|
295
|
-
|
296
|
-
index_exists? :articles, :title, name: "idx_title" # => `true`
|
297
|
-
index_exists? :articles, :body, name: "idx_title" # => `false`
|
267
|
+
*Eileen M. Uchitelle*
|
298
268
|
|
299
|
-
|
269
|
+
* Enforce fresh ETag header after a collection's contents change by adding
|
270
|
+
ActiveRecord::Relation#cache_key_with_version. This method will be used by
|
271
|
+
ActionController::ConditionalGet to ensure that when collection cache versioning
|
272
|
+
is enabled, requests using ConditionalGet don't return the same ETag header
|
273
|
+
after a collection is modified. Fixes #38078.
|
300
274
|
|
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`.
|
275
|
+
*Aaron Lipman*
|
304
276
|
|
305
|
-
|
277
|
+
* A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgresSQL `options`.
|
306
278
|
|
307
|
-
*
|
308
|
-
message now reflects whether that object is a new record or has been
|
309
|
-
destroyed.
|
279
|
+
*Joshua Flanagan*
|
310
280
|
|
311
|
-
|
281
|
+
* Retain explicit selections on the base model after applying `includes` and `joins`.
|
312
282
|
|
313
|
-
|
283
|
+
Resolves #34889.
|
314
284
|
|
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.
|
285
|
+
*Patrick Rebsch*
|
319
286
|
|
320
|
-
Fixes #16413.
|
321
287
|
|
322
|
-
|
288
|
+
## Rails 6.0.2.2 (March 19, 2020) ##
|
323
289
|
|
324
|
-
*
|
325
|
-
Use `.load_schema_current` instead. In the future `load_schema` will
|
326
|
-
require the `configuration` to act on as an argument.
|
290
|
+
* No changes.
|
327
291
|
|
328
|
-
*Yves Senn*
|
329
292
|
|
330
|
-
|
331
|
-
schema format.
|
293
|
+
## Rails 6.0.2.1 (December 18, 2019) ##
|
332
294
|
|
333
|
-
|
295
|
+
* No changes.
|
334
296
|
|
335
|
-
*Wojciech Wnętrzak*
|
336
297
|
|
337
|
-
|
298
|
+
## Rails 6.0.2 (December 13, 2019) ##
|
338
299
|
|
339
|
-
|
300
|
+
* Share the same connection pool for primary and replica databases in the
|
301
|
+
transactional tests for the same database.
|
340
302
|
|
341
|
-
*
|
303
|
+
*Edouard Chin*
|
342
304
|
|
343
|
-
|
344
|
-
|
345
|
-
was removed in #16353.
|
305
|
+
* Fix the preloader when one record is fetched using `after_initialize`
|
306
|
+
but not the entire collection.
|
346
307
|
|
347
|
-
*
|
308
|
+
*Bradley Price*
|
348
309
|
|
349
|
-
*
|
310
|
+
* Fix collection callbacks not terminating when `:abort` is thrown.
|
350
311
|
|
351
|
-
|
312
|
+
*Edouard Chin*, *Ryuta Kamizono*
|
352
313
|
|
353
|
-
|
314
|
+
* Correctly deprecate `where.not` working as NOR for relations.
|
354
315
|
|
355
|
-
|
316
|
+
12a9664 deprecated where.not working as NOR, however
|
317
|
+
doing a relation query like `where.not(relation: { ... })`
|
318
|
+
wouldn't be properly deprecated and `where.not` would work as
|
319
|
+
NAND instead.
|
356
320
|
|
357
|
-
|
321
|
+
*Edouard Chin*
|
358
322
|
|
359
|
-
|
360
|
-
|
361
|
-
end
|
323
|
+
* Fix `db:migrate` task with multiple databases to restore the connection
|
324
|
+
to the previous database.
|
362
325
|
|
363
|
-
|
326
|
+
The migrate task iterates and establish a connection over each db
|
327
|
+
resulting in the last one to be used by subsequent rake tasks.
|
328
|
+
We should reestablish a connection to the connection that was
|
329
|
+
established before the migrate tasks was run
|
364
330
|
|
365
|
-
*
|
331
|
+
*Edouard Chin*
|
366
332
|
|
367
|
-
|
333
|
+
* Fix multi-threaded issue for `AcceptanceValidator`.
|
368
334
|
|
369
|
-
*
|
370
|
-
`DROP DEFAULT` instead of a `DEFAULT NULL` query.
|
335
|
+
*Ryuta Kamizono*
|
371
336
|
|
372
|
-
Fixes #16261.
|
373
337
|
|
374
|
-
|
338
|
+
## Rails 6.0.1 (November 5, 2019) ##
|
375
339
|
|
376
|
-
*
|
377
|
-
and `add_reference`.
|
340
|
+
* Common Table Expressions are allowed on read-only connections.
|
378
341
|
|
379
|
-
|
342
|
+
*Chris Morris*
|
380
343
|
|
381
|
-
|
382
|
-
t.references :station, type: :uuid
|
383
|
-
end
|
344
|
+
* New record instantiation respects `unscope`.
|
384
345
|
|
385
|
-
|
346
|
+
*Ryuta Kamizono*
|
386
347
|
|
387
|
-
*
|
388
|
-
This matches the existing behavior of HABTM associations.
|
348
|
+
* Fixed a case where `find_in_batches` could halt too early.
|
389
349
|
|
390
|
-
|
350
|
+
*Takayuki Nakata*
|
391
351
|
|
392
|
-
|
352
|
+
* Autosaved associations always perform validations when a custom validation
|
353
|
+
context is used.
|
393
354
|
|
394
|
-
*
|
395
|
-
a class.
|
355
|
+
*Tekin Suleyman*
|
396
356
|
|
397
|
-
|
357
|
+
* `sql.active_record` notifications now include the `:connection` in
|
358
|
+
their payloads.
|
398
359
|
|
399
|
-
*
|
360
|
+
*Eugene Kenny*
|
400
361
|
|
401
|
-
|
362
|
+
* A rollback encountered in an `after_commit` callback does not reset
|
363
|
+
previously-committed record state.
|
402
364
|
|
403
|
-
*
|
365
|
+
*Ryuta Kamizono*
|
404
366
|
|
405
|
-
|
406
|
-
the second attribute. It will now return a hash as per previous versions.
|
367
|
+
* Fixed that join order was lost when eager-loading.
|
407
368
|
|
408
|
-
|
369
|
+
*Ryuta Kamizono*
|
409
370
|
|
410
|
-
|
411
|
-
serialize :comment, JSON
|
412
|
-
end
|
371
|
+
* `DESCRIBE` queries are allowed on read-only connections.
|
413
372
|
|
414
|
-
|
415
|
-
include ActiveModel::Model
|
416
|
-
attr_accessor :category, :text
|
417
|
-
end
|
373
|
+
*Dylan Thacker-Smith*
|
418
374
|
|
419
|
-
|
420
|
-
post.comment = Comment.new(category: "Animals", text: "This is a comment about squirrels.")
|
421
|
-
post.save!
|
375
|
+
* Fixed that records that had been `inspect`ed could not be marshaled.
|
422
376
|
|
423
|
-
|
424
|
-
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
|
377
|
+
*Eugene Kenny*
|
425
378
|
|
426
|
-
|
427
|
-
|
379
|
+
* The connection pool reaper thread is respawned in forked processes. This
|
380
|
+
fixes that idle connections in forked processes wouldn't be reaped.
|
428
381
|
|
429
|
-
|
430
|
-
post.comment # => {"category"=>"Animals", "text"=>"This is a comment about squirrels."}
|
382
|
+
*John Hawthorn*
|
431
383
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
correctly using the `#as_json` hook.
|
384
|
+
* The memoized result of `ActiveRecord::Relation#take` is properly cleared
|
385
|
+
when `ActiveRecord::Relation#reset` or `ActiveRecord::Relation#reload`
|
386
|
+
is called.
|
436
387
|
|
437
|
-
|
438
|
-
([example](https://gist.github.com/jenncoop/8c4142bbe59da77daa63)).
|
388
|
+
*Anmol Arora*
|
439
389
|
|
440
|
-
|
390
|
+
* Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
|
441
391
|
|
442
|
-
*
|
392
|
+
*Hiroyuki Ishii*
|
443
393
|
|
444
|
-
*
|
394
|
+
* `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
|
445
395
|
|
446
|
-
|
396
|
+
*Eugene Kenny*
|
447
397
|
|
448
|
-
|
398
|
+
* Call `while_preventing_writes` directly from `connected_to`.
|
449
399
|
|
450
|
-
|
451
|
-
counter cache if one exists.
|
400
|
+
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)`.
|
452
401
|
|
453
|
-
|
402
|
+
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.
|
454
403
|
|
455
|
-
*
|
456
|
-
primary key with default value of custom PostgreSQL function result.
|
404
|
+
*Eileen M. Uchitelle*
|
457
405
|
|
458
|
-
|
406
|
+
* Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
|
459
407
|
|
460
|
-
*
|
408
|
+
*Kir Shatrov*
|
461
409
|
|
462
|
-
* Fix the SQL generated when a `delete_all` is run on an association to not
|
463
|
-
produce an `IN` statements.
|
464
410
|
|
465
|
-
|
411
|
+
## Rails 6.0.0 (August 16, 2019) ##
|
466
412
|
|
467
|
-
|
468
|
-
"categorizations"."category_id" = 1 AND "categorizations"."id" IN (1, 2)
|
413
|
+
* Preserve user supplied joins order as much as possible.
|
469
414
|
|
470
|
-
|
415
|
+
Fixes #36761, #34328, #24281, #12953.
|
471
416
|
|
472
|
-
|
473
|
-
"categorizations"."category_id" = 1
|
417
|
+
*Ryuta Kamizono*
|
474
418
|
|
475
|
-
|
419
|
+
* Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
|
476
420
|
|
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.
|
421
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
481
422
|
|
482
|
-
|
423
|
+
* Add a warning for enum elements with 'not_' prefix.
|
483
424
|
|
484
|
-
|
425
|
+
class Foo
|
426
|
+
enum status: [:sent, :not_sent]
|
427
|
+
end
|
485
428
|
|
486
|
-
*
|
429
|
+
*Edu Depetris*
|
487
430
|
|
488
|
-
*
|
489
|
-
API for presence validations on associations.
|
431
|
+
* Make currency symbols optional for money column type in PostgreSQL
|
490
432
|
|
491
|
-
*
|
433
|
+
*Joel Schneider*
|
492
434
|
|
493
|
-
* Fix an error in `reset_counters` when associations have `select` scope.
|
494
|
-
(Call to `count` generated invalid SQL.)
|
495
435
|
|
496
|
-
|
436
|
+
## Rails 6.0.0.rc2 (July 22, 2019) ##
|
497
437
|
|
498
|
-
*
|
438
|
+
* Add database_exists? method to connection adapters to check if a database exists.
|
499
439
|
|
500
|
-
|
440
|
+
*Guilherme Mansur*
|
501
441
|
|
502
|
-
|
442
|
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
503
443
|
|
504
|
-
|
444
|
+
Fixes #36022.
|
505
445
|
|
506
|
-
*
|
446
|
+
*Ryuta Kamizono*
|
507
447
|
|
508
|
-
*
|
509
|
-
from `before_destroy` to `after_destroy` callback chain
|
448
|
+
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
510
449
|
|
511
|
-
Fixes #
|
450
|
+
Fixes #36465.
|
512
451
|
|
513
|
-
*
|
452
|
+
*Jeff Doering*
|
514
453
|
|
515
|
-
*
|
454
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
516
455
|
|
517
|
-
|
518
|
-
changed in order for it to be persisted in the database. Now it is no longer
|
519
|
-
required.
|
456
|
+
*Martin R. Schuster*
|
520
457
|
|
521
|
-
|
458
|
+
* Fix invalid schema when primary key column has a comment.
|
522
459
|
|
523
|
-
|
524
|
-
user.name << ' Griffin'
|
525
|
-
user.name_will_change!
|
526
|
-
user.save
|
527
|
-
user.reload.name # => "Sean Griffin"
|
460
|
+
Fixes #29966.
|
528
461
|
|
529
|
-
|
462
|
+
*Guilherme Goettems Schneider*
|
530
463
|
|
531
|
-
|
532
|
-
user.name << ' Griffin'
|
533
|
-
user.save
|
534
|
-
user.reload.name # => "Sean Griffin"
|
464
|
+
* Fix table comment also being applied to the primary key column.
|
535
465
|
|
536
|
-
*
|
466
|
+
*Guilherme Goettems Schneider*
|
537
467
|
|
538
|
-
*
|
539
|
-
is invalid.
|
468
|
+
* Fix merging left_joins to maintain its own `join_type` context.
|
540
469
|
|
541
|
-
|
470
|
+
Fixes #36103.
|
542
471
|
|
543
|
-
*
|
544
|
-
a part of `schema.rb`. This is supported by Mysql2Adapter, MysqlAdapter
|
545
|
-
and PostgreSQLAdapter.
|
472
|
+
*Ryuta Kamizono*
|
546
473
|
|
547
|
-
Many thanks to *Matthew Higgins* for laying the foundation with his work on
|
548
|
-
[foreigner](https://github.com/matthuhiggins/foreigner).
|
549
474
|
|
550
|
-
|
475
|
+
## Rails 6.0.0.rc1 (April 24, 2019) ##
|
551
476
|
|
552
|
-
|
553
|
-
add_foreign_key :articles, :authors
|
554
|
-
remove_foreign_key :articles, :authors
|
477
|
+
* Add `touch` option to `has_one` association.
|
555
478
|
|
556
|
-
*
|
479
|
+
*Abhay Nikam*
|
557
480
|
|
558
|
-
*
|
559
|
-
key. `'id'` will no longer be part of the attributes hash.
|
481
|
+
* Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
|
560
482
|
|
561
|
-
|
483
|
+
```ruby
|
484
|
+
all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
|
485
|
+
assert_equal all, PriceEstimate.all.map(&:estimate_of)
|
486
|
+
```
|
562
487
|
|
563
|
-
|
564
|
-
broken and inconsistent.
|
488
|
+
In Rails 6.0:
|
565
489
|
|
566
|
-
|
490
|
+
```ruby
|
491
|
+
sapphire = treasures(:sapphire)
|
567
492
|
|
568
|
-
|
493
|
+
nor = all.reject { |e|
|
494
|
+
e.estimate_of_type == sapphire.class.polymorphic_name
|
495
|
+
}.reject { |e|
|
496
|
+
e.estimate_of_id == sapphire.id
|
497
|
+
}
|
498
|
+
assert_equal [cars(:honda)], nor
|
569
499
|
|
570
|
-
|
500
|
+
without_sapphire = PriceEstimate.where.not(
|
501
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
502
|
+
)
|
503
|
+
assert_equal nor, without_sapphire.map(&:estimate_of)
|
504
|
+
```
|
571
505
|
|
572
|
-
|
506
|
+
In Rails 6.1:
|
573
507
|
|
574
|
-
|
575
|
-
|
576
|
-
this would only occur if the old value was 0.
|
508
|
+
```ruby
|
509
|
+
sapphire = treasures(:sapphire)
|
577
510
|
|
578
|
-
|
511
|
+
nand = all - [sapphire]
|
512
|
+
assert_equal [treasures(:diamond), cars(:honda)], nand
|
579
513
|
|
580
|
-
|
581
|
-
|
582
|
-
|
514
|
+
without_sapphire = PriceEstimate.where.not(
|
515
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
516
|
+
)
|
517
|
+
assert_equal nand, without_sapphire.map(&:estimate_of)
|
518
|
+
```
|
583
519
|
|
584
|
-
|
520
|
+
*Ryuta Kamizono*
|
585
521
|
|
586
|
-
|
522
|
+
* Fix dirty tracking after rollback.
|
587
523
|
|
588
|
-
|
589
|
-
The attribute hash is fully replaced. The record is put into the same state
|
590
|
-
as it would be with `Model.find(model.id)`.
|
524
|
+
Fixes #15018, #30167, #33868.
|
591
525
|
|
592
|
-
*
|
526
|
+
*Ryuta Kamizono*
|
593
527
|
|
594
|
-
*
|
595
|
-
|
528
|
+
* Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
|
529
|
+
the versioned entries in `ActiveSupport::Cache`. This also means that
|
530
|
+
`ActiveRecord::Relation#cache_key` will now return a stable key that does not
|
531
|
+
include the max timestamp or count any more.
|
596
532
|
|
597
|
-
|
533
|
+
NOTE: This feature is turned off by default, and `cache_key` will still return
|
534
|
+
cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
|
535
|
+
That's the setting for all new apps on Rails 6.0+
|
536
|
+
|
537
|
+
*Lachlan Sylvester*
|
598
538
|
|
599
|
-
*
|
539
|
+
* Fix dirty tracking for `touch` to track saved changes.
|
600
540
|
|
601
|
-
|
541
|
+
Fixes #33429.
|
602
542
|
|
603
|
-
*
|
543
|
+
*Ryuta Kamzono*
|
604
544
|
|
605
|
-
|
545
|
+
* `change_column_comment` and `change_table_comment` are invertible only if
|
546
|
+
`to` and `from` options are specified.
|
606
547
|
|
607
|
-
*
|
548
|
+
*Yoshiyuki Kinjo*
|
608
549
|
|
609
|
-
|
550
|
+
* Don't call commit/rollback callbacks when a record isn't saved.
|
610
551
|
|
611
|
-
|
612
|
-
are part of the URI structure, not the actual host.
|
552
|
+
Fixes #29747.
|
613
553
|
|
614
|
-
|
554
|
+
*Ryuta Kamizono*
|
615
555
|
|
616
|
-
|
556
|
+
* Fix circular `autosave: true` causes invalid records to be saved.
|
617
557
|
|
618
|
-
|
619
|
-
|
558
|
+
Prior to the fix, when there was a circular series of `autosave: true`
|
559
|
+
associations, the callback for a `has_many` association was run while
|
560
|
+
another instance of the same callback on the same association hadn't
|
561
|
+
finished running. When control returned to the first instance of the
|
562
|
+
callback, the instance variable had changed, and subsequent associated
|
563
|
+
records weren't saved correctly. Specifically, the ID field for the
|
564
|
+
`belongs_to` corresponding to the `has_many` was `nil`.
|
620
565
|
|
621
|
-
|
566
|
+
Fixes #28080.
|
622
567
|
|
623
|
-
*
|
624
|
-
Serialized attributes on ActiveRecord models will no longer save when
|
625
|
-
unchanged.
|
568
|
+
*Larry Reid*
|
626
569
|
|
627
|
-
|
570
|
+
* Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
|
628
571
|
|
629
|
-
|
572
|
+
Before:
|
630
573
|
|
631
|
-
|
632
|
-
|
574
|
+
```ruby
|
575
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
576
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
577
|
+
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
|
578
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
|
579
|
+
```
|
633
580
|
|
634
|
-
|
581
|
+
After:
|
635
582
|
|
636
|
-
|
583
|
+
```ruby
|
584
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
585
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
586
|
+
add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
|
587
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
|
588
|
+
```
|
637
589
|
|
638
|
-
*
|
590
|
+
*Ryuta Kamizono*
|
639
591
|
|
640
|
-
|
592
|
+
* Association loading isn't to be affected by scoping consistently
|
593
|
+
whether preloaded / eager loaded or not, with the exception of `unscoped`.
|
641
594
|
|
642
|
-
|
595
|
+
Before:
|
643
596
|
|
644
|
-
|
597
|
+
```ruby
|
598
|
+
Post.where("1=0").scoping do
|
599
|
+
Comment.find(1).post # => nil
|
600
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
601
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
602
|
+
end
|
603
|
+
```
|
645
604
|
|
646
|
-
|
647
|
-
`Enumerable#find` does.
|
605
|
+
After:
|
648
606
|
|
649
|
-
|
607
|
+
```ruby
|
608
|
+
Post.where("1=0").scoping do
|
609
|
+
Comment.find(1).post # => #<Post id: 1, ...>
|
610
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
611
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
612
|
+
end
|
613
|
+
```
|
650
614
|
|
651
|
-
|
615
|
+
Fixes #34638, #35398.
|
652
616
|
|
653
|
-
*
|
617
|
+
*Ryuta Kamizono*
|
654
618
|
|
655
|
-
|
619
|
+
* Add `rails db:prepare` to migrate or setup a database.
|
656
620
|
|
657
|
-
|
621
|
+
Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
|
658
622
|
|
659
|
-
*
|
660
|
-
`primary_key_prefix_type` configuration.
|
623
|
+
*Roberto Miranda*
|
661
624
|
|
662
|
-
|
625
|
+
* Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
|
663
626
|
|
664
|
-
*
|
627
|
+
*DHH*
|
665
628
|
|
666
|
-
*
|
629
|
+
* Assign all attributes before calling `build` to ensure the child record is visible in
|
630
|
+
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
667
631
|
|
668
|
-
Fixes #
|
632
|
+
Fixes #33249.
|
669
633
|
|
670
|
-
*
|
634
|
+
*Ryan H. Kerr*
|
671
635
|
|
672
|
-
*
|
636
|
+
* Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
|
673
637
|
|
674
|
-
|
675
|
-
|
638
|
+
```
|
639
|
+
account.memberships.extract_associated(:user)
|
640
|
+
# => Returns collection of User records
|
641
|
+
```
|
676
642
|
|
677
|
-
|
643
|
+
*DHH*
|
678
644
|
|
679
|
-
|
645
|
+
* Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
|
680
646
|
|
681
|
-
|
682
|
-
`proper_table_name` instance method on `ActiveRecord::Migration` instead.
|
647
|
+
For example:
|
683
648
|
|
684
|
-
|
649
|
+
```
|
650
|
+
Post.where(id: 123).annotate("this is a comment").to_sql
|
651
|
+
# SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
|
652
|
+
```
|
685
653
|
|
686
|
-
|
687
|
-
existing column.
|
654
|
+
This can be useful in instrumentation or other analysis of issued queries.
|
688
655
|
|
689
|
-
|
656
|
+
*Matt Yoho*
|
690
657
|
|
691
|
-
|
658
|
+
* Support Optimizer Hints.
|
692
659
|
|
693
|
-
|
694
|
-
|
660
|
+
In most databases, a way to control the optimizer is by using optimizer hints,
|
661
|
+
which can be specified within individual statements.
|
695
662
|
|
696
|
-
|
663
|
+
Example (for MySQL):
|
697
664
|
|
698
|
-
|
665
|
+
Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
|
666
|
+
# SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
|
699
667
|
|
700
|
-
|
668
|
+
Example (for PostgreSQL with pg_hint_plan):
|
701
669
|
|
702
|
-
|
703
|
-
|
670
|
+
Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
|
671
|
+
# SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
|
704
672
|
|
705
|
-
|
673
|
+
See also:
|
706
674
|
|
707
|
-
*
|
675
|
+
* https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
|
676
|
+
* https://pghintplan.osdn.jp/pg_hint_plan.html
|
677
|
+
* https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
|
678
|
+
* https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
|
679
|
+
* https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
|
708
680
|
|
709
|
-
*
|
681
|
+
*Ryuta Kamizono*
|
710
682
|
|
711
|
-
*
|
683
|
+
* Fix query attribute method on user-defined attribute to be aware of typecasted value.
|
712
684
|
|
713
|
-
|
685
|
+
For example, the following code no longer return false as casted non-empty string:
|
714
686
|
|
715
|
-
|
687
|
+
```
|
688
|
+
class Post < ActiveRecord::Base
|
689
|
+
attribute :user_defined_text, :text
|
690
|
+
end
|
716
691
|
|
717
|
-
|
692
|
+
Post.new(user_defined_text: "false").user_defined_text? # => true
|
693
|
+
```
|
718
694
|
|
719
|
-
*
|
720
|
-
with orders without sort direction modifiers.
|
695
|
+
*Yuji Kamijima*
|
721
696
|
|
722
|
-
|
697
|
+
* Quote empty ranges like other empty enumerables.
|
723
698
|
|
724
|
-
*
|
699
|
+
*Patrick Rebsch*
|
725
700
|
|
726
|
-
|
701
|
+
* Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
|
702
|
+
allowing bulk inserts akin to the bulk updates provided by `update_all` and
|
703
|
+
bulk deletes by `delete_all`.
|
727
704
|
|
728
|
-
|
729
|
-
|
705
|
+
Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
|
706
|
+
for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
|
707
|
+
for MySQL.
|
730
708
|
|
731
|
-
|
709
|
+
*Bob Lail*
|
732
710
|
|
733
|
-
|
711
|
+
* Add `rails db:seed:replant` that truncates tables of each database
|
712
|
+
for current environment and loads the seeds.
|
734
713
|
|
735
|
-
*
|
714
|
+
*bogdanvlviv*, *DHH*
|
736
715
|
|
737
|
-
|
716
|
+
* Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
|
738
717
|
|
739
|
-
*
|
740
|
-
Fixing regression case, where redefining the same `has_and_belongs_to_many`
|
741
|
-
definition into a subclass would raise.
|
718
|
+
*bogdanvlviv*
|
742
719
|
|
743
|
-
|
720
|
+
* Deprecate mismatched collation comparison for uniqueness validator.
|
744
721
|
|
745
|
-
|
722
|
+
Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
|
723
|
+
To continue case sensitive comparison on the case insensitive column,
|
724
|
+
pass `case_sensitive: true` option explicitly to the uniqueness validator.
|
746
725
|
|
747
|
-
*
|
748
|
-
When defining a `has_and_belongs_to_many`, internally we convert that to two has_many.
|
749
|
-
But as `reflections` is a public API, people expect to see the right macro.
|
726
|
+
*Ryuta Kamizono*
|
750
727
|
|
751
|
-
|
728
|
+
* Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
|
752
729
|
|
753
|
-
|
730
|
+
Fixes #27340.
|
754
731
|
|
755
|
-
*
|
732
|
+
*Willian Gustavo Veiga*
|
756
733
|
|
757
|
-
|
734
|
+
* Add negative scopes for all enum values.
|
758
735
|
|
759
|
-
|
736
|
+
Example:
|
760
737
|
|
761
|
-
|
762
|
-
|
738
|
+
class Post < ActiveRecord::Base
|
739
|
+
enum status: %i[ drafted active trashed ]
|
740
|
+
end
|
763
741
|
|
764
|
-
|
742
|
+
Post.not_drafted # => where.not(status: :drafted)
|
743
|
+
Post.not_active # => where.not(status: :active)
|
744
|
+
Post.not_trashed # => where.not(status: :trashed)
|
765
745
|
|
766
|
-
*
|
767
|
-
`update_column`.
|
746
|
+
*DHH*
|
768
747
|
|
769
|
-
|
748
|
+
* Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
|
770
749
|
|
771
|
-
|
750
|
+
Fixes #35214.
|
772
751
|
|
773
|
-
|
752
|
+
*Juani Villarejo*
|
774
753
|
|
775
|
-
*Lauro Caetano*
|
776
754
|
|
777
|
-
|
755
|
+
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
778
756
|
|
779
|
-
|
780
|
-
record will only be touched if the record was modified. This makes it
|
781
|
-
consistent with timestamp updating on the record itself.
|
757
|
+
* No changes.
|
782
758
|
|
783
|
-
*Brock Trappitt*
|
784
759
|
|
785
|
-
|
786
|
-
table inside a schema.
|
760
|
+
## Rails 6.0.0.beta2 (February 25, 2019) ##
|
787
761
|
|
788
|
-
|
762
|
+
* Fix prepared statements caching to be enabled even when query caching is enabled.
|
789
763
|
|
790
|
-
*
|
764
|
+
*Ryuta Kamizono*
|
791
765
|
|
792
|
-
*
|
793
|
-
in all cases. Fixes inconsistencies when column types are sent outside of
|
794
|
-
`ActiveRecord`, such as for XML Serialization.
|
766
|
+
* Ensure `update_all` series cares about optimistic locking.
|
795
767
|
|
796
|
-
*
|
768
|
+
*Ryuta Kamizono*
|
797
769
|
|
798
|
-
*
|
799
|
-
extension names in PostgreSQL when migrating.
|
770
|
+
* Don't allow `where` with non numeric string matches to 0 values.
|
800
771
|
|
801
|
-
*
|
772
|
+
*Ryuta Kamizono*
|
802
773
|
|
803
|
-
*
|
804
|
-
`references`, now works with any column types.
|
774
|
+
* Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
|
805
775
|
|
806
|
-
|
776
|
+
`destroy_by` allows relation to find all the records matching the condition and perform
|
777
|
+
`destroy_all` on the matched records.
|
807
778
|
|
808
|
-
|
779
|
+
Example:
|
809
780
|
|
810
|
-
|
781
|
+
Person.destroy_by(name: 'David')
|
782
|
+
Person.destroy_by(name: 'David', rating: 4)
|
811
783
|
|
812
|
-
|
813
|
-
|
784
|
+
david = Person.find_by(name: 'David')
|
785
|
+
david.posts.destroy_by(id: [1, 2, 3])
|
814
786
|
|
815
|
-
|
816
|
-
|
787
|
+
`delete_by` allows relation to find all the records matching the condition and perform
|
788
|
+
`delete_all` on the matched records.
|
817
789
|
|
818
|
-
|
790
|
+
Example:
|
819
791
|
|
820
|
-
|
792
|
+
Person.delete_by(name: 'David')
|
793
|
+
Person.delete_by(name: 'David', rating: 4)
|
821
794
|
|
822
|
-
|
823
|
-
|
795
|
+
david = Person.find_by(name: 'David')
|
796
|
+
david.posts.delete_by(id: [1, 2, 3])
|
824
797
|
|
825
|
-
|
798
|
+
*Abhay Nikam*
|
826
799
|
|
827
|
-
|
800
|
+
* Don't allow `where` with invalid value matches to nil values.
|
828
801
|
|
829
|
-
|
830
|
-
association.
|
802
|
+
Fixes #33624.
|
831
803
|
|
832
|
-
|
804
|
+
*Ryuta Kamizono*
|
833
805
|
|
834
|
-
|
806
|
+
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
|
835
807
|
|
836
|
-
*
|
837
|
-
strings in column names as equal.
|
808
|
+
*Ryuta Kamizono*
|
838
809
|
|
839
|
-
|
840
|
-
|
841
|
-
throw a `StatementInvalid` exception.
|
810
|
+
* Deprecate using class level querying methods if the receiver scope
|
811
|
+
regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
|
842
812
|
|
843
|
-
*
|
813
|
+
*Ryuta Kamizono*
|
844
814
|
|
845
|
-
*
|
846
|
-
attributes defined in parent classes.
|
815
|
+
* Allow applications to automatically switch connections.
|
847
816
|
|
848
|
-
|
817
|
+
Adds a middleware and configuration options that can be used in your
|
818
|
+
application to automatically switch between the writing and reading
|
819
|
+
database connections.
|
849
820
|
|
850
|
-
|
821
|
+
`GET` and `HEAD` requests will read from the replica unless there was
|
822
|
+
a write in the last 2 seconds, otherwise they will read from the primary.
|
823
|
+
Non-get requests will always write to the primary. The middleware accepts
|
824
|
+
an argument for a Resolver class and an Operations class where you are able
|
825
|
+
to change how the auto-switcher works to be most beneficial for your
|
826
|
+
application.
|
851
827
|
|
852
|
-
|
828
|
+
To use the middleware in your application you can use the following
|
829
|
+
configuration options:
|
853
830
|
|
854
|
-
|
831
|
+
```
|
832
|
+
config.active_record.database_selector = { delay: 2.seconds }
|
833
|
+
config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
|
834
|
+
config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
|
835
|
+
```
|
855
836
|
|
856
|
-
|
837
|
+
To change the database selection strategy, pass a custom class to the
|
838
|
+
configuration options:
|
857
839
|
|
858
|
-
|
840
|
+
```
|
841
|
+
config.active_record.database_selector = { delay: 10.seconds }
|
842
|
+
config.active_record.database_resolver = MyResolver
|
843
|
+
config.active_record.database_resolver_context = MyResolver::MyCookies
|
844
|
+
```
|
859
845
|
|
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.
|
846
|
+
*Eileen M. Uchitelle*
|
864
847
|
|
865
|
-
|
848
|
+
* MySQL: Support `:size` option to change text and blob size.
|
866
849
|
|
867
|
-
*
|
868
|
-
NaN PostgreSQL values into a native Ruby `Float::INFINITY` and `Float::NAN`
|
850
|
+
*Ryuta Kamizono*
|
869
851
|
|
870
|
-
|
852
|
+
* Make `t.timestamps` with precision by default.
|
871
853
|
|
872
|
-
|
873
|
-
Point.last.value # => 0.0
|
854
|
+
*Ryuta Kamizono*
|
874
855
|
|
875
|
-
After:
|
876
856
|
|
877
|
-
|
878
|
-
Point.last.value # => Infinity
|
857
|
+
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
879
858
|
|
880
|
-
|
859
|
+
* Remove deprecated `#set_state` from the transaction object.
|
881
860
|
|
882
|
-
*
|
861
|
+
*Rafael Mendonça França*
|
883
862
|
|
884
|
-
|
863
|
+
* Remove deprecated `#supports_statement_cache?` from the database adapters.
|
885
864
|
|
886
|
-
*
|
865
|
+
*Rafael Mendonça França*
|
887
866
|
|
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.
|
867
|
+
* Remove deprecated `#insert_fixtures` from the database adapters.
|
892
868
|
|
893
|
-
|
869
|
+
*Rafael Mendonça França*
|
894
870
|
|
895
|
-
|
871
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
|
896
872
|
|
897
|
-
*
|
873
|
+
*Rafael Mendonça França*
|
898
874
|
|
899
|
-
|
900
|
-
size calculation if the collection is not cached or loaded.
|
875
|
+
* Do not allow passing the column name to `sum` when a block is passed.
|
901
876
|
|
902
|
-
|
877
|
+
*Rafael Mendonça França*
|
903
878
|
|
904
|
-
|
879
|
+
* Do not allow passing the column name to `count` when a block is passed.
|
905
880
|
|
906
|
-
*
|
907
|
-
not exist.
|
881
|
+
*Rafael Mendonça França*
|
908
882
|
|
909
|
-
|
883
|
+
* Remove delegation of missing methods in a relation to arel.
|
910
884
|
|
911
|
-
*
|
885
|
+
*Rafael Mendonça França*
|
912
886
|
|
913
|
-
|
914
|
-
using namespaced models.
|
887
|
+
* Remove delegation of missing methods in a relation to private methods of the class.
|
915
888
|
|
916
|
-
*
|
889
|
+
*Rafael Mendonça França*
|
890
|
+
|
891
|
+
* Deprecate `config.active_record.sqlite3.represent_boolean_as_integer`.
|
917
892
|
|
918
|
-
*
|
893
|
+
*Rafael Mendonça França*
|
919
894
|
|
920
|
-
|
921
|
-
In 4.0 series it is delegated to `Array#join`.
|
895
|
+
* Change `SQLite3Adapter` to always represent boolean values as integers.
|
922
896
|
|
923
|
-
*
|
897
|
+
*Rafael Mendonça França*
|
924
898
|
|
925
|
-
*
|
899
|
+
* Remove ability to specify a timestamp name for `#cache_key`.
|
926
900
|
|
927
|
-
|
928
|
-
in that column, the SQL logger would throw an exception when trying
|
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.
|
901
|
+
*Rafael Mendonça França*
|
934
902
|
|
935
|
-
|
903
|
+
* Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
|
936
904
|
|
937
|
-
*
|
938
|
-
in order to validate child associations with the same context.
|
905
|
+
*Rafael Mendonça França*
|
939
906
|
|
940
|
-
|
907
|
+
* Remove deprecated `expand_hash_conditions_for_aggregates`.
|
941
908
|
|
942
|
-
*
|
909
|
+
*Rafael Mendonça França*
|
943
910
|
|
944
|
-
*
|
911
|
+
* Set polymorphic type column to NULL on `dependent: :nullify` strategy.
|
945
912
|
|
946
|
-
|
947
|
-
was ignored and overwritten by strict mode option.
|
913
|
+
On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
|
948
914
|
|
949
|
-
|
915
|
+
*Laerti Papa*
|
950
916
|
|
951
|
-
|
917
|
+
* Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
|
952
918
|
|
953
|
-
*
|
919
|
+
*Gannon McGibbon*
|
954
920
|
|
955
|
-
|
921
|
+
* Add support for endless ranges introduces in Ruby 2.6.
|
956
922
|
|
957
|
-
*
|
923
|
+
*Greg Navis*
|
958
924
|
|
959
|
-
*
|
925
|
+
* Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
|
960
926
|
|
961
|
-
*
|
927
|
+
*Ryuta Kamizono*
|
962
928
|
|
963
|
-
*
|
964
|
-
on Reflections. This causes a problem when rails loads fixtures, because it
|
965
|
-
uses the reflections to set database with fixtures.
|
929
|
+
* MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
|
966
930
|
|
967
|
-
|
931
|
+
Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
|
932
|
+
format for InnoDB tables. The default setting is `DYNAMIC`.
|
933
|
+
The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
|
968
934
|
|
969
|
-
*
|
935
|
+
*Ryuta Kamizono*
|
970
936
|
|
971
|
-
*
|
972
|
-
Additionally display a warning message to make the user aware.
|
937
|
+
* Fix join table column quoting with SQLite.
|
973
938
|
|
974
|
-
*
|
939
|
+
*Gannon McGibbon*
|
975
940
|
|
976
|
-
*
|
977
|
-
different spellings of timestamps are treated the same.
|
941
|
+
* Allow disabling scopes generated by `ActiveRecord.enum`.
|
978
942
|
|
979
|
-
|
943
|
+
*Alfred Dominic*
|
980
944
|
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
# => also :datetime (previously would be :timestamp)
|
945
|
+
* Ensure that `delete_all` on collection proxy returns affected count.
|
946
|
+
|
947
|
+
*Ryuta Kamizono*
|
985
948
|
|
986
|
-
|
949
|
+
* Reset scope after delete on collection association to clear stale offsets of removed records.
|
987
950
|
|
988
|
-
*
|
951
|
+
*Gannon McGibbon*
|
989
952
|
|
990
|
-
*
|
953
|
+
* Add the ability to prevent writes to a database for the duration of a block.
|
991
954
|
|
992
|
-
|
955
|
+
Allows the application to prevent writes to a database. This can be useful when
|
956
|
+
you're building out multiple databases and want to make sure you're not sending
|
957
|
+
writes when you want a read.
|
993
958
|
|
994
|
-
|
959
|
+
If `while_preventing_writes` is called and the query is considered a write
|
960
|
+
query the database will raise an exception regardless of whether the database
|
961
|
+
user is able to write.
|
995
962
|
|
996
|
-
|
963
|
+
This is not meant to be a catch-all for write queries but rather a way to enforce
|
964
|
+
read-only queries without opening a second connection. One purpose of this is to
|
965
|
+
catch accidental writes, not all writes.
|
997
966
|
|
998
|
-
|
967
|
+
*Eileen M. Uchitelle*
|
999
968
|
|
1000
|
-
|
969
|
+
* Allow aliased attributes to be used in `#update_columns` and `#update`.
|
1001
970
|
|
1002
|
-
*
|
1003
|
-
a scoped `has_many`.
|
971
|
+
*Gannon McGibbon*
|
1004
972
|
|
1005
|
-
|
1006
|
-
`has_many :through` uses this association, then the scope adjustment is
|
1007
|
-
unexpectedly neglected.
|
973
|
+
* Allow spaces in postgres table names.
|
1008
974
|
|
1009
|
-
Fixes
|
975
|
+
Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
|
1010
976
|
|
1011
|
-
*
|
977
|
+
*Gannon McGibbon*
|
1012
978
|
|
1013
|
-
*
|
979
|
+
* Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
|
1014
980
|
|
1015
|
-
|
981
|
+
PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
|
982
|
+
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
1016
983
|
|
1017
|
-
|
984
|
+
```ruby
|
985
|
+
class DeveloperName < ActiveRecord::Type::String
|
986
|
+
def deserialize(value)
|
987
|
+
"Developer: #{value}"
|
988
|
+
end
|
989
|
+
end
|
1018
990
|
|
1019
|
-
|
991
|
+
class AttributedDeveloper < ActiveRecord::Base
|
992
|
+
self.table_name = "developers"
|
1020
993
|
|
1021
|
-
|
994
|
+
attribute :name, DeveloperName.new
|
1022
995
|
|
1023
|
-
|
996
|
+
self.ignored_columns += ["name"]
|
997
|
+
end
|
1024
998
|
|
1025
|
-
|
999
|
+
developer = AttributedDeveloper.create
|
1000
|
+
developer.update_column :name, "name"
|
1026
1001
|
|
1027
|
-
|
1002
|
+
loaded_developer = AttributedDeveloper.where(id: developer.id).select("*").first
|
1003
|
+
puts loaded_developer.name # should be "Developer: name" but it's just "name"
|
1004
|
+
```
|
1028
1005
|
|
1029
|
-
*
|
1030
|
-
|
1006
|
+
*Dmitry Tsepelev*
|
1007
|
+
|
1008
|
+
* Make the implicit order column configurable.
|
1009
|
+
|
1010
|
+
When calling ordered finder methods such as `first` or `last` without an
|
1011
|
+
explicit order clause, ActiveRecord sorts records by primary key. This can
|
1012
|
+
result in unpredictable and surprising behaviour when the primary key is
|
1013
|
+
not an auto-incrementing integer, for example when it's a UUID. This change
|
1014
|
+
makes it possible to override the column used for implicit ordering such
|
1015
|
+
that `first` and `last` will return more predictable results.
|
1031
1016
|
|
1032
1017
|
Example:
|
1033
1018
|
|
1034
|
-
class
|
1035
|
-
|
1036
|
-
where("title LIKE ?", sanitize_sql_like(term))
|
1037
|
-
end
|
1019
|
+
class Project < ActiveRecord::Base
|
1020
|
+
self.implicit_order_column = "created_at"
|
1038
1021
|
end
|
1039
1022
|
|
1040
|
-
|
1041
|
-
|
1023
|
+
*Tekin Suleyman*
|
1024
|
+
|
1025
|
+
* Bump minimum PostgreSQL version to 9.3.
|
1026
|
+
|
1027
|
+
*Yasuo Honda*
|
1028
|
+
|
1029
|
+
* Values of enum are frozen, raising an error when attempting to modify them.
|
1042
1030
|
|
1043
|
-
*
|
1031
|
+
*Emmanuel Byrd*
|
1044
1032
|
|
1045
|
-
*
|
1033
|
+
* Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
|
1046
1034
|
|
1047
|
-
|
1035
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
|
1048
1036
|
|
1049
|
-
|
1037
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
|
1050
1038
|
|
1051
|
-
|
1039
|
+
Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
|
1052
1040
|
|
1053
1041
|
Example:
|
1054
1042
|
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1043
|
+
```
|
1044
|
+
class MySubclassedError < ActiveRecord::StatementInvalid
|
1045
|
+
def initialize(message, sql:, binds:)
|
1046
|
+
super(message, sql: sql, binds: binds)
|
1047
|
+
end
|
1048
|
+
end
|
1049
|
+
```
|
1059
1050
|
|
1060
|
-
|
1051
|
+
*Gannon McGibbon*
|
1061
1052
|
|
1062
|
-
|
1053
|
+
* Add an `:if_not_exists` option to `create_table`.
|
1063
1054
|
|
1064
|
-
|
1065
|
-
generates an SQL statement containing each id of the collection:
|
1055
|
+
Example:
|
1066
1056
|
|
1067
|
-
|
1057
|
+
create_table :posts, if_not_exists: true do |t|
|
1058
|
+
t.string :title
|
1059
|
+
end
|
1068
1060
|
|
1069
|
-
|
1070
|
-
AND `model`.`id` IN (1, 2, 3...)
|
1061
|
+
That would execute:
|
1071
1062
|
|
1072
|
-
|
1063
|
+
CREATE TABLE IF NOT EXISTS posts (
|
1064
|
+
...
|
1065
|
+
)
|
1073
1066
|
|
1074
|
-
|
1067
|
+
If the table already exists, `if_not_exists: false` (the default) raises an
|
1068
|
+
exception whereas `if_not_exists: true` does nothing.
|
1075
1069
|
|
1076
|
-
*
|
1070
|
+
*fatkodima*, *Stefan Kanev*
|
1077
1071
|
|
1078
|
-
*
|
1079
|
-
with `select`.
|
1072
|
+
* Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
|
1080
1073
|
|
1081
|
-
|
1074
|
+
*Christophe Maximin*
|
1082
1075
|
|
1083
|
-
|
1076
|
+
* Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
|
1084
1077
|
|
1085
|
-
*
|
1078
|
+
*Gannon McGibbon*
|
1086
1079
|
|
1087
|
-
|
1080
|
+
* `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
|
1081
|
+
if the attribute does not exist.
|
1088
1082
|
|
1089
|
-
*
|
1083
|
+
*Sean Griffin*
|
1090
1084
|
|
1091
|
-
*
|
1092
|
-
unknown OIDs.
|
1085
|
+
* Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
|
1093
1086
|
|
1094
|
-
|
1087
|
+
````
|
1088
|
+
User.connected_to(database: { writing: "postgres://foo" }) do
|
1089
|
+
User.create!(name: "Gannon")
|
1090
|
+
end
|
1095
1091
|
|
1096
|
-
|
1092
|
+
config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
|
1093
|
+
User.connected_to(database: { reading: config }) do
|
1094
|
+
User.count
|
1095
|
+
end
|
1096
|
+
````
|
1097
1097
|
|
1098
|
-
*
|
1098
|
+
*Gannon McGibbon*
|
1099
1099
|
|
1100
|
-
|
1100
|
+
* Support default expression for MySQL.
|
1101
1101
|
|
1102
|
-
|
1102
|
+
MySQL 8.0.13 and higher supports default value to be a function or expression.
|
1103
1103
|
|
1104
|
-
|
1104
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-table.html
|
1105
1105
|
|
1106
|
-
|
1106
|
+
*Ryuta Kamizono*
|
1107
1107
|
|
1108
|
-
|
1108
|
+
* Support expression indexes for MySQL.
|
1109
1109
|
|
1110
|
-
|
1111
|
-
|
1110
|
+
MySQL 8.0.13 and higher supports functional key parts that index
|
1111
|
+
expression values rather than column or column prefix values.
|
1112
1112
|
|
1113
|
-
|
1113
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-index.html
|
1114
|
+
|
1115
|
+
*Ryuta Kamizono*
|
1114
1116
|
|
1115
|
-
|
1117
|
+
* Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
|
1116
1118
|
|
1117
|
-
|
1119
|
+
Fixes #33056.
|
1118
1120
|
|
1119
|
-
|
1121
|
+
*Federico Martinez*
|
1120
1122
|
|
1121
|
-
|
1123
|
+
* Add basic API for connection switching to support multiple databases.
|
1122
1124
|
|
1123
|
-
|
1125
|
+
1) Adds a `connects_to` method for models to connect to multiple databases. Example:
|
1124
1126
|
|
1125
|
-
|
1127
|
+
```
|
1128
|
+
class AnimalsModel < ApplicationRecord
|
1129
|
+
self.abstract_class = true
|
1126
1130
|
|
1127
|
-
|
1131
|
+
connects_to database: { writing: :animals_primary, reading: :animals_replica }
|
1132
|
+
end
|
1128
1133
|
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1134
|
+
class Dog < AnimalsModel
|
1135
|
+
# connected to both the animals_primary db for writing and the animals_replica for reading
|
1136
|
+
end
|
1137
|
+
```
|
1133
1138
|
|
1134
|
-
|
1139
|
+
2) Adds a `connected_to` block method for switching connection roles or connecting to
|
1140
|
+
a database that the model didn't connect to. Connecting to the database in this block is
|
1141
|
+
useful when you have another defined connection, for example `slow_replica` that you don't
|
1142
|
+
want to connect to by default but need in the console, or a specific code block.
|
1135
1143
|
|
1136
|
-
|
1144
|
+
```
|
1145
|
+
ActiveRecord::Base.connected_to(role: :reading) do
|
1146
|
+
Dog.first # finds dog from replica connected to AnimalsBase
|
1147
|
+
Book.first # doesn't have a reading connection, will raise an error
|
1148
|
+
end
|
1149
|
+
```
|
1137
1150
|
|
1138
|
-
|
1151
|
+
```
|
1152
|
+
ActiveRecord::Base.connected_to(database: :slow_replica) do
|
1153
|
+
SlowReplicaModel.first # if the db config has a slow_replica configuration this will be used to do the lookup, otherwise this will throw an exception
|
1154
|
+
end
|
1155
|
+
```
|
1139
1156
|
|
1140
|
-
|
1157
|
+
*Eileen M. Uchitelle*
|
1141
1158
|
|
1142
|
-
|
1159
|
+
* Enum raises on invalid definition values
|
1143
1160
|
|
1144
|
-
|
1161
|
+
When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
|
1162
|
+
commit checks that only valid definition values are provided, those can
|
1163
|
+
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
1164
|
+
raises an `ArgumentError`.
|
1145
1165
|
|
1146
|
-
|
1166
|
+
Fixes #33961
|
1147
1167
|
|
1148
|
-
|
1168
|
+
*Alberto Almagro*
|
1149
1169
|
|
1150
|
-
|
1170
|
+
* Reloading associations now clears the Query Cache like `Persistence#reload` does.
|
1151
1171
|
|
1152
|
-
|
1153
|
-
|
1172
|
+
```
|
1173
|
+
class Post < ActiveRecord::Base
|
1174
|
+
has_one :category
|
1175
|
+
belongs_to :author
|
1176
|
+
has_many :comments
|
1177
|
+
end
|
1154
1178
|
|
1155
|
-
|
1156
|
-
|
1179
|
+
# Each of the following will now clear the query cache.
|
1180
|
+
post.reload_category
|
1181
|
+
post.reload_author
|
1182
|
+
post.comments.reload
|
1183
|
+
```
|
1157
1184
|
|
1158
|
-
*
|
1185
|
+
*Christophe Maximin*
|
1159
1186
|
|
1160
|
-
*
|
1187
|
+
* Added `index` option for `change_table` migration helpers.
|
1188
|
+
With this change you can create indexes while adding new
|
1189
|
+
columns into the existing tables.
|
1161
1190
|
|
1162
1191
|
Example:
|
1163
1192
|
|
1164
|
-
|
1193
|
+
change_table(:languages) do |t|
|
1194
|
+
t.string :country_code, index: true
|
1195
|
+
end
|
1165
1196
|
|
1166
|
-
*
|
1197
|
+
*Mehmet Emin İNAÇ*
|
1167
1198
|
|
1168
|
-
*
|
1199
|
+
* Fix `transaction` reverting for migrations.
|
1169
1200
|
|
1170
|
-
|
1201
|
+
Before: Commands inside a `transaction` in a reverted migration ran uninverted.
|
1202
|
+
Now: This change fixes that by reverting commands inside `transaction` block.
|
1171
1203
|
|
1172
|
-
*
|
1204
|
+
*fatkodima*, *David Verhasselt*
|
1173
1205
|
|
1174
|
-
|
1206
|
+
* Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
|
1175
1207
|
|
1176
|
-
*
|
1177
|
-
The column types stay the same except for enum columns. They no longer have
|
1178
|
-
`nil` as type but `enum`.
|
1208
|
+
*Gannon McGibbon*, *Max Albrecht*
|
1179
1209
|
|
1180
|
-
|
1210
|
+
* Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
|
1181
1211
|
|
1182
|
-
*
|
1212
|
+
*Gannon McGibbon*
|
1183
1213
|
|
1184
|
-
*
|
1185
|
-
column.
|
1214
|
+
* Don't update counter cache unless the record is actually saved.
|
1186
1215
|
|
1187
|
-
Fixes #
|
1216
|
+
Fixes #31493, #33113, #33117.
|
1188
1217
|
|
1189
|
-
*
|
1218
|
+
*Ryuta Kamizono*
|
1190
1219
|
|
1191
|
-
*
|
1192
|
-
custom primary key that did not save due to validation error.
|
1220
|
+
* Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
|
1193
1221
|
|
1194
|
-
|
1222
|
+
*Gannon McGibbon*, *Kevin Cheng*
|
1195
1223
|
|
1196
|
-
|
1224
|
+
* SQLite3 adapter supports expression indexes.
|
1197
1225
|
|
1198
|
-
|
1226
|
+
```
|
1227
|
+
create_table :users do |t|
|
1228
|
+
t.string :email
|
1229
|
+
end
|
1199
1230
|
|
1200
|
-
|
1231
|
+
add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
|
1232
|
+
```
|
1201
1233
|
|
1202
|
-
*
|
1234
|
+
*Gray Kemmey*
|
1203
1235
|
|
1204
|
-
*
|
1236
|
+
* Allow subclasses to redefine autosave callbacks for associated records.
|
1205
1237
|
|
1206
|
-
|
1207
|
-
would commit the transaction.
|
1238
|
+
Fixes #33305.
|
1208
1239
|
|
1209
|
-
|
1210
|
-
required.
|
1240
|
+
*Andrey Subbota*
|
1211
1241
|
|
1212
|
-
|
1242
|
+
* Bump minimum MySQL version to 5.5.8.
|
1213
1243
|
|
1214
|
-
|
1215
|
-
t.index :zip
|
1216
|
-
end
|
1217
|
-
# => CREATE TEMPORARY TABLE temp (INDEX (zip)) AS SELECT id, name, zip FROM a_really_complicated_query
|
1244
|
+
*Yasuo Honda*
|
1218
1245
|
|
1219
|
-
|
1246
|
+
* Use MySQL utf8mb4 character set by default.
|
1220
1247
|
|
1221
|
-
|
1222
|
-
`
|
1248
|
+
`utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
|
1249
|
+
The previous default 3-Byte encoding character set `utf8` is not enough to support them.
|
1223
1250
|
|
1224
|
-
|
1251
|
+
*Yasuo Honda*
|
1225
1252
|
|
1226
|
-
|
1253
|
+
* Fix duplicated record creation when using nested attributes with `create_with`.
|
1227
1254
|
|
1228
|
-
*
|
1255
|
+
*Darwin Wu*
|
1229
1256
|
|
1230
|
-
|
1257
|
+
* Configuration item `config.filter_parameters` could also filter out
|
1258
|
+
sensitive values of database columns when calling `#inspect`.
|
1259
|
+
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
1260
|
+
specify sensitive attributes to specific model.
|
1231
1261
|
|
1232
|
-
|
1233
|
-
|
1262
|
+
```
|
1263
|
+
Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
|
1264
|
+
Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
|
1265
|
+
SecureAccount.filter_attributes += [:name]
|
1266
|
+
SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
|
1267
|
+
```
|
1234
1268
|
|
1235
|
-
*
|
1269
|
+
*Zhang Kang*, *Yoshiyuki Kinjo*
|
1236
1270
|
|
1237
|
-
* `
|
1238
|
-
|
1271
|
+
* Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
|
1272
|
+
`indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
|
1273
|
+
and `joins_per_query` methods in `DatabaseLimits`.
|
1239
1274
|
|
1240
|
-
|
1275
|
+
*Ryuta Kamizono*
|
1241
1276
|
|
1242
|
-
|
1277
|
+
* `ActiveRecord::Base.configurations` now returns an object.
|
1243
1278
|
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
the
|
1279
|
+
`ActiveRecord::Base.configurations` used to return a hash, but this
|
1280
|
+
is an inflexible data model. In order to improve multiple-database
|
1281
|
+
handling in Rails, we've changed this to return an object. Some methods
|
1282
|
+
are provided to make the object behave hash-like in order to ease the
|
1283
|
+
transition process. Since most applications don't manipulate the hash
|
1284
|
+
we've decided to add backwards-compatible functionality that will throw
|
1285
|
+
a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
|
1286
|
+
will use the new version internally and externally.
|
1249
1287
|
|
1250
|
-
|
1288
|
+
For example, the following `database.yml`:
|
1251
1289
|
|
1252
|
-
|
1253
|
-
|
1290
|
+
```
|
1291
|
+
development:
|
1292
|
+
adapter: sqlite3
|
1293
|
+
database: db/development.sqlite3
|
1294
|
+
```
|
1254
1295
|
|
1255
|
-
|
1296
|
+
Used to become a hash:
|
1256
1297
|
|
1257
|
-
|
1298
|
+
```
|
1299
|
+
{ "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
|
1300
|
+
```
|
1258
1301
|
|
1259
|
-
|
1302
|
+
Is now converted into the following object:
|
1260
1303
|
|
1261
|
-
|
1304
|
+
```
|
1305
|
+
#<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
|
1306
|
+
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
1307
|
+
@spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
|
1308
|
+
]
|
1309
|
+
```
|
1262
1310
|
|
1263
|
-
|
1311
|
+
Iterating over the database configurations has also changed. Instead of
|
1312
|
+
calling hash methods on the `configurations` hash directly, a new method `configs_for` has
|
1313
|
+
been provided that allows you to select the correct configuration. `env_name` and
|
1314
|
+
`spec_name` arguments are optional. For example, these return an array of
|
1315
|
+
database config objects for the requested environment and a single database config object
|
1316
|
+
will be returned for the requested environment and specification name respectively.
|
1264
1317
|
|
1265
|
-
|
1318
|
+
```
|
1319
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development")
|
1320
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
|
1321
|
+
```
|
1266
1322
|
|
1267
|
-
|
1268
|
-
email: $LABEL@email.com
|
1323
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*
|
1269
1324
|
|
1270
|
-
|
1325
|
+
* Add database configuration to disable advisory locks.
|
1271
1326
|
|
1272
|
-
|
1327
|
+
```
|
1328
|
+
production:
|
1329
|
+
adapter: postgresql
|
1330
|
+
advisory_locks: false
|
1331
|
+
```
|
1273
1332
|
|
1274
|
-
*
|
1333
|
+
*Guo Xiang*
|
1275
1334
|
|
1276
|
-
|
1335
|
+
* SQLite3 adapter `alter_table` method restores foreign keys.
|
1277
1336
|
|
1278
|
-
*
|
1337
|
+
*Yasuo Honda*
|
1279
1338
|
|
1280
|
-
*
|
1281
|
-
Call `.id` on the object first.
|
1339
|
+
* Allow `:to_table` option to `invert_remove_foreign_key`.
|
1282
1340
|
|
1283
|
-
|
1341
|
+
Example:
|
1284
1342
|
|
1285
|
-
|
1286
|
-
has a case insensitive collation.
|
1343
|
+
remove_foreign_key :accounts, to_table: :owners
|
1287
1344
|
|
1288
|
-
*
|
1345
|
+
*Nikolay Epifanov*, *Rich Chen*
|
1346
|
+
|
1347
|
+
* Add environment & load_config dependency to `bin/rake db:seed` to enable
|
1348
|
+
seed load in environments without Rails and custom DB configuration
|
1349
|
+
|
1350
|
+
*Tobias Bielohlawek*
|
1289
1351
|
|
1290
|
-
*
|
1352
|
+
* Fix default value for mysql time types with specified precision.
|
1291
1353
|
|
1292
|
-
*
|
1354
|
+
*Nikolay Kondratyev*
|
1293
1355
|
|
1294
|
-
*
|
1295
|
-
`where` values without needing to wrap in UPPER/LOWER sql functions.
|
1356
|
+
* Fix `touch` option to behave consistently with `Persistence#touch` method.
|
1296
1357
|
|
1297
|
-
*
|
1358
|
+
*Ryuta Kamizono*
|
1298
1359
|
|
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.
|
1360
|
+
* Migrations raise when duplicate column definition.
|
1302
1361
|
|
1303
|
-
|
1362
|
+
Fixes #33024.
|
1304
1363
|
|
1305
|
-
*
|
1364
|
+
*Federico Martinez*
|
1306
1365
|
|
1307
|
-
|
1366
|
+
* Bump minimum SQLite version to 3.8
|
1308
1367
|
|
1309
|
-
|
1368
|
+
*Yasuo Honda*
|
1310
1369
|
|
1311
|
-
|
1370
|
+
* Fix parent record should not get saved with duplicate children records.
|
1312
1371
|
|
1313
|
-
|
1314
|
-
warnings on enum columns.
|
1372
|
+
Fixes #32940.
|
1315
1373
|
|
1316
|
-
*
|
1374
|
+
*Santosh Wadghule*
|
1317
1375
|
|
1318
|
-
*
|
1319
|
-
joins are involved.
|
1376
|
+
* Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
|
1320
1377
|
|
1321
|
-
|
1378
|
+
*Brian Durand*
|
1322
1379
|
|
1323
|
-
|
1380
|
+
* Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
|
1381
|
+
use loaded association ids if present.
|
1324
1382
|
|
1325
|
-
*
|
1326
|
-
any enum attribute is always evaluated as 0 during uniqueness validation.
|
1383
|
+
*Graham Turner*
|
1327
1384
|
|
1328
|
-
|
1385
|
+
* Add support to preload associations of polymorphic associations when not all the records have the requested associations.
|
1329
1386
|
|
1330
|
-
*
|
1387
|
+
*Dana Sherson*
|
1331
1388
|
|
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.
|
1389
|
+
* Add `touch_all` method to `ActiveRecord::Relation`.
|
1337
1390
|
|
1338
|
-
|
1391
|
+
Example:
|
1339
1392
|
|
1340
|
-
|
1341
|
-
private method defined on its ancestors.
|
1393
|
+
Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
|
1342
1394
|
|
1343
|
-
|
1395
|
+
*fatkodima*, *duggiefresh*
|
1344
1396
|
|
1345
|
-
|
1397
|
+
* Add `ActiveRecord::Base.base_class?` predicate.
|
1346
1398
|
|
1347
|
-
*
|
1399
|
+
*Bogdan Gusiev*
|
1348
1400
|
|
1349
|
-
|
1401
|
+
* Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
|
1402
|
+
|
1403
|
+
*Tan Huynh*, *Yukio Mizuta*
|
1404
|
+
|
1405
|
+
* Rails 6 requires Ruby 2.5.0 or newer.
|
1406
|
+
|
1407
|
+
*Jeremy Daer*, *Kasper Timm Hansen*
|
1350
1408
|
|
1351
|
-
|
1352
|
-
book.save!
|
1353
|
-
book.title # => "12345"
|
1409
|
+
* Deprecate `update_attributes`/`!` in favor of `update`/`!`.
|
1354
1410
|
|
1355
|
-
*
|
1411
|
+
*Eddie Lebow*
|
1356
1412
|
|
1357
|
-
*
|
1358
|
-
|
1359
|
-
possible because the Ruby range does not support excluded beginnings.
|
1413
|
+
* Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
|
1414
|
+
`ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
|
1360
1415
|
|
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.
|
1416
|
+
*DHH*
|
1365
1417
|
|
1366
|
-
|
1418
|
+
* Add `Relation#pick` as short-hand for single-value plucks.
|
1367
1419
|
|
1368
|
-
*
|
1420
|
+
*DHH*
|
1369
1421
|
|
1370
|
-
*Yves Senn*
|
1371
1422
|
|
1372
|
-
Please check [
|
1423
|
+
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.
|