activerecord 5.2.6 → 6.1.3.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activerecord might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1038 -571
- data/MIT-LICENSE +3 -1
- data/README.rdoc +7 -5
- data/examples/performance.rb +1 -1
- data/lib/active_record.rb +13 -12
- data/lib/active_record/aggregations.rb +9 -8
- data/lib/active_record/association_relation.rb +30 -10
- data/lib/active_record/associations.rb +137 -25
- data/lib/active_record/associations/alias_tracker.rb +19 -16
- data/lib/active_record/associations/association.rb +95 -42
- data/lib/active_record/associations/association_scope.rb +23 -21
- data/lib/active_record/associations/belongs_to_association.rb +54 -46
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +7 -6
- data/lib/active_record/associations/builder/association.rb +45 -22
- data/lib/active_record/associations/builder/belongs_to.rb +29 -59
- data/lib/active_record/associations/builder/collection_association.rb +8 -17
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -41
- data/lib/active_record/associations/builder/has_many.rb +8 -2
- data/lib/active_record/associations/builder/has_one.rb +33 -2
- data/lib/active_record/associations/builder/singular_association.rb +3 -1
- data/lib/active_record/associations/collection_association.rb +31 -29
- data/lib/active_record/associations/collection_proxy.rb +25 -21
- data/lib/active_record/associations/foreign_association.rb +20 -0
- data/lib/active_record/associations/has_many_association.rb +26 -13
- data/lib/active_record/associations/has_many_through_association.rb +24 -18
- data/lib/active_record/associations/has_one_association.rb +43 -31
- data/lib/active_record/associations/has_one_through_association.rb +5 -5
- data/lib/active_record/associations/join_dependency.rb +91 -60
- data/lib/active_record/associations/join_dependency/join_association.rb +44 -22
- data/lib/active_record/associations/join_dependency/join_part.rb +5 -5
- data/lib/active_record/associations/preloader.rb +47 -34
- data/lib/active_record/associations/preloader/association.rb +71 -43
- data/lib/active_record/associations/preloader/through_association.rb +49 -40
- data/lib/active_record/associations/singular_association.rb +3 -17
- data/lib/active_record/associations/through_association.rb +1 -1
- data/lib/active_record/attribute_assignment.rb +17 -19
- data/lib/active_record/attribute_methods.rb +81 -143
- data/lib/active_record/attribute_methods/before_type_cast.rb +13 -7
- data/lib/active_record/attribute_methods/dirty.rb +101 -40
- data/lib/active_record/attribute_methods/primary_key.rb +20 -25
- data/lib/active_record/attribute_methods/query.rb +4 -8
- data/lib/active_record/attribute_methods/read.rb +14 -56
- data/lib/active_record/attribute_methods/serialization.rb +12 -7
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +12 -15
- data/lib/active_record/attribute_methods/write.rb +18 -34
- data/lib/active_record/attributes.rb +46 -9
- data/lib/active_record/autosave_association.rb +57 -42
- data/lib/active_record/base.rb +4 -17
- data/lib/active_record/callbacks.rb +158 -43
- data/lib/active_record/coders/yaml_column.rb +1 -2
- data/lib/active_record/connection_adapters.rb +50 -0
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +272 -130
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +7 -36
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +167 -146
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +18 -14
- data/lib/active_record/connection_adapters/abstract/quoting.rb +98 -47
- data/lib/active_record/connection_adapters/abstract/savepoints.rb +3 -3
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +153 -110
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +207 -90
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +2 -4
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +385 -144
- data/lib/active_record/connection_adapters/abstract/transaction.rb +155 -68
- data/lib/active_record/connection_adapters/abstract_adapter.rb +228 -98
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +243 -275
- data/lib/active_record/connection_adapters/column.rb +30 -12
- data/lib/active_record/connection_adapters/deduplicable.rb +29 -0
- data/lib/active_record/connection_adapters/legacy_pool_manager.rb +31 -0
- data/lib/active_record/connection_adapters/mysql/column.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +86 -32
- data/lib/active_record/connection_adapters/mysql/explain_pretty_printer.rb +1 -2
- data/lib/active_record/connection_adapters/mysql/quoting.rb +59 -7
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +34 -10
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +48 -32
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +18 -7
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +139 -19
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +14 -9
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +53 -18
- data/lib/active_record/connection_adapters/pool_config.rb +73 -0
- data/lib/active_record/connection_adapters/pool_manager.rb +43 -0
- data/lib/active_record/connection_adapters/postgresql/column.rb +37 -28
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +38 -54
- data/lib/active_record/connection_adapters/postgresql/oid.rb +2 -0
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
- data/lib/active_record/connection_adapters/postgresql/oid/cidr.rb +3 -5
- data/lib/active_record/connection_adapters/postgresql/oid/date.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/date_time.rb +10 -2
- data/lib/active_record/connection_adapters/postgresql/oid/enum.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/oid/interval.rb +49 -0
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +3 -4
- data/lib/active_record/connection_adapters/postgresql/oid/macaddr.rb +25 -0
- data/lib/active_record/connection_adapters/postgresql/oid/oid.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +3 -4
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +25 -7
- data/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +9 -7
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +15 -3
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +47 -10
- data/lib/active_record/connection_adapters/postgresql/referential_integrity.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +19 -4
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +107 -91
- data/lib/active_record/connection_adapters/postgresql/schema_dumper.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +120 -100
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +31 -26
- data/lib/active_record/connection_adapters/postgresql/utils.rb +0 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +224 -120
- data/lib/active_record/connection_adapters/schema_cache.rb +127 -21
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +19 -6
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +144 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +42 -7
- data/lib/active_record/connection_adapters/sqlite3/schema_creation.rb +5 -1
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +77 -13
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +174 -186
- data/lib/active_record/connection_adapters/statement_pool.rb +0 -1
- data/lib/active_record/connection_handling.rb +293 -33
- data/lib/active_record/core.rb +323 -97
- data/lib/active_record/counter_cache.rb +8 -30
- data/lib/active_record/database_configurations.rb +272 -0
- data/lib/active_record/database_configurations/connection_url_resolver.rb +98 -0
- data/lib/active_record/database_configurations/database_config.rb +80 -0
- data/lib/active_record/database_configurations/hash_config.rb +96 -0
- data/lib/active_record/database_configurations/url_config.rb +53 -0
- data/lib/active_record/delegated_type.rb +209 -0
- data/lib/active_record/destroy_association_async_job.rb +36 -0
- data/lib/active_record/dynamic_matchers.rb +3 -4
- data/lib/active_record/enum.rb +111 -37
- data/lib/active_record/errors.rb +62 -19
- data/lib/active_record/explain.rb +10 -6
- data/lib/active_record/explain_subscriber.rb +1 -1
- data/lib/active_record/fixture_set/file.rb +10 -17
- data/lib/active_record/fixture_set/model_metadata.rb +32 -0
- data/lib/active_record/fixture_set/render_context.rb +17 -0
- data/lib/active_record/fixture_set/table_row.rb +152 -0
- data/lib/active_record/fixture_set/table_rows.rb +46 -0
- data/lib/active_record/fixtures.rb +200 -481
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +53 -24
- data/lib/active_record/insert_all.rb +208 -0
- data/lib/active_record/integration.rb +67 -17
- data/lib/active_record/internal_metadata.rb +26 -9
- data/lib/active_record/legacy_yaml_adapter.rb +7 -3
- data/lib/active_record/locking/optimistic.rb +37 -23
- data/lib/active_record/locking/pessimistic.rb +9 -5
- data/lib/active_record/log_subscriber.rb +35 -35
- data/lib/active_record/middleware/database_selector.rb +77 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +92 -0
- data/lib/active_record/middleware/database_selector/resolver/session.rb +48 -0
- data/lib/active_record/migration.rb +206 -157
- data/lib/active_record/migration/command_recorder.rb +96 -44
- data/lib/active_record/migration/compatibility.rb +142 -64
- data/lib/active_record/migration/join_table.rb +0 -1
- data/lib/active_record/model_schema.rb +148 -22
- data/lib/active_record/nested_attributes.rb +4 -7
- data/lib/active_record/no_touching.rb +8 -1
- data/lib/active_record/null_relation.rb +0 -1
- data/lib/active_record/persistence.rb +267 -59
- data/lib/active_record/query_cache.rb +21 -4
- data/lib/active_record/querying.rb +40 -23
- data/lib/active_record/railtie.rb +115 -58
- data/lib/active_record/railties/console_sandbox.rb +2 -4
- data/lib/active_record/railties/controller_runtime.rb +30 -35
- data/lib/active_record/railties/databases.rake +408 -78
- data/lib/active_record/readonly_attributes.rb +4 -0
- data/lib/active_record/reflection.rb +109 -93
- data/lib/active_record/relation.rb +374 -104
- data/lib/active_record/relation/batches.rb +44 -35
- data/lib/active_record/relation/batches/batch_enumerator.rb +25 -9
- data/lib/active_record/relation/calculations.rb +153 -90
- data/lib/active_record/relation/delegation.rb +35 -50
- data/lib/active_record/relation/finder_methods.rb +64 -39
- data/lib/active_record/relation/from_clause.rb +5 -1
- data/lib/active_record/relation/merger.rb +32 -40
- data/lib/active_record/relation/predicate_builder.rb +62 -45
- data/lib/active_record/relation/predicate_builder/array_handler.rb +13 -13
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +5 -9
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +11 -10
- data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
- data/lib/active_record/relation/predicate_builder/relation_handler.rb +1 -1
- data/lib/active_record/relation/query_attribute.rb +13 -8
- data/lib/active_record/relation/query_methods.rb +475 -186
- data/lib/active_record/relation/record_fetch_warning.rb +3 -3
- data/lib/active_record/relation/spawn_methods.rb +9 -9
- data/lib/active_record/relation/where_clause.rb +111 -61
- data/lib/active_record/result.rb +64 -38
- data/lib/active_record/runtime_registry.rb +2 -2
- data/lib/active_record/sanitization.rb +22 -41
- data/lib/active_record/schema.rb +2 -11
- data/lib/active_record/schema_dumper.rb +54 -9
- data/lib/active_record/schema_migration.rb +7 -9
- data/lib/active_record/scoping.rb +8 -9
- data/lib/active_record/scoping/default.rb +4 -6
- data/lib/active_record/scoping/named.rb +17 -24
- data/lib/active_record/secure_token.rb +16 -8
- data/lib/active_record/serialization.rb +5 -3
- data/lib/active_record/signed_id.rb +116 -0
- data/lib/active_record/statement_cache.rb +49 -6
- data/lib/active_record/store.rb +88 -9
- data/lib/active_record/suppressor.rb +2 -2
- data/lib/active_record/table_metadata.rb +42 -43
- data/lib/active_record/tasks/database_tasks.rb +277 -81
- data/lib/active_record/tasks/mysql_database_tasks.rb +37 -39
- data/lib/active_record/tasks/postgresql_database_tasks.rb +27 -32
- data/lib/active_record/tasks/sqlite_database_tasks.rb +14 -17
- data/lib/active_record/test_databases.rb +24 -0
- data/lib/active_record/test_fixtures.rb +246 -0
- data/lib/active_record/timestamp.rb +43 -32
- data/lib/active_record/touch_later.rb +23 -22
- data/lib/active_record/transactions.rb +62 -118
- data/lib/active_record/translation.rb +1 -1
- data/lib/active_record/type.rb +10 -5
- data/lib/active_record/type/adapter_specific_registry.rb +3 -13
- data/lib/active_record/type/hash_lookup_type_map.rb +0 -1
- data/lib/active_record/type/serialized.rb +6 -3
- data/lib/active_record/type/time.rb +10 -0
- data/lib/active_record/type/type_map.rb +0 -1
- data/lib/active_record/type/unsigned_integer.rb +0 -1
- data/lib/active_record/type_caster/connection.rb +15 -15
- data/lib/active_record/type_caster/map.rb +8 -8
- data/lib/active_record/validations.rb +4 -3
- data/lib/active_record/validations/associated.rb +1 -2
- data/lib/active_record/validations/numericality.rb +35 -0
- data/lib/active_record/validations/uniqueness.rb +38 -30
- data/lib/arel.rb +54 -0
- data/lib/arel/alias_predication.rb +9 -0
- data/lib/arel/attributes/attribute.rb +41 -0
- data/lib/arel/collectors/bind.rb +29 -0
- data/lib/arel/collectors/composite.rb +39 -0
- data/lib/arel/collectors/plain_string.rb +20 -0
- data/lib/arel/collectors/sql_string.rb +27 -0
- data/lib/arel/collectors/substitute_binds.rb +35 -0
- data/lib/arel/crud.rb +42 -0
- data/lib/arel/delete_manager.rb +18 -0
- data/lib/arel/errors.rb +9 -0
- data/lib/arel/expressions.rb +29 -0
- data/lib/arel/factory_methods.rb +49 -0
- data/lib/arel/insert_manager.rb +49 -0
- data/lib/arel/math.rb +45 -0
- data/lib/arel/nodes.rb +70 -0
- data/lib/arel/nodes/and.rb +32 -0
- data/lib/arel/nodes/ascending.rb +23 -0
- data/lib/arel/nodes/binary.rb +126 -0
- data/lib/arel/nodes/bind_param.rb +44 -0
- data/lib/arel/nodes/case.rb +55 -0
- data/lib/arel/nodes/casted.rb +62 -0
- data/lib/arel/nodes/comment.rb +29 -0
- data/lib/arel/nodes/count.rb +12 -0
- data/lib/arel/nodes/delete_statement.rb +45 -0
- data/lib/arel/nodes/descending.rb +23 -0
- data/lib/arel/nodes/equality.rb +15 -0
- data/lib/arel/nodes/extract.rb +24 -0
- data/lib/arel/nodes/false.rb +16 -0
- data/lib/arel/nodes/full_outer_join.rb +8 -0
- data/lib/arel/nodes/function.rb +44 -0
- data/lib/arel/nodes/grouping.rb +11 -0
- data/lib/arel/nodes/homogeneous_in.rb +72 -0
- data/lib/arel/nodes/in.rb +15 -0
- data/lib/arel/nodes/infix_operation.rb +92 -0
- data/lib/arel/nodes/inner_join.rb +8 -0
- data/lib/arel/nodes/insert_statement.rb +37 -0
- data/lib/arel/nodes/join_source.rb +20 -0
- data/lib/arel/nodes/matches.rb +18 -0
- data/lib/arel/nodes/named_function.rb +23 -0
- data/lib/arel/nodes/node.rb +51 -0
- data/lib/arel/nodes/node_expression.rb +13 -0
- data/lib/arel/nodes/ordering.rb +27 -0
- data/lib/arel/nodes/outer_join.rb +8 -0
- data/lib/arel/nodes/over.rb +15 -0
- data/lib/arel/nodes/regexp.rb +16 -0
- data/lib/arel/nodes/right_outer_join.rb +8 -0
- data/lib/arel/nodes/select_core.rb +67 -0
- data/lib/arel/nodes/select_statement.rb +41 -0
- data/lib/arel/nodes/sql_literal.rb +19 -0
- data/lib/arel/nodes/string_join.rb +11 -0
- data/lib/arel/nodes/table_alias.rb +31 -0
- data/lib/arel/nodes/terminal.rb +16 -0
- data/lib/arel/nodes/true.rb +16 -0
- data/lib/arel/nodes/unary.rb +44 -0
- data/lib/arel/nodes/unary_operation.rb +20 -0
- data/lib/arel/nodes/unqualified_column.rb +22 -0
- data/lib/arel/nodes/update_statement.rb +41 -0
- data/lib/arel/nodes/values_list.rb +9 -0
- data/lib/arel/nodes/window.rb +126 -0
- data/lib/arel/nodes/with.rb +11 -0
- data/lib/arel/order_predications.rb +13 -0
- data/lib/arel/predications.rb +250 -0
- data/lib/arel/select_manager.rb +270 -0
- data/lib/arel/table.rb +118 -0
- data/lib/arel/tree_manager.rb +72 -0
- data/lib/arel/update_manager.rb +34 -0
- data/lib/arel/visitors.rb +13 -0
- data/lib/arel/visitors/dot.rb +308 -0
- data/lib/arel/visitors/mysql.rb +93 -0
- data/lib/arel/visitors/postgresql.rb +120 -0
- data/lib/arel/visitors/sqlite.rb +38 -0
- data/lib/arel/visitors/to_sql.rb +899 -0
- data/lib/arel/visitors/visitor.rb +45 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/rails/generators/active_record/application_record/application_record_generator.rb +0 -1
- data/lib/rails/generators/active_record/migration.rb +19 -2
- data/lib/rails/generators/active_record/migration/migration_generator.rb +3 -5
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +3 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +7 -5
- data/lib/rails/generators/active_record/model/model_generator.rb +39 -2
- data/lib/rails/generators/active_record/model/templates/abstract_base_class.rb.tt +7 -0
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
- metadata +119 -34
- data/lib/active_record/attribute_decorators.rb +0 -90
- data/lib/active_record/collection_cache_key.rb +0 -53
- data/lib/active_record/connection_adapters/connection_specification.rb +0 -287
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +0 -33
- data/lib/active_record/define_callbacks.rb +0 -22
- data/lib/active_record/relation/predicate_builder/base_handler.rb +0 -19
- data/lib/active_record/relation/where_clause_factory.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4388f56d55688f1f53d21619c1d97a976a0bf198e46813febbaf7a867fb47702
|
4
|
+
data.tar.gz: 63314ed55ab0aa06c816b9208764f00a897ec40485c23dc23659ecadf5490d91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6da5c43903489b203067e4c187ffa405a91d6f35bd0d23087e225b2bc49f9b1ad4e5c4df73f72de8577ed0c044e049b5381a22a0b1c83215b1d3fc3b5b6d4dd
|
7
|
+
data.tar.gz: 3e3fffe809e00d052c6147b1e373744ac8875abf94c5225289901184447989a998cd953bbc4a0e644feac0eb4fdf33e14071bf48ac8d6b7741bd1aa962a592ea
|
data/CHANGELOG.md
CHANGED
@@ -1,19 +1,69 @@
|
|
1
|
-
## Rails
|
1
|
+
## Rails 6.1.3.2 (May 05, 2021) ##
|
2
2
|
|
3
3
|
* No changes.
|
4
4
|
|
5
5
|
|
6
|
-
## Rails
|
6
|
+
## Rails 6.1.3.1 (March 26, 2021) ##
|
7
7
|
|
8
8
|
* No changes.
|
9
9
|
|
10
10
|
|
11
|
-
## Rails
|
11
|
+
## Rails 6.1.3 (February 17, 2021) ##
|
12
12
|
|
13
|
-
*
|
13
|
+
* Fix the MySQL adapter to always set the right collation and charset
|
14
|
+
to the connection session.
|
15
|
+
|
16
|
+
*Rafael Mendonça França*
|
17
|
+
|
18
|
+
* Fix MySQL adapter handling of time objects when prepared statements
|
19
|
+
are enabled.
|
20
|
+
|
21
|
+
*Rafael Mendonça França*
|
22
|
+
|
23
|
+
* Fix scoping in enum fields using conditions that would generate
|
24
|
+
an `IN` clause.
|
25
|
+
|
26
|
+
*Ryuta Kamizono*
|
27
|
+
|
28
|
+
* Skip optimised #exist? query when #include? is called on a relation
|
29
|
+
with a having clause
|
30
|
+
|
31
|
+
Relations that have aliased select values AND a having clause that
|
32
|
+
references an aliased select value would generate an error when
|
33
|
+
#include? was called, due to an optimisation that would generate
|
34
|
+
call #exists? on the relation instead, which effectively alters
|
35
|
+
the select values of the query (and thus removes the aliased select
|
36
|
+
values), but leaves the having clause intact. Because the having
|
37
|
+
clause is then referencing an aliased column that is no longer
|
38
|
+
present in the simplified query, an ActiveRecord::InvalidStatement
|
39
|
+
error was raised.
|
40
|
+
|
41
|
+
An sample query affected by this problem:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Author.select('COUNT(*) as total_posts', 'authors.*')
|
45
|
+
.joins(:posts)
|
46
|
+
.group(:id)
|
47
|
+
.having('total_posts > 2')
|
48
|
+
.include?(Author.first)
|
49
|
+
```
|
50
|
+
|
51
|
+
This change adds an addition check to the condition that skips the
|
52
|
+
simplified #exists? query, which simply checks for the presence of
|
53
|
+
a having clause.
|
54
|
+
|
55
|
+
Fixes #41417
|
56
|
+
|
57
|
+
*Michael Smart*
|
14
58
|
|
59
|
+
* Increment postgres prepared statement counter before making a prepared statement, so if the statement is aborted
|
60
|
+
without Rails knowledge (e.g., if app gets kill -9d during long-running query or due to Rack::Timeout), app won't end
|
61
|
+
up in perpetual crash state for being inconsistent with Postgres.
|
15
62
|
|
16
|
-
|
63
|
+
*wbharding*, *Martin Tepper*
|
64
|
+
|
65
|
+
|
66
|
+
## Rails 6.1.2.1 (February 10, 2021) ##
|
17
67
|
|
18
68
|
* Fix possible DoS vector in PostgreSQL money type
|
19
69
|
|
@@ -28,999 +78,1416 @@
|
|
28
78
|
*Aaron Patterson*
|
29
79
|
|
30
80
|
|
31
|
-
## Rails
|
81
|
+
## Rails 6.1.2 (February 09, 2021) ##
|
32
82
|
|
33
|
-
*
|
83
|
+
* Fix timestamp type for sqlite3.
|
34
84
|
|
85
|
+
*Eileen M. Uchitelle*
|
35
86
|
|
36
|
-
|
87
|
+
* Make destroy async transactional.
|
37
88
|
|
38
|
-
|
89
|
+
An active record rollback could occur while enqueuing a job. In this
|
90
|
+
case the job would enqueue even though the database deletion
|
91
|
+
rolledback putting things in a funky state.
|
39
92
|
|
40
|
-
|
93
|
+
Now the jobs are only enqueued until after the db transaction has been committed.
|
41
94
|
|
42
|
-
*
|
95
|
+
*Cory Gwin*
|
43
96
|
|
97
|
+
* Fix malformed packet error in MySQL statement for connection configuration.
|
44
98
|
|
45
|
-
|
99
|
+
*robinroestenburg*
|
46
100
|
|
47
|
-
*
|
101
|
+
* Connection specification now passes the "url" key as a configuration for the
|
102
|
+
adapter if the "url" protocol is "jdbc", "http", or "https". Previously only
|
103
|
+
urls with the "jdbc" prefix were passed to the Active Record Adapter, others
|
104
|
+
are assumed to be adapter specification urls.
|
48
105
|
|
106
|
+
Fixes #41137.
|
49
107
|
|
50
|
-
|
108
|
+
*Jonathan Bracy*
|
51
109
|
|
52
|
-
* Fix
|
110
|
+
* Fix granular connection swapping when there are multiple abstract classes.
|
53
111
|
|
54
|
-
|
55
|
-
associations, the callback for a `has_many` association was run while
|
56
|
-
another instance of the same callback on the same association hadn't
|
57
|
-
finished running. When control returned to the first instance of the
|
58
|
-
callback, the instance variable had changed, and subsequent associated
|
59
|
-
records weren't saved correctly. Specifically, the ID field for the
|
60
|
-
`belongs_to` corresponding to the `has_many` was `nil`.
|
112
|
+
*Eileen M. Uchitelle*
|
61
113
|
|
62
|
-
|
114
|
+
* Fix `find_by` with custom primary key for belongs_to association.
|
63
115
|
|
64
|
-
*
|
116
|
+
*Ryuta Kamizono*
|
65
117
|
|
66
|
-
*
|
118
|
+
* Add support for `rails console --sandbox` for multiple database applications.
|
67
119
|
|
68
|
-
|
120
|
+
*alpaca-tc*
|
69
121
|
|
70
|
-
|
122
|
+
* Fix `where` on polymorphic association with empty array.
|
71
123
|
|
72
|
-
*
|
124
|
+
*Ryuta Kamizono*
|
73
125
|
|
74
|
-
|
126
|
+
* Fix preventing writes for `ApplicationRecord`.
|
75
127
|
|
76
|
-
*
|
128
|
+
*Eileen M. Uchitelle*
|
77
129
|
|
78
|
-
Fixes #36465.
|
79
130
|
|
80
|
-
|
131
|
+
## Rails 6.1.1 (January 07, 2021) ##
|
81
132
|
|
82
|
-
*
|
83
|
-
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
133
|
+
* Fix fixtures loading when strict loading is enabled for the association.
|
84
134
|
|
85
|
-
|
135
|
+
*Alex Ghiculescu*
|
86
136
|
|
87
|
-
|
137
|
+
* Fix `where` with custom primary key for belongs_to association.
|
88
138
|
|
139
|
+
*Ryuta Kamizono*
|
89
140
|
|
90
|
-
|
141
|
+
* Fix `where` with aliased associations.
|
91
142
|
|
92
|
-
*
|
143
|
+
*Ryuta Kamizono*
|
93
144
|
|
94
|
-
|
145
|
+
* Fix `composed_of` with symbol mapping.
|
95
146
|
|
96
|
-
*
|
147
|
+
*Ryuta Kamizono*
|
97
148
|
|
98
|
-
*
|
149
|
+
* Don't skip money's type cast for pluck and calculations.
|
99
150
|
|
100
151
|
*Ryuta Kamizono*
|
101
152
|
|
102
|
-
*
|
103
|
-
|
104
|
-
Fixes #33624.
|
153
|
+
* Fix `where` on polymorphic association with non Active Record object.
|
105
154
|
|
106
155
|
*Ryuta Kamizono*
|
107
156
|
|
108
|
-
*
|
157
|
+
* Make sure `db:prepare` works even the schema file doesn't exist.
|
109
158
|
|
110
|
-
|
159
|
+
*Rafael Mendonça França*
|
160
|
+
|
161
|
+
* Fix complicated `has_many :through` with nested where condition.
|
111
162
|
|
112
163
|
*Ryuta Kamizono*
|
113
164
|
|
114
|
-
*
|
165
|
+
* Handle STI models for `has_many dependent: :destroy_async`.
|
115
166
|
|
116
|
-
*
|
167
|
+
*Muhammad Usman*
|
117
168
|
|
118
|
-
*
|
169
|
+
* Restore possibility of passing `false` to :polymorphic option of `belongs_to`.
|
119
170
|
|
120
|
-
|
171
|
+
Previously, passing `false` would trigger the option validation logic
|
172
|
+
to throw an error saying :polymorphic would not be a valid option.
|
121
173
|
|
122
|
-
*
|
174
|
+
*glaszig*
|
123
175
|
|
124
|
-
|
176
|
+
* Allow adding nonnamed expression indexes to be revertible.
|
125
177
|
|
178
|
+
Fixes #40732.
|
126
179
|
|
127
|
-
|
180
|
+
Previously, the following code would raise an error, when executed while rolling back,
|
181
|
+
and the index name should be specified explicitly. Now, the index name is inferred
|
182
|
+
automatically.
|
128
183
|
|
129
|
-
|
184
|
+
```ruby
|
185
|
+
add_index(:items, "to_tsvector('english', description)")
|
186
|
+
```
|
130
187
|
|
188
|
+
*fatkodima*
|
131
189
|
|
132
|
-
## Rails 5.2.2 (December 04, 2018) ##
|
133
190
|
|
134
|
-
|
191
|
+
## Rails 6.1.0 (December 09, 2020) ##
|
135
192
|
|
136
|
-
|
193
|
+
* Only warn about negative enums if a positive form that would cause conflicts exists.
|
137
194
|
|
138
|
-
|
195
|
+
Fixes #39065.
|
139
196
|
|
140
|
-
*
|
197
|
+
*Alex Ghiculescu*
|
141
198
|
|
142
|
-
*
|
199
|
+
* Change `attribute_for_inspect` to take `filter_attributes` in consideration.
|
143
200
|
|
144
|
-
|
145
|
-
adapter.
|
201
|
+
*Rafael Mendonça França*
|
146
202
|
|
147
|
-
|
203
|
+
* Fix odd behavior of inverse_of with multiple belongs_to to same class.
|
148
204
|
|
149
|
-
|
205
|
+
Fixes #35204.
|
150
206
|
|
151
|
-
|
152
|
-
|
207
|
+
*Tomoyuki Kai*
|
208
|
+
|
209
|
+
* Build predicate conditions with objects that delegate `#id` and primary key:
|
153
210
|
|
154
211
|
```ruby
|
155
|
-
class
|
156
|
-
|
157
|
-
|
212
|
+
class AdminAuthor
|
213
|
+
delegate_missing_to :@author
|
214
|
+
|
215
|
+
def initialize(author)
|
216
|
+
@author = author
|
158
217
|
end
|
159
218
|
end
|
160
219
|
|
161
|
-
|
162
|
-
|
220
|
+
Post.where(author: AdminAuthor.new(author))
|
221
|
+
```
|
163
222
|
|
164
|
-
|
223
|
+
*Sean Doyle*
|
165
224
|
|
166
|
-
|
167
|
-
end
|
225
|
+
* Add `connected_to_many` API.
|
168
226
|
|
169
|
-
|
170
|
-
developer.update_column :name, "name"
|
227
|
+
This API allows applications to connect to multiple databases at once without switching all of them or implementing a deeply nested stack.
|
171
228
|
|
172
|
-
|
173
|
-
puts loaded_developer.name # should be "Developer: name" but it's just "name"
|
174
|
-
```
|
175
|
-
|
176
|
-
*Dmitry Tsepelev*
|
229
|
+
Before:
|
177
230
|
|
178
|
-
|
231
|
+
AnimalsRecord.connected_to(role: :reading) do
|
232
|
+
MealsRecord.connected_to(role: :reading) do
|
233
|
+
Dog.first # read from animals replica
|
234
|
+
Dinner.first # read from meals replica
|
235
|
+
Person.first # read from primary writer
|
236
|
+
end
|
237
|
+
end
|
179
238
|
|
180
|
-
|
239
|
+
After:
|
181
240
|
|
182
|
-
|
183
|
-
|
241
|
+
ActiveRecord::Base.connected_to_many([AnimalsRecord, MealsRecord], role: :reading) do
|
242
|
+
Dog.first # read from animals replica
|
243
|
+
Dinner.first # read from meals replica
|
244
|
+
Person.first # read from primary writer
|
245
|
+
end
|
184
246
|
|
185
|
-
*
|
247
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
186
248
|
|
187
|
-
*
|
249
|
+
* Add option to raise or log for `ActiveRecord::StrictLoadingViolationError`.
|
188
250
|
|
189
|
-
|
251
|
+
Some applications may not want to raise an error in production if using `strict_loading`. This would allow an application to set strict loading to log for the production environment while still raising in development and test environments.
|
190
252
|
|
191
|
-
|
253
|
+
Set `config.active_record.action_on_strict_loading_violation` to `:log` errors instead of raising.
|
192
254
|
|
193
255
|
*Eileen M. Uchitelle*
|
194
256
|
|
195
|
-
*
|
257
|
+
* Allow the inverse of a `has_one` association that was previously autosaved to be loaded.
|
196
258
|
|
197
|
-
Fixes #
|
259
|
+
Fixes #34255.
|
198
260
|
|
199
|
-
*
|
261
|
+
*Steven Weber*
|
200
262
|
|
201
|
-
*
|
263
|
+
* Optimise the length of index names for polymorphic references by using the reference name rather than the type and id column names.
|
202
264
|
|
203
|
-
|
265
|
+
Because the default behaviour when adding an index with multiple columns is to use all column names in the index name, this could frequently lead to overly long index names for polymorphic references which would fail the migration if it exceeded the database limit.
|
204
266
|
|
205
|
-
|
267
|
+
This change reduces the chance of that happening by using the reference name, e.g. `index_my_table_on_my_reference`.
|
206
268
|
|
207
|
-
|
269
|
+
Fixes #38655.
|
208
270
|
|
209
|
-
*
|
271
|
+
*Luke Redpath*
|
210
272
|
|
211
|
-
|
273
|
+
* MySQL: Uniqueness validator now respects default database collation,
|
274
|
+
no longer enforce case sensitive comparison by default.
|
212
275
|
|
213
|
-
*
|
276
|
+
*Ryuta Kamizono*
|
214
277
|
|
215
|
-
|
278
|
+
* Remove deprecated methods from `ActiveRecord::ConnectionAdapters::DatabaseLimits`.
|
216
279
|
|
217
|
-
|
280
|
+
`column_name_length`
|
281
|
+
`table_name_length`
|
282
|
+
`columns_per_table`
|
283
|
+
`indexes_per_table`
|
284
|
+
`columns_per_multicolumn_index`
|
285
|
+
`sql_query_length`
|
286
|
+
`joins_per_query`
|
218
287
|
|
219
|
-
*
|
288
|
+
*Rafael Mendonça França*
|
220
289
|
|
221
|
-
*
|
290
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?`.
|
222
291
|
|
223
|
-
*
|
292
|
+
*Rafael Mendonça França*
|
224
293
|
|
225
|
-
*
|
294
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?`.
|
226
295
|
|
227
|
-
*
|
296
|
+
*Rafael Mendonça França*
|
228
297
|
|
229
|
-
*
|
298
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?`.
|
230
299
|
|
231
|
-
*
|
300
|
+
*Rafael Mendonça França*
|
232
301
|
|
302
|
+
* Remove deprecated `ActiveRecord::Base#update_attributes` and `ActiveRecord::Base#update_attributes!`.
|
233
303
|
|
234
|
-
|
304
|
+
*Rafael Mendonça França*
|
235
305
|
|
236
|
-
*
|
306
|
+
* Remove deprecated `migrations_path` argument in `ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version`.
|
237
307
|
|
308
|
+
*Rafael Mendonça França*
|
309
|
+
|
310
|
+
* Remove deprecated `config.active_record.sqlite3.represent_boolean_as_integer`.
|
311
|
+
|
312
|
+
*Rafael Mendonça França*
|
238
313
|
|
239
|
-
|
314
|
+
* `relation.create` does no longer leak scope to class level querying methods
|
315
|
+
in initialization block and callbacks.
|
240
316
|
|
241
|
-
|
317
|
+
Before:
|
242
318
|
|
243
|
-
|
319
|
+
User.where(name: "John").create do |john|
|
320
|
+
User.find_by(name: "David") # => nil
|
321
|
+
end
|
244
322
|
|
245
|
-
|
323
|
+
After:
|
246
324
|
|
247
|
-
|
325
|
+
User.where(name: "John").create do |john|
|
326
|
+
User.find_by(name: "David") # => #<User name: "David", ...>
|
327
|
+
end
|
248
328
|
|
249
|
-
*
|
329
|
+
*Ryuta Kamizono*
|
250
330
|
|
251
|
-
*
|
331
|
+
* Named scope chain does no longer leak scope to class level querying methods.
|
252
332
|
|
253
|
-
|
333
|
+
class User < ActiveRecord::Base
|
334
|
+
scope :david, -> { User.where(name: "David") }
|
335
|
+
end
|
254
336
|
|
255
|
-
|
337
|
+
Before:
|
256
338
|
|
257
|
-
|
339
|
+
User.where(name: "John").david
|
340
|
+
# SELECT * FROM users WHERE name = 'John' AND name = 'David'
|
258
341
|
|
259
|
-
|
342
|
+
After:
|
260
343
|
|
261
|
-
|
344
|
+
User.where(name: "John").david
|
345
|
+
# SELECT * FROM users WHERE name = 'David'
|
262
346
|
|
263
347
|
*Ryuta Kamizono*
|
264
348
|
|
265
|
-
*
|
349
|
+
* Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`.
|
266
350
|
|
267
|
-
|
351
|
+
`fetch`
|
352
|
+
`each`
|
353
|
+
`first`
|
354
|
+
`values`
|
355
|
+
`[]=`
|
268
356
|
|
269
|
-
*
|
357
|
+
*Rafael Mendonça França*
|
270
358
|
|
271
|
-
|
359
|
+
* `where.not` now generates NAND predicates instead of NOR.
|
272
360
|
|
273
|
-
|
361
|
+
Before:
|
274
362
|
|
275
|
-
|
363
|
+
User.where.not(name: "Jon", role: "admin")
|
364
|
+
# SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
|
276
365
|
|
277
|
-
|
366
|
+
After:
|
278
367
|
|
279
|
-
|
368
|
+
User.where.not(name: "Jon", role: "admin")
|
369
|
+
# SELECT * FROM users WHERE NOT (name == 'Jon' AND role == 'admin')
|
280
370
|
|
281
|
-
*
|
371
|
+
*Rafael Mendonça França*
|
282
372
|
|
283
|
-
|
373
|
+
* Remove deprecated `ActiveRecord::Result#to_hash` method.
|
284
374
|
|
285
|
-
*
|
375
|
+
*Rafael Mendonça França*
|
286
376
|
|
287
|
-
*
|
377
|
+
* Deprecate `ActiveRecord::Base.allow_unsafe_raw_sql`.
|
288
378
|
|
289
|
-
*
|
379
|
+
*Rafael Mendonça França*
|
290
380
|
|
291
|
-
*
|
292
|
-
wrongly persists through record.
|
381
|
+
* Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.
|
293
382
|
|
294
|
-
|
383
|
+
*Rafael Mendonça França*
|
295
384
|
|
296
|
-
|
385
|
+
* Allow users to silence the "Rails couldn't infer whether you are using multiple databases..."
|
386
|
+
message using `config.active_record.suppress_multiple_database_warning`.
|
297
387
|
|
298
|
-
*
|
299
|
-
query cache.
|
388
|
+
*Omri Gabay*
|
300
389
|
|
301
|
-
|
390
|
+
* Connections can be granularly switched for abstract classes when `connected_to` is called.
|
302
391
|
|
392
|
+
This change allows `connected_to` to switch a `role` and/or `shard` for a single abstract class instead of all classes globally. Applications that want to use the new feature need to set `config.active_record.legacy_connection_handling` to `false` in their application configuration.
|
303
393
|
|
304
|
-
|
394
|
+
Example usage:
|
305
395
|
|
306
|
-
|
396
|
+
Given an application we have a `User` model that inherits from `ApplicationRecord` and a `Dog` model that inherits from `AnimalsRecord`. `AnimalsRecord` and `ApplicationRecord` have writing and reading connections as well as shard `default`, `one`, and `two`.
|
307
397
|
|
308
|
-
|
398
|
+
```ruby
|
399
|
+
ActiveRecord::Base.connected_to(role: :reading) do
|
400
|
+
User.first # reads from default replica
|
401
|
+
Dog.first # reads from default replica
|
309
402
|
|
310
|
-
|
403
|
+
AnimalsRecord.connected_to(role: :writing, shard: :one) do
|
404
|
+
User.first # reads from default replica
|
405
|
+
Dog.first # reads from shard one primary
|
406
|
+
end
|
311
407
|
|
312
|
-
|
313
|
-
|
314
|
-
that precision. This behavior is now applied to time columns as well.
|
408
|
+
User.first # reads from default replica
|
409
|
+
Dog.first # reads from default replica
|
315
410
|
|
316
|
-
|
411
|
+
ApplicationRecord.connected_to(role: :writing, shard: :two) do
|
412
|
+
User.first # reads from shard two primary
|
413
|
+
Dog.first # reads from default replica
|
414
|
+
end
|
415
|
+
end
|
416
|
+
```
|
317
417
|
|
318
|
-
*
|
418
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
319
419
|
|
320
|
-
*
|
420
|
+
* Allow double-dash comment syntax when querying read-only databases
|
321
421
|
|
322
|
-
|
323
|
-
because until #24542 the quoting for time columns didn't remove the date
|
324
|
-
component. To ensure that values are consistent we now normalize the
|
325
|
-
date component to 2001-01-01 on reading and writing.
|
422
|
+
*James Adam*
|
326
423
|
|
327
|
-
|
424
|
+
* Add `values_at` method.
|
328
425
|
|
329
|
-
|
426
|
+
Returns an array containing the values associated with the given methods.
|
330
427
|
|
331
|
-
|
332
|
-
|
333
|
-
|
428
|
+
```ruby
|
429
|
+
topic = Topic.first
|
430
|
+
topic.values_at(:title, :author_name)
|
431
|
+
# => ["Budget", "Jason"]
|
432
|
+
```
|
334
433
|
|
335
|
-
|
434
|
+
Similar to `Hash#values_at` but on an Active Record instance.
|
336
435
|
|
337
|
-
*
|
338
|
-
the parent class was getting deleted when the child was not.
|
436
|
+
*Guillaume Briday*
|
339
437
|
|
340
|
-
|
438
|
+
* Fix `read_attribute_before_type_cast` to consider attribute aliases.
|
341
439
|
|
342
|
-
*
|
440
|
+
*Marcelo Lauxen*
|
343
441
|
|
344
|
-
*
|
442
|
+
* Support passing record to uniqueness validator `:conditions` callable:
|
345
443
|
|
346
|
-
|
444
|
+
```ruby
|
445
|
+
class Article < ApplicationRecord
|
446
|
+
validates_uniqueness_of :title, conditions: ->(article) {
|
447
|
+
published_at = article.published_at
|
448
|
+
where(published_at: published_at.beginning_of_year..published_at.end_of_year)
|
449
|
+
}
|
450
|
+
end
|
451
|
+
```
|
347
452
|
|
348
|
-
*
|
453
|
+
*Eliot Sykes*
|
349
454
|
|
350
|
-
|
455
|
+
* `BatchEnumerator#update_all` and `BatchEnumerator#delete_all` now return the
|
456
|
+
total number of rows affected, just like their non-batched counterparts.
|
351
457
|
|
352
|
-
|
353
|
-
|
354
|
-
|
458
|
+
```ruby
|
459
|
+
Person.in_batches.update_all("first_name = 'Eugene'") # => 42
|
460
|
+
Person.in_batches.delete_all # => 42
|
461
|
+
```
|
355
462
|
|
356
|
-
Fixes #
|
463
|
+
Fixes #40287.
|
357
464
|
|
358
|
-
*
|
465
|
+
*Eugene Kenny*
|
359
466
|
|
360
|
-
*
|
467
|
+
* Add support for PostgreSQL `interval` data type with conversion to
|
468
|
+
`ActiveSupport::Duration` when loading records from database and
|
469
|
+
serialization to ISO 8601 formatted duration string on save.
|
470
|
+
Add support to define a column in migrations and get it in a schema dump.
|
471
|
+
Optional column precision is supported.
|
361
472
|
|
362
|
-
|
473
|
+
To use this in 6.1, you need to place the next string to your model file:
|
363
474
|
|
364
|
-
|
475
|
+
attribute :duration, :interval
|
365
476
|
|
366
|
-
|
477
|
+
To keep old behavior until 6.2 is released:
|
367
478
|
|
368
|
-
|
479
|
+
attribute :duration, :string
|
369
480
|
|
370
|
-
|
371
|
-
Using a `Relation` for performing queries is the prefered API.
|
481
|
+
Example:
|
372
482
|
|
373
|
-
|
483
|
+
create_table :events do |t|
|
484
|
+
t.string :name
|
485
|
+
t.interval :duration
|
486
|
+
end
|
374
487
|
|
375
|
-
|
488
|
+
class Event < ApplicationRecord
|
489
|
+
attribute :duration, :interval
|
490
|
+
end
|
376
491
|
|
377
|
-
|
378
|
-
|
379
|
-
|
492
|
+
Event.create!(name: 'Rock Fest', duration: 2.days)
|
493
|
+
Event.last.duration # => 2 days
|
494
|
+
Event.last.duration.iso8601 # => "P2D"
|
495
|
+
Event.new(duration: 'P1DT12H3S').duration # => 1 day, 12 hours, and 3 seconds
|
496
|
+
Event.new(duration: '1 day') # Unknown value will be ignored and NULL will be written to database
|
380
497
|
|
381
|
-
|
382
|
-
|
498
|
+
*Andrey Novikov*
|
499
|
+
|
500
|
+
* Allow associations supporting the `dependent:` key to take `dependent: :destroy_async`.
|
501
|
+
|
502
|
+
```ruby
|
503
|
+
class Account < ActiveRecord::Base
|
504
|
+
belongs_to :supplier, dependent: :destroy_async
|
505
|
+
end
|
383
506
|
```
|
384
507
|
|
385
|
-
|
508
|
+
`:destroy_async` will enqueue a job to destroy associated records in the background.
|
386
509
|
|
387
|
-
*
|
510
|
+
*DHH*, *George Claghorn*, *Cory Gwin*, *Rafael Mendonça França*, *Adrianna Chang*
|
388
511
|
|
389
|
-
*
|
512
|
+
* Add `SKIP_TEST_DATABASE` environment variable to disable modifying the test database when `rails db:create` and `rails db:drop` are called.
|
390
513
|
|
391
|
-
|
514
|
+
*Jason Schweier*
|
392
515
|
|
393
|
-
|
516
|
+
* `connects_to` can only be called on `ActiveRecord::Base` or abstract classes.
|
394
517
|
|
395
|
-
|
518
|
+
Ensure that `connects_to` can only be called from `ActiveRecord::Base` or abstract classes. This protects the application from opening duplicate or too many connections.
|
396
519
|
|
397
|
-
|
520
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
398
521
|
|
399
|
-
|
522
|
+
* All connection adapters `execute` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
523
|
+
`ActiveRecord::StatementInvalid` when they encounter a connection error.
|
400
524
|
|
401
|
-
*
|
525
|
+
*Jean Boussier*
|
402
526
|
|
403
|
-
|
527
|
+
* `Mysql2Adapter#quote_string` now raises `ActiveRecord::ConnectionNotEstablished` rather than
|
528
|
+
`ActiveRecord::StatementInvalid` when it can't connect to the MySQL server.
|
404
529
|
|
405
|
-
*
|
530
|
+
*Jean Boussier*
|
406
531
|
|
407
|
-
|
532
|
+
* Add support for check constraints that are `NOT VALID` via `validate: false` (PostgreSQL-only).
|
408
533
|
|
409
|
-
*
|
534
|
+
*Alex Robbin*
|
410
535
|
|
411
|
-
|
536
|
+
* Ensure the default configuration is considered primary or first for an environment
|
412
537
|
|
413
|
-
|
538
|
+
If a multiple database application provides a configuration named primary, that will be treated as default. In applications that do not have a primary entry, the default database configuration will be the first configuration for an environment.
|
414
539
|
|
415
|
-
|
540
|
+
*Eileen M. Uchitelle*
|
416
541
|
|
417
|
-
|
542
|
+
* Allow `where` references association names as joined table name aliases.
|
418
543
|
|
419
|
-
|
544
|
+
```ruby
|
545
|
+
class Comment < ActiveRecord::Base
|
546
|
+
enum label: [:default, :child]
|
547
|
+
has_many :children, class_name: "Comment", foreign_key: :parent_id
|
548
|
+
end
|
420
549
|
|
421
|
-
|
550
|
+
# ... FROM comments LEFT OUTER JOIN comments children ON ... WHERE children.label = 1
|
551
|
+
Comment.includes(:children).where("children.label": "child")
|
552
|
+
```
|
422
553
|
|
423
|
-
|
424
|
-
belongs_to :author
|
425
|
-
has_many :books, through: :author
|
426
|
-
has_many :subscriptions, through: :books
|
427
|
-
end
|
554
|
+
*Ryuta Kamizono*
|
428
555
|
|
429
|
-
|
430
|
-
has_one :post
|
431
|
-
has_many :books
|
432
|
-
has_many :subscriptions, through: :books
|
433
|
-
end
|
556
|
+
* Support storing demodulized class name for polymorphic type.
|
434
557
|
|
435
|
-
|
436
|
-
|
437
|
-
has_many :subscriptions
|
438
|
-
end
|
558
|
+
Before Rails 6.1, storing demodulized class name is supported only for STI type
|
559
|
+
by `store_full_sti_class` class attribute.
|
439
560
|
|
440
|
-
|
441
|
-
belongs_to :book
|
442
|
-
end
|
561
|
+
Now `store_full_class_name` class attribute can handle both STI and polymorphic types.
|
443
562
|
|
444
|
-
|
563
|
+
*Ryuta Kamizono*
|
445
564
|
|
446
|
-
|
565
|
+
* Deprecate `rails db:structure:{load, dump}` tasks and extend
|
566
|
+
`rails db:schema:{load, dump}` tasks to work with either `:ruby` or `:sql` format,
|
567
|
+
depending on `config.active_record.schema_format` configuration value.
|
447
568
|
|
448
|
-
|
569
|
+
*fatkodima*
|
449
570
|
|
450
|
-
|
451
|
-
just like it would if `post` were persisted.
|
571
|
+
* Respect the `select` values for eager loading.
|
452
572
|
|
453
|
-
|
573
|
+
```ruby
|
574
|
+
post = Post.select("UPPER(title) AS title").first
|
575
|
+
post.title # => "WELCOME TO THE WEBLOG"
|
576
|
+
post.body # => ActiveModel::MissingAttributeError
|
577
|
+
|
578
|
+
# Rails 6.0 (ignore the `select` values)
|
579
|
+
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
580
|
+
post.title # => "Welcome to the weblog"
|
581
|
+
post.body # => "Such a lovely day"
|
582
|
+
|
583
|
+
# Rails 6.1 (respect the `select` values)
|
584
|
+
post = Post.select("UPPER(title) AS title").eager_load(:comments).first
|
585
|
+
post.title # => "WELCOME TO THE WEBLOG"
|
586
|
+
post.body # => ActiveModel::MissingAttributeError
|
587
|
+
```
|
454
588
|
|
455
|
-
*
|
589
|
+
*Ryuta Kamizono*
|
456
590
|
|
457
|
-
*
|
458
|
-
The `first(n)` finder now respects the `limit()`, making it consistent
|
459
|
-
with `relation.to_a.first(n)`, and also with the behavior of `last(n)`.
|
591
|
+
* Allow attribute's default to be configured but keeping its own type.
|
460
592
|
|
461
|
-
|
593
|
+
```ruby
|
594
|
+
class Post < ActiveRecord::Base
|
595
|
+
attribute :written_at, default: -> { Time.now.utc }
|
596
|
+
end
|
462
597
|
|
463
|
-
|
598
|
+
# Rails 6.0
|
599
|
+
Post.type_for_attribute(:written_at) # => #<Type::Value ... precision: nil, ...>
|
464
600
|
|
465
|
-
|
466
|
-
|
601
|
+
# Rails 6.1
|
602
|
+
Post.type_for_attribute(:written_at) # => #<Type::DateTime ... precision: 6, ...>
|
603
|
+
```
|
467
604
|
|
468
|
-
*
|
605
|
+
*Ryuta Kamizono*
|
469
606
|
|
470
|
-
*
|
607
|
+
* Allow default to be configured for Enum.
|
471
608
|
|
472
|
-
|
609
|
+
```ruby
|
610
|
+
class Book < ActiveRecord::Base
|
611
|
+
enum status: [:proposed, :written, :published], _default: :published
|
612
|
+
end
|
473
613
|
|
474
|
-
|
614
|
+
Book.new.status # => "published"
|
615
|
+
```
|
475
616
|
|
476
617
|
*Ryuta Kamizono*
|
477
618
|
|
478
|
-
*
|
619
|
+
* Deprecate YAML loading from legacy format older than Rails 5.0.
|
479
620
|
|
480
621
|
*Ryuta Kamizono*
|
481
622
|
|
482
|
-
*
|
483
|
-
|
623
|
+
* Added the setting `ActiveRecord::Base.immutable_strings_by_default`, which
|
624
|
+
allows you to specify that all string columns should be frozen unless
|
625
|
+
otherwise specified. This will reduce memory pressure for applications which
|
626
|
+
do not generally mutate string properties of Active Record objects.
|
484
627
|
|
485
|
-
*
|
628
|
+
*Sean Griffin*, *Ryuta Kamizono*
|
486
629
|
|
487
|
-
*
|
630
|
+
* Deprecate `map!` and `collect!` on `ActiveRecord::Result`.
|
488
631
|
|
489
|
-
|
490
|
-
of database queries in the log to facilitate N+1 query resolution
|
491
|
-
and other debugging.
|
632
|
+
*Ryuta Kamizono*
|
492
633
|
|
493
|
-
|
494
|
-
recommended for use in the production environment since it relies
|
495
|
-
on Ruby's `Kernel#caller_locations` which is fairly slow.
|
634
|
+
* Support `relation.and` for intersection as Set theory.
|
496
635
|
|
497
|
-
|
636
|
+
```ruby
|
637
|
+
david_and_mary = Author.where(id: [david, mary])
|
638
|
+
mary_and_bob = Author.where(id: [mary, bob])
|
498
639
|
|
499
|
-
|
640
|
+
david_and_mary.merge(mary_and_bob) # => [mary, bob]
|
500
641
|
|
642
|
+
david_and_mary.and(mary_and_bob) # => [mary]
|
643
|
+
david_and_mary.or(mary_and_bob) # => [david, mary, bob]
|
501
644
|
```
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
645
|
+
|
646
|
+
*Ryuta Kamizono*
|
647
|
+
|
648
|
+
* Merging conditions on the same column no longer maintain both conditions,
|
649
|
+
and will be consistently replaced by the latter condition in Rails 6.2.
|
650
|
+
To migrate to Rails 6.2's behavior, use `relation.merge(other, rewhere: true)`.
|
651
|
+
|
652
|
+
```ruby
|
653
|
+
# Rails 6.1 (IN clause is replaced by merger side equality condition)
|
654
|
+
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
655
|
+
|
656
|
+
# Rails 6.1 (both conflict conditions exists, deprecated)
|
657
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => []
|
658
|
+
|
659
|
+
# Rails 6.1 with rewhere to migrate to Rails 6.2's behavior
|
660
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob), rewhere: true) # => [bob]
|
661
|
+
|
662
|
+
# Rails 6.2 (same behavior with IN clause, mergee side condition is consistently replaced)
|
663
|
+
Author.where(id: [david.id, mary.id]).merge(Author.where(id: bob)) # => [bob]
|
664
|
+
Author.where(id: david.id..mary.id).merge(Author.where(id: bob)) # => [bob]
|
665
|
+
```
|
666
|
+
|
667
|
+
*Ryuta Kamizono*
|
668
|
+
|
669
|
+
* Do not mark Postgresql MAC address and UUID attributes as changed when the assigned value only varies by case.
|
670
|
+
|
671
|
+
*Peter Fry*
|
672
|
+
|
673
|
+
* Resolve issue with insert_all unique_by option when used with expression index.
|
674
|
+
|
675
|
+
When the `:unique_by` option of `ActiveRecord::Persistence.insert_all` and
|
676
|
+
`ActiveRecord::Persistence.upsert_all` was used with the name of an expression index, an error
|
677
|
+
was raised. Adding a guard around the formatting behavior for the `:unique_by` corrects this.
|
678
|
+
|
679
|
+
Usage:
|
680
|
+
|
681
|
+
```ruby
|
682
|
+
create_table :books, id: :integer, force: true do |t|
|
683
|
+
t.column :name, :string
|
684
|
+
t.index "lower(name)", unique: true
|
508
685
|
end
|
509
686
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
687
|
+
Book.insert_all [{ name: "MyTest" }], unique_by: :index_books_on_lower_name
|
688
|
+
```
|
689
|
+
|
690
|
+
Fixes #39516.
|
691
|
+
|
692
|
+
*Austen Madden*
|
693
|
+
|
694
|
+
* Add basic support for CHECK constraints to database migrations.
|
695
|
+
|
696
|
+
Usage:
|
697
|
+
|
698
|
+
```ruby
|
699
|
+
add_check_constraint :products, "price > 0", name: "price_check"
|
700
|
+
remove_check_constraint :products, name: "price_check"
|
701
|
+
```
|
702
|
+
|
703
|
+
*fatkodima*
|
704
|
+
|
705
|
+
* Add `ActiveRecord::Base.strict_loading_by_default` and `ActiveRecord::Base.strict_loading_by_default=`
|
706
|
+
to enable/disable strict_loading mode by default for a model. The configuration's value is
|
707
|
+
inheritable by subclasses, but they can override that value and it will not impact parent class.
|
708
|
+
|
709
|
+
Usage:
|
710
|
+
|
711
|
+
```ruby
|
712
|
+
class Developer < ApplicationRecord
|
713
|
+
self.strict_loading_by_default = true
|
714
|
+
|
715
|
+
has_many :projects
|
515
716
|
end
|
717
|
+
|
718
|
+
dev = Developer.first
|
719
|
+
dev.projects.first
|
720
|
+
# => ActiveRecord::StrictLoadingViolationError Exception: Developer is marked as strict_loading and Project cannot be lazily loaded.
|
516
721
|
```
|
517
722
|
|
723
|
+
*bogdanvlviv*
|
724
|
+
|
725
|
+
* Deprecate passing an Active Record object to `quote`/`type_cast` directly.
|
726
|
+
|
727
|
+
*Ryuta Kamizono*
|
728
|
+
|
729
|
+
* Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic.
|
730
|
+
|
518
731
|
Before:
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
|
524
|
-
commit transaction
|
525
|
-
|
526
|
-
comment = Comment.create!(post: post)
|
527
|
-
# => begin transaction
|
528
|
-
INSERT INTO "comments" ("post_id") VALUES (1)
|
529
|
-
|
530
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
|
531
|
-
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
532
|
-
|
533
|
-
UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330',
|
534
|
-
"lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
|
535
|
-
rollback transaction
|
536
|
-
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
537
|
-
|
538
|
-
Comment.take.destroy!
|
539
|
-
# => begin transaction
|
540
|
-
DELETE FROM "comments" WHERE "comments"."id" = 1
|
541
|
-
|
542
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
|
543
|
-
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
544
|
-
|
545
|
-
UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901',
|
546
|
-
"lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
|
547
|
-
rollback transaction
|
548
|
-
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
732
|
+
|
733
|
+
```ruby
|
734
|
+
create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
|
735
|
+
end
|
549
736
|
```
|
550
737
|
|
551
738
|
After:
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
|
557
|
-
commit transaction
|
558
|
-
|
559
|
-
comment = Comment.create!(post: post)
|
560
|
-
# => begin transaction
|
561
|
-
INSERT INTO "comments" ("post_id") VALUES (1)
|
562
|
-
|
563
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
|
564
|
-
"lock_version" = COALESCE("lock_version", 0) + 1,
|
565
|
-
"updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
|
566
|
-
commit transaction
|
567
|
-
|
568
|
-
comment.destroy!
|
569
|
-
# => begin transaction
|
570
|
-
DELETE FROM "comments" WHERE "comments"."id" = 1
|
571
|
-
|
572
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
|
573
|
-
"lock_version" = COALESCE("lock_version", 0) + 1,
|
574
|
-
"updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
|
575
|
-
commit transaction
|
739
|
+
|
740
|
+
```ruby
|
741
|
+
create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
|
742
|
+
end
|
576
743
|
```
|
577
744
|
|
578
|
-
|
745
|
+
*Ryuta Kamizono*
|
579
746
|
|
580
|
-
|
747
|
+
* Added delegated type as an alternative to single-table inheritance for representing class hierarchies.
|
748
|
+
See ActiveRecord::DelegatedType for the full description.
|
581
749
|
|
582
|
-
*
|
750
|
+
*DHH*
|
583
751
|
|
584
|
-
|
752
|
+
* Deprecate aggregations with group by duplicated fields.
|
585
753
|
|
586
|
-
|
754
|
+
To migrate to Rails 6.2's behavior, use `uniq!(:group)` to deduplicate group fields.
|
587
755
|
|
588
|
-
|
756
|
+
```ruby
|
757
|
+
accounts = Account.group(:firm_id)
|
758
|
+
|
759
|
+
# duplicated group fields, deprecated.
|
760
|
+
accounts.merge(accounts.where.not(credit_limit: nil)).sum(:credit_limit)
|
761
|
+
# => {
|
762
|
+
# [1, 1] => 50,
|
763
|
+
# [2, 2] => 60
|
764
|
+
# }
|
765
|
+
|
766
|
+
# use `uniq!(:group)` to deduplicate group fields.
|
767
|
+
accounts.merge(accounts.where.not(credit_limit: nil)).uniq!(:group).sum(:credit_limit)
|
768
|
+
# => {
|
769
|
+
# 1 => 50,
|
770
|
+
# 2 => 60
|
771
|
+
# }
|
772
|
+
```
|
589
773
|
|
590
|
-
*
|
774
|
+
*Ryuta Kamizono*
|
591
775
|
|
592
|
-
|
776
|
+
* Deprecate duplicated query annotations.
|
593
777
|
|
594
|
-
|
778
|
+
To migrate to Rails 6.2's behavior, use `uniq!(:annotate)` to deduplicate query annotations.
|
595
779
|
|
596
|
-
|
597
|
-
|
780
|
+
```ruby
|
781
|
+
accounts = Account.where(id: [1, 2]).annotate("david and mary")
|
782
|
+
|
783
|
+
# duplicated annotations, deprecated.
|
784
|
+
accounts.merge(accounts.rewhere(id: 3))
|
785
|
+
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */ /* david and mary */
|
786
|
+
|
787
|
+
# use `uniq!(:annotate)` to deduplicate annotations.
|
788
|
+
accounts.merge(accounts.rewhere(id: 3)).uniq!(:annotate)
|
789
|
+
# SELECT accounts.* FROM accounts WHERE accounts.id = 3 /* david and mary */
|
790
|
+
```
|
598
791
|
|
599
792
|
*Ryuta Kamizono*
|
600
793
|
|
601
|
-
*
|
602
|
-
migrating up, e.g. populating a new column.
|
794
|
+
* Resolve conflict between counter cache and optimistic locking.
|
603
795
|
|
604
|
-
|
796
|
+
Bump an Active Record instance's lock version after updating its counter
|
797
|
+
cache. This avoids raising an unnecessary `ActiveRecord::StaleObjectError`
|
798
|
+
upon subsequent transactions by maintaining parity with the corresponding
|
799
|
+
database record's `lock_version` column.
|
605
800
|
|
606
|
-
|
607
|
-
relation query methods.
|
801
|
+
Fixes #16449.
|
608
802
|
|
609
|
-
|
610
|
-
|
611
|
-
|
803
|
+
*Aaron Lipman*
|
804
|
+
|
805
|
+
* Support merging option `:rewhere` to allow mergee side condition to be replaced exactly.
|
806
|
+
|
807
|
+
```ruby
|
808
|
+
david_and_mary = Author.where(id: david.id..mary.id)
|
809
|
+
|
810
|
+
# both conflict conditions exists
|
811
|
+
david_and_mary.merge(Author.where(id: bob)) # => []
|
812
|
+
|
813
|
+
# mergee side condition is replaced by rewhere
|
814
|
+
david_and_mary.merge(Author.rewhere(id: bob)) # => [bob]
|
815
|
+
|
816
|
+
# mergee side condition is replaced by rewhere option
|
817
|
+
david_and_mary.merge(Author.where(id: bob), rewhere: true) # => [bob]
|
612
818
|
```
|
613
819
|
|
614
|
-
|
820
|
+
*Ryuta Kamizono*
|
821
|
+
|
822
|
+
* Add support for finding records based on signed ids, which are tamper-proof, verified ids that can be
|
823
|
+
set to expire and scoped with a purpose. This is particularly useful for things like password reset
|
824
|
+
or email verification, where you want the bearer of the signed id to be able to interact with the
|
825
|
+
underlying record, but usually only within a certain time period.
|
826
|
+
|
827
|
+
```ruby
|
828
|
+
signed_id = User.first.signed_id expires_in: 15.minutes, purpose: :password_reset
|
829
|
+
|
830
|
+
User.find_signed signed_id # => nil, since the purpose does not match
|
831
|
+
|
832
|
+
travel 16.minutes
|
833
|
+
User.find_signed signed_id, purpose: :password_reset # => nil, since the signed id has expired
|
834
|
+
|
835
|
+
travel_back
|
836
|
+
User.find_signed signed_id, purpose: :password_reset # => User.first
|
837
|
+
|
838
|
+
User.find_signed! "bad data" # => ActiveSupport::MessageVerifier::InvalidSignature
|
615
839
|
```
|
616
|
-
|
840
|
+
|
841
|
+
*DHH*
|
842
|
+
|
843
|
+
* Support `ALGORITHM = INSTANT` DDL option for index operations on MySQL.
|
844
|
+
|
845
|
+
*Ryuta Kamizono*
|
846
|
+
|
847
|
+
* Fix index creation to preserve index comment in bulk change table on MySQL.
|
848
|
+
|
849
|
+
*Ryuta Kamizono*
|
850
|
+
|
851
|
+
* Allow `unscope` to be aware of table name qualified values.
|
852
|
+
|
853
|
+
It is possible to unscope only the column in the specified table.
|
854
|
+
|
855
|
+
```ruby
|
856
|
+
posts = Post.joins(:comments).group(:"posts.hidden")
|
857
|
+
posts = posts.where("posts.hidden": false, "comments.hidden": false)
|
858
|
+
|
859
|
+
posts.count
|
860
|
+
# => { false => 10 }
|
861
|
+
|
862
|
+
# unscope both hidden columns
|
863
|
+
posts.unscope(where: :hidden).count
|
864
|
+
# => { false => 11, true => 1 }
|
865
|
+
|
866
|
+
# unscope only comments.hidden column
|
867
|
+
posts.unscope(where: :"comments.hidden").count
|
868
|
+
# => { false => 11 }
|
617
869
|
```
|
618
870
|
|
619
|
-
|
620
|
-
|
621
|
-
|
871
|
+
*Ryuta Kamizono*, *Slava Korolev*
|
872
|
+
|
873
|
+
* Fix `rewhere` to truly overwrite collided where clause by new where clause.
|
874
|
+
|
875
|
+
```ruby
|
876
|
+
steve = Person.find_by(name: "Steve")
|
877
|
+
david = Author.find_by(name: "David")
|
878
|
+
|
879
|
+
relation = Essay.where(writer: steve)
|
622
880
|
|
623
|
-
|
624
|
-
|
625
|
-
can opt in to the future behavior by setting `allow_unsafe_raw_sql`
|
626
|
-
to `:disabled`.
|
881
|
+
# Before
|
882
|
+
relation.rewhere(writer: david).to_a # => []
|
627
883
|
|
628
|
-
|
629
|
-
|
884
|
+
# After
|
885
|
+
relation.rewhere(writer: david).to_a # => [david]
|
630
886
|
```
|
631
|
-
|
887
|
+
|
888
|
+
*Ryuta Kamizono*
|
889
|
+
|
890
|
+
* Inspect time attributes with subsec and time zone offset.
|
891
|
+
|
892
|
+
```ruby
|
893
|
+
p Knot.create
|
894
|
+
=> #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000 +0000">
|
632
895
|
```
|
633
896
|
|
634
|
-
*
|
897
|
+
*akinomaeni*, *Jonathan Hefner*
|
635
898
|
|
636
|
-
*
|
637
|
-
`Type#serialize`. This means that `update_all(foo: 'true')` will properly
|
638
|
-
persist a boolean.
|
899
|
+
* Deprecate passing a column to `type_cast`.
|
639
900
|
|
640
|
-
*
|
901
|
+
*Ryuta Kamizono*
|
641
902
|
|
642
|
-
*
|
643
|
-
when statement timeout exceeded.
|
903
|
+
* Deprecate `in_clause_length` and `allowed_index_name_length` in `DatabaseLimits`.
|
644
904
|
|
645
905
|
*Ryuta Kamizono*
|
646
906
|
|
647
|
-
*
|
648
|
-
`bin/rails db:migrate` with empty VERSION behaves as without `VERSION`.
|
649
|
-
Check a format of `VERSION`: Allow a migration version number
|
650
|
-
or name of a migration file. Raise error if format of `VERSION` is invalid.
|
651
|
-
Raise error if target migration doesn't exist.
|
907
|
+
* Support bulk insert/upsert on relation to preserve scope values.
|
652
908
|
|
653
|
-
*
|
909
|
+
*Josef Šimánek*, *Ryuta Kamizono*
|
654
910
|
|
655
|
-
*
|
656
|
-
`db/schema.rb` when using the sqlite adapter.
|
911
|
+
* Preserve column comment value on changing column name on MySQL.
|
657
912
|
|
658
|
-
|
913
|
+
*Islam Taha*
|
659
914
|
|
660
|
-
|
915
|
+
* Add support for `if_exists` option for removing an index.
|
661
916
|
|
662
|
-
|
917
|
+
The `remove_index` method can take an `if_exists` option. If this is set to true an error won't be raised if the index doesn't exist.
|
663
918
|
|
664
|
-
*
|
919
|
+
*Eileen M. Uchitelle*
|
665
920
|
|
666
|
-
* Remove
|
921
|
+
* Remove ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base.
|
667
922
|
|
668
|
-
*
|
923
|
+
*Ryuta Kamizono*
|
669
924
|
|
670
|
-
*
|
925
|
+
* Prevent `build_association` from `touching` a parent record if the record isn't persisted for `has_one` associations.
|
671
926
|
|
672
|
-
|
927
|
+
Fixes #38219.
|
673
928
|
|
674
|
-
*
|
929
|
+
*Josh Brody*
|
675
930
|
|
676
|
-
|
931
|
+
* Add support for `if_not_exists` option for adding index.
|
677
932
|
|
678
|
-
|
933
|
+
The `add_index` method respects `if_not_exists` option. If it is set to true
|
934
|
+
index won't be added.
|
679
935
|
|
680
|
-
|
936
|
+
Usage:
|
681
937
|
|
682
|
-
|
938
|
+
```ruby
|
939
|
+
add_index :users, :account_id, if_not_exists: true
|
940
|
+
```
|
683
941
|
|
684
|
-
|
942
|
+
The `if_not_exists` option passed to `create_table` also gets propagated to indexes
|
943
|
+
created within that migration so that if table and its indexes exist then there is no
|
944
|
+
attempt to create them again.
|
685
945
|
|
686
|
-
*
|
946
|
+
*Prathamesh Sonpatki*
|
687
947
|
|
688
|
-
|
948
|
+
* Add `ActiveRecord::Base#previously_new_record?` to show if a record was new before the last save.
|
689
949
|
|
690
|
-
*
|
950
|
+
*Tom Ward*
|
691
951
|
|
692
|
-
|
952
|
+
* Support descending order for `find_each`, `find_in_batches`, and `in_batches`.
|
693
953
|
|
694
|
-
|
954
|
+
Batch processing methods allow you to work with the records in batches, greatly reducing memory consumption, but records are always batched from oldest id to newest.
|
695
955
|
|
696
|
-
|
956
|
+
This change allows reversing the order, batching from newest to oldest. This is useful when you need to process newer batches of records first.
|
697
957
|
|
698
|
-
|
958
|
+
Pass `order: :desc` to yield batches in descending order. The default remains `order: :asc`.
|
699
959
|
|
700
|
-
|
960
|
+
```ruby
|
961
|
+
Person.find_each(order: :desc) do |person|
|
962
|
+
person.party_all_night!
|
963
|
+
end
|
964
|
+
```
|
701
965
|
|
702
|
-
*
|
966
|
+
*Alexey Vasiliev*
|
703
967
|
|
704
|
-
|
968
|
+
* Fix `insert_all` with enum values.
|
705
969
|
|
706
|
-
|
970
|
+
Fixes #38716.
|
707
971
|
|
708
|
-
*
|
972
|
+
*Joel Blum*
|
709
973
|
|
710
|
-
*
|
974
|
+
* Add support for `db:rollback:name` for multiple database applications.
|
711
975
|
|
712
|
-
|
976
|
+
Multiple database applications will now raise if `db:rollback` is call and recommend using the `db:rollback:[NAME]` to rollback migrations.
|
977
|
+
|
978
|
+
*Eileen M. Uchitelle*
|
713
979
|
|
714
|
-
*
|
715
|
-
ar_internal_metadata's data for a test database.
|
980
|
+
* `Relation#pick` now uses already loaded results instead of making another query.
|
716
981
|
|
717
|
-
|
982
|
+
*Eugene Kenny*
|
983
|
+
|
984
|
+
* Deprecate using `return`, `break` or `throw` to exit a transaction block after writes.
|
985
|
+
|
986
|
+
*Dylan Thacker-Smith*
|
987
|
+
|
988
|
+
* Dump the schema or structure of a database when calling `db:migrate:name`.
|
989
|
+
|
990
|
+
In previous versions of Rails, `rails db:migrate` would dump the schema of the database. In Rails 6, that holds true (`rails db:migrate` dumps all databases' schemas), but `rails db:migrate:name` does not share that behavior.
|
991
|
+
|
992
|
+
Going forward, calls to `rails db:migrate:name` will dump the schema (or structure) of the database being migrated.
|
993
|
+
|
994
|
+
*Kyle Thompson*
|
995
|
+
|
996
|
+
* Reset the `ActiveRecord::Base` connection after `rails db:migrate:name`.
|
997
|
+
|
998
|
+
When `rails db:migrate` has finished, it ensures the `ActiveRecord::Base` connection is reset to its original configuration. Going forward, `rails db:migrate:name` will have the same behavior.
|
999
|
+
|
1000
|
+
*Kyle Thompson*
|
1001
|
+
|
1002
|
+
* Disallow calling `connected_to` on subclasses of `ActiveRecord::Base`.
|
1003
|
+
|
1004
|
+
Behavior has not changed here but the previous API could be misleading to people who thought it would switch connections for only that class. `connected_to` switches the context from which we are getting connections, not the connections themselves.
|
1005
|
+
|
1006
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1007
|
+
|
1008
|
+
* Add support for horizontal sharding to `connects_to` and `connected_to`.
|
1009
|
+
|
1010
|
+
Applications can now connect to multiple shards and switch between their shards in an application. Note that the shard swapping is still a manual process as this change does not include an API for automatic shard swapping.
|
1011
|
+
|
1012
|
+
Usage:
|
1013
|
+
|
1014
|
+
Given the following configuration:
|
1015
|
+
|
1016
|
+
```yaml
|
1017
|
+
# config/database.yml
|
1018
|
+
production:
|
1019
|
+
primary:
|
1020
|
+
database: my_database
|
1021
|
+
primary_shard_one:
|
1022
|
+
database: my_database_shard_one
|
718
1023
|
```
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
1024
|
+
|
1025
|
+
Connect to multiple shards:
|
1026
|
+
|
1027
|
+
```ruby
|
1028
|
+
class ApplicationRecord < ActiveRecord::Base
|
1029
|
+
self.abstract_class = true
|
1030
|
+
|
1031
|
+
connects_to shards: {
|
1032
|
+
default: { writing: :primary },
|
1033
|
+
shard_one: { writing: :primary_shard_one }
|
1034
|
+
}
|
723
1035
|
```
|
724
1036
|
|
725
|
-
|
1037
|
+
Swap between shards in your controller / model code:
|
1038
|
+
|
1039
|
+
```ruby
|
1040
|
+
ActiveRecord::Base.connected_to(shard: :shard_one) do
|
1041
|
+
# Read from shard one
|
1042
|
+
end
|
726
1043
|
```
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
1044
|
+
|
1045
|
+
The horizontal sharding API also supports read replicas. See guides for more details.
|
1046
|
+
|
1047
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1048
|
+
|
1049
|
+
* Deprecate `spec_name` in favor of `name` on database configurations.
|
1050
|
+
|
1051
|
+
The accessors for `spec_name` on `configs_for` and `DatabaseConfig` are deprecated. Please use `name` instead.
|
1052
|
+
|
1053
|
+
Deprecated behavior:
|
1054
|
+
|
1055
|
+
```ruby
|
1056
|
+
db_config = ActiveRecord::Base.configs_for(env_name: "development", spec_name: "primary")
|
1057
|
+
db_config.spec_name
|
731
1058
|
```
|
732
1059
|
|
733
|
-
|
1060
|
+
New behavior:
|
734
1061
|
|
735
|
-
|
1062
|
+
```ruby
|
1063
|
+
db_config = ActiveRecord::Base.configs_for(env_name: "development", name: "primary")
|
1064
|
+
db_config.name
|
1065
|
+
```
|
736
1066
|
|
737
|
-
*
|
1067
|
+
*Eileen M. Uchitelle*
|
738
1068
|
|
739
|
-
|
1069
|
+
* Add additional database-specific rake tasks for multi-database users.
|
740
1070
|
|
741
|
-
|
1071
|
+
Previously, `rails db:create`, `rails db:drop`, and `rails db:migrate` were the only rails tasks that could operate on a single
|
1072
|
+
database. For example:
|
742
1073
|
|
743
|
-
|
1074
|
+
```
|
1075
|
+
rails db:create
|
1076
|
+
rails db:create:primary
|
1077
|
+
rails db:create:animals
|
1078
|
+
rails db:drop
|
1079
|
+
rails db:drop:primary
|
1080
|
+
rails db:drop:animals
|
1081
|
+
rails db:migrate
|
1082
|
+
rails db:migrate:primary
|
1083
|
+
rails db:migrate:animals
|
1084
|
+
```
|
744
1085
|
|
745
|
-
|
1086
|
+
With these changes, `rails db:schema:dump`, `rails db:schema:load`, `rails db:structure:dump`, `rails db:structure:load` and
|
1087
|
+
`rails db:test:prepare` can additionally operate on a single database. For example:
|
746
1088
|
|
747
|
-
|
1089
|
+
```
|
1090
|
+
rails db:schema:dump
|
1091
|
+
rails db:schema:dump:primary
|
1092
|
+
rails db:schema:dump:animals
|
1093
|
+
rails db:schema:load
|
1094
|
+
rails db:schema:load:primary
|
1095
|
+
rails db:schema:load:animals
|
1096
|
+
rails db:structure:dump
|
1097
|
+
rails db:structure:dump:primary
|
1098
|
+
rails db:structure:dump:animals
|
1099
|
+
rails db:structure:load
|
1100
|
+
rails db:structure:load:primary
|
1101
|
+
rails db:structure:load:animals
|
1102
|
+
rails db:test:prepare
|
1103
|
+
rails db:test:prepare:primary
|
1104
|
+
rails db:test:prepare:animals
|
1105
|
+
```
|
748
1106
|
|
749
|
-
*
|
1107
|
+
*Kyle Thompson*
|
750
1108
|
|
751
|
-
|
1109
|
+
* Add support for `strict_loading` mode on association declarations.
|
752
1110
|
|
753
|
-
|
1111
|
+
Raise an error if attempting to load a record from an association that has been marked as `strict_loading` unless it was explicitly eager loaded.
|
754
1112
|
|
755
|
-
|
1113
|
+
Usage:
|
756
1114
|
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
dropped in SQL commands:
|
1115
|
+
```ruby
|
1116
|
+
class Developer < ApplicationRecord
|
1117
|
+
has_many :projects, strict_loading: true
|
1118
|
+
end
|
762
1119
|
|
763
|
-
|
1120
|
+
dev = Developer.first
|
1121
|
+
dev.projects.first
|
1122
|
+
# => ActiveRecord::StrictLoadingViolationError: The projects association is marked as strict_loading and cannot be lazily loaded.
|
1123
|
+
```
|
1124
|
+
|
1125
|
+
*Kevin Deisz*
|
764
1126
|
|
765
|
-
|
766
|
-
# => "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)"
|
1127
|
+
* Add support for `strict_loading` mode to prevent lazy loading of records.
|
767
1128
|
|
768
|
-
|
1129
|
+
Raise an error if a parent record is marked as `strict_loading` and attempts to lazily load its associations. This is useful for finding places you may want to preload an association and avoid additional queries.
|
769
1130
|
|
770
|
-
|
771
|
-
# => "[2010-01-01 13:30:00.670277,2011-02-02 19:30:00.745125)"
|
1131
|
+
Usage:
|
772
1132
|
|
773
|
-
|
1133
|
+
```ruby
|
1134
|
+
dev = Developer.strict_loading.first
|
1135
|
+
dev.audit_logs.to_a
|
1136
|
+
# => ActiveRecord::StrictLoadingViolationError: Developer is marked as strict_loading and AuditLog cannot be lazily loaded.
|
1137
|
+
```
|
774
1138
|
|
775
|
-
*
|
776
|
-
array.
|
1139
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*
|
777
1140
|
|
778
|
-
|
1141
|
+
* Add support for PostgreSQL 11+ partitioned indexes when using `upsert_all`.
|
779
1142
|
|
780
|
-
*
|
1143
|
+
*Sebastián Palma*
|
781
1144
|
|
782
|
-
|
1145
|
+
* Adds support for `if_not_exists` to `add_column` and `if_exists` to `remove_column`.
|
783
1146
|
|
784
|
-
|
1147
|
+
Applications can set their migrations to ignore exceptions raised when adding a column that already exists or when removing a column that does not exist.
|
785
1148
|
|
786
|
-
|
787
|
-
more descriptive.
|
1149
|
+
Example Usage:
|
788
1150
|
|
789
|
-
|
1151
|
+
```ruby
|
1152
|
+
class AddColumnTitle < ActiveRecord::Migration[6.1]
|
1153
|
+
def change
|
1154
|
+
add_column :posts, :title, :string, if_not_exists: true
|
1155
|
+
end
|
1156
|
+
end
|
1157
|
+
```
|
790
1158
|
|
791
|
-
|
1159
|
+
```ruby
|
1160
|
+
class RemoveColumnTitle < ActiveRecord::Migration[6.1]
|
1161
|
+
def change
|
1162
|
+
remove_column :posts, :title, if_exists: true
|
1163
|
+
end
|
1164
|
+
end
|
1165
|
+
```
|
792
1166
|
|
793
|
-
*
|
794
|
-
when lock wait timeout exceeded.
|
1167
|
+
*Eileen M. Uchitelle*
|
795
1168
|
|
796
|
-
|
1169
|
+
* Regexp-escape table name for MS SQL Server.
|
797
1170
|
|
798
|
-
|
1171
|
+
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.
|
799
1172
|
|
800
|
-
*
|
1173
|
+
*Larry Reid*
|
801
1174
|
|
802
|
-
*
|
1175
|
+
* Store advisory locks on their own named connection.
|
803
1176
|
|
804
|
-
|
1177
|
+
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.
|
805
1178
|
|
806
|
-
|
1179
|
+
In order to fix this we are storing the advisory lock on a new connection with the connection specification name `AdvisoryLockBase`. The caveat is that we need to maintain at least 2 connections to a database while migrations are running in order to do this.
|
807
1180
|
|
808
|
-
|
1181
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
809
1182
|
|
810
|
-
|
1183
|
+
* Allow schema cache path to be defined in the database configuration file.
|
811
1184
|
|
812
|
-
|
1185
|
+
For example:
|
813
1186
|
|
814
|
-
|
1187
|
+
```yaml
|
1188
|
+
development:
|
1189
|
+
adapter: postgresql
|
1190
|
+
database: blog_development
|
1191
|
+
pool: 5
|
1192
|
+
schema_cache_path: tmp/schema/main.yml
|
1193
|
+
```
|
815
1194
|
|
816
|
-
*
|
1195
|
+
*Katrina Owen*
|
817
1196
|
|
818
|
-
|
1197
|
+
* Deprecate `#remove_connection` in favor of `#remove_connection_pool` when called on the handler.
|
819
1198
|
|
820
|
-
|
821
|
-
`references` only, as `references` can be implicitly called by `where`.
|
1199
|
+
`#remove_connection` is deprecated in order to support returning a `DatabaseConfig` object instead of a `Hash`. Use `#remove_connection_pool`, `#remove_connection` will be removed in 6.2.
|
822
1200
|
|
823
|
-
|
1201
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
824
1202
|
|
825
|
-
|
1203
|
+
* Deprecate `#default_hash` and it's alias `#[]` on database configurations.
|
826
1204
|
|
827
|
-
|
828
|
-
need to generate it, it can be created with `rails g application_record`.
|
1205
|
+
Applications should use `configs_for`. `#default_hash` and `#[]` will be removed in 6.2.
|
829
1206
|
|
830
|
-
*
|
1207
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
831
1208
|
|
832
|
-
*
|
1209
|
+
* Add scale support to `ActiveRecord::Validations::NumericalityValidator`.
|
833
1210
|
|
834
|
-
*
|
1211
|
+
*Gannon McGibbon*
|
835
1212
|
|
836
|
-
*
|
837
|
-
`destroyed_by_association` will now be set to the reflection, matching the
|
838
|
-
behaviour of `has_many` associations.
|
1213
|
+
* Find orphans by looking for missing relations through chaining `where.missing`:
|
839
1214
|
|
840
|
-
|
1215
|
+
Before:
|
841
1216
|
|
842
|
-
|
1217
|
+
```ruby
|
1218
|
+
Post.left_joins(:author).where(authors: { id: nil })
|
1219
|
+
```
|
843
1220
|
|
844
|
-
|
845
|
-
bind values used by the `or` instead. (possibly other cases too)
|
1221
|
+
After:
|
846
1222
|
|
1223
|
+
```ruby
|
1224
|
+
Post.where.missing(:author)
|
847
1225
|
```
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
1226
|
+
|
1227
|
+
*Tom Rossi*
|
1228
|
+
|
1229
|
+
* Ensure `:reading` connections always raise if a write is attempted.
|
1230
|
+
|
1231
|
+
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`.
|
1232
|
+
|
1233
|
+
*Eileen M. Uchitelle*
|
1234
|
+
|
1235
|
+
* Deprecate `"primary"` as the `connection_specification_name` for `ActiveRecord::Base`.
|
1236
|
+
|
1237
|
+
`"primary"` has been deprecated as the `connection_specification_name` for `ActiveRecord::Base` in favor of using `"ActiveRecord::Base"`. This change affects calls to `ActiveRecord::Base.connection_handler.retrieve_connection` and `ActiveRecord::Base.connection_handler.remove_connection`. If you're calling these methods with `"primary"`, please switch to `"ActiveRecord::Base"`.
|
1238
|
+
|
1239
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
1240
|
+
|
1241
|
+
* Add `ActiveRecord::Validations::NumericalityValidator` with
|
1242
|
+
support for casting floats using a database columns' precision value.
|
1243
|
+
|
1244
|
+
*Gannon McGibbon*
|
1245
|
+
|
1246
|
+
* Enforce fresh ETag header after a collection's contents change by adding
|
1247
|
+
ActiveRecord::Relation#cache_key_with_version. This method will be used by
|
1248
|
+
ActionController::ConditionalGet to ensure that when collection cache versioning
|
1249
|
+
is enabled, requests using ConditionalGet don't return the same ETag header
|
1250
|
+
after a collection is modified.
|
1251
|
+
|
1252
|
+
Fixes #38078.
|
1253
|
+
|
1254
|
+
*Aaron Lipman*
|
1255
|
+
|
1256
|
+
* Skip test database when running `db:create` or `db:drop` in development
|
1257
|
+
with `DATABASE_URL` set.
|
1258
|
+
|
1259
|
+
*Brian Buchalter*
|
1260
|
+
|
1261
|
+
* Don't allow mutations on the database configurations hash.
|
1262
|
+
|
1263
|
+
Freeze the configurations hash to disallow directly changing it. If applications need to change the hash, for example to create databases for parallelization, they should use the `DatabaseConfig` object directly.
|
1264
|
+
|
1265
|
+
Before:
|
1266
|
+
|
1267
|
+
```ruby
|
1268
|
+
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
|
1269
|
+
@db_config.configuration_hash.merge!(idle_timeout: "0.02")
|
853
1270
|
```
|
854
1271
|
|
855
|
-
|
1272
|
+
After:
|
856
1273
|
|
857
|
-
|
858
|
-
|
1274
|
+
```ruby
|
1275
|
+
@db_config = ActiveRecord::Base.configurations.configs_for(env_name: "test", spec_name: "primary")
|
1276
|
+
config = @db_config.configuration_hash.merge(idle_timeout: "0.02")
|
1277
|
+
db_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(@db_config.env_name, @db_config.spec_name, config)
|
1278
|
+
```
|
859
1279
|
|
860
|
-
*
|
1280
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
861
1281
|
|
862
|
-
* `
|
863
|
-
`current_scope`, with the exception of `unscoped`.
|
1282
|
+
* Remove `:connection_id` from the `sql.active_record` notification.
|
864
1283
|
|
865
|
-
|
1284
|
+
*Aaron Patterson*, *Rafael Mendonça França*
|
866
1285
|
|
867
|
-
|
1286
|
+
* The `:name` key will no longer be returned as part of `DatabaseConfig#configuration_hash`. Please use `DatabaseConfig#owner_name` instead.
|
868
1287
|
|
869
|
-
*
|
1288
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
870
1289
|
|
871
|
-
|
872
|
-
recognize 't' and 'f' as was previously serialized.
|
1290
|
+
* ActiveRecord's `belongs_to_required_by_default` flag can now be set per model.
|
873
1291
|
|
874
|
-
|
875
|
-
|
876
|
-
whose default false value is deprecated.
|
1292
|
+
You can now opt-out/opt-in specific models from having their associations required
|
1293
|
+
by default.
|
877
1294
|
|
878
|
-
|
1295
|
+
This change is meant to ease the process of migrating all your models to have
|
1296
|
+
their association required.
|
879
1297
|
|
880
|
-
*
|
881
|
-
`in_batches`).
|
1298
|
+
*Edouard Chin*
|
882
1299
|
|
883
|
-
|
884
|
-
until the end of the request or job.
|
1300
|
+
* The `connection_config` method has been deprecated, please use `connection_db_config` instead which will return a `DatabaseConfigurations::DatabaseConfig` instead of a `Hash`.
|
885
1301
|
|
886
|
-
*
|
1302
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
887
1303
|
|
888
|
-
*
|
889
|
-
`ActiveRecord::StatementInvalid` exceptions.
|
1304
|
+
* Retain explicit selections on the base model after applying `includes` and `joins`.
|
890
1305
|
|
891
|
-
|
1306
|
+
Resolves #34889.
|
892
1307
|
|
893
|
-
*
|
1308
|
+
*Patrick Rebsch*
|
894
1309
|
|
895
|
-
|
1310
|
+
* The `database` kwarg is deprecated without replacement because it can't be used for sharding and creates an issue if it's used during a request. Applications that need to create new connections should use `connects_to` instead.
|
896
1311
|
|
897
|
-
*
|
1312
|
+
*Eileen M. Uchitelle*, *John Crepezzi*
|
898
1313
|
|
899
|
-
*
|
1314
|
+
* Allow attributes to be fetched from Arel node groupings.
|
900
1315
|
|
901
|
-
|
902
|
-
inner transaction would still be marked as persisted.
|
1316
|
+
*Jeff Emminger*, *Gannon McGibbon*
|
903
1317
|
|
904
|
-
|
905
|
-
parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted.
|
1318
|
+
* A database URL can now contain a querystring value that contains an equal sign. This is needed to support passing PostgreSQL `options`.
|
906
1319
|
|
907
|
-
*
|
1320
|
+
*Joshua Flanagan*
|
908
1321
|
|
909
|
-
*
|
1322
|
+
* Calling methods like `establish_connection` with a `Hash` which is invalid (eg: no `adapter`) will now raise an error the same way as connections defined in `config/database.yml`.
|
910
1323
|
|
911
|
-
|
912
|
-
state of the transaction you can now use `rollback!`, `commit!` or `nullify!` instead of
|
913
|
-
`set_state(:rolledback)`, `set_state(:committed)`, or `set_state(nil)`.
|
1324
|
+
*John Crepezzi*
|
914
1325
|
|
915
|
-
|
1326
|
+
* Specifying `implicit_order_column` now subsorts the records by primary key if available to ensure deterministic results.
|
916
1327
|
|
917
|
-
*
|
1328
|
+
*Paweł Urbanek*
|
918
1329
|
|
919
|
-
|
1330
|
+
* `where(attr => [])` now loads an empty result without making a query.
|
920
1331
|
|
921
|
-
*
|
922
|
-
without being connected.
|
1332
|
+
*John Hawthorn*
|
923
1333
|
|
924
|
-
|
1334
|
+
* Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
|
925
1335
|
|
926
|
-
*
|
927
|
-
if the child records were deleted before the parent was saved, they would
|
928
|
-
still be persisted. Now, if child records are deleted before the parent is saved
|
929
|
-
on a `has_many :through` association, the child records will not be persisted.
|
1336
|
+
*Hiroyuki Ishii*
|
930
1337
|
|
931
|
-
|
1338
|
+
* Add support for `belongs_to` to `has_many` inversing.
|
932
1339
|
|
933
|
-
*
|
934
|
-
the merged relation into LEFT OUTER JOIN.
|
1340
|
+
*Gannon McGibbon*
|
935
1341
|
|
936
|
-
|
1342
|
+
* Allow length configuration for `has_secure_token` method. The minimum length
|
1343
|
+
is set at 24 characters.
|
937
1344
|
|
1345
|
+
Before:
|
1346
|
+
|
1347
|
+
```ruby
|
1348
|
+
has_secure_token :auth_token
|
938
1349
|
```
|
939
|
-
Author.joins(:posts).merge(Post.joins(:comments))
|
940
|
-
# Before the change:
|
941
|
-
#=> SELECT ... FROM authors INNER JOIN posts ON ... LEFT OUTER JOIN comments ON...
|
942
1350
|
|
943
|
-
|
944
|
-
|
1351
|
+
After:
|
1352
|
+
|
1353
|
+
```ruby
|
1354
|
+
has_secure_token :default_token # 24 characters
|
1355
|
+
has_secure_token :auth_token, length: 36 # 36 characters
|
1356
|
+
has_secure_token :invalid_token, length: 12 # => ActiveRecord::SecureToken::MinimumLengthError
|
945
1357
|
```
|
946
1358
|
|
947
|
-
*
|
1359
|
+
*Bernardo de Araujo*
|
948
1360
|
|
949
|
-
* `
|
950
|
-
`locking_column`, without default value, is null in the database.
|
1361
|
+
* Deprecate `DatabaseConfigurations#to_h`. These connection hashes are still available via `ActiveRecord::Base.configurations.configs_for`.
|
951
1362
|
|
952
|
-
*
|
1363
|
+
*Eileen Uchitelle*, *John Crepezzi*
|
953
1364
|
|
954
|
-
*
|
955
|
-
`locking_column` is null in the database.
|
1365
|
+
* Add `DatabaseConfig#configuration_hash` to return database configuration hashes with symbol keys, and use all symbol-key configuration hashes internally. Deprecate `DatabaseConfig#config` which returns a String-keyed `Hash` with the same values.
|
956
1366
|
|
957
|
-
*
|
1367
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
1368
|
+
|
1369
|
+
* Allow column names to be passed to `remove_index` positionally along with other options.
|
1370
|
+
|
1371
|
+
Passing other options can be necessary to make `remove_index` correctly reversible.
|
958
1372
|
|
959
|
-
|
1373
|
+
Before:
|
1374
|
+
|
1375
|
+
add_index :reports, :report_id # => works
|
1376
|
+
add_index :reports, :report_id, unique: true # => works
|
1377
|
+
remove_index :reports, :report_id # => works
|
1378
|
+
remove_index :reports, :report_id, unique: true # => ArgumentError
|
1379
|
+
|
1380
|
+
After:
|
1381
|
+
|
1382
|
+
remove_index :reports, :report_id, unique: true # => works
|
1383
|
+
|
1384
|
+
*Eugene Kenny*
|
1385
|
+
|
1386
|
+
* Allow bulk `ALTER` statements to drop and recreate indexes with the same name.
|
1387
|
+
|
1388
|
+
*Eugene Kenny*
|
1389
|
+
|
1390
|
+
* `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
|
1391
|
+
|
1392
|
+
*Eugene Kenny*
|
1393
|
+
|
1394
|
+
* Call `while_preventing_writes` directly from `connected_to`.
|
1395
|
+
|
1396
|
+
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)`.
|
1397
|
+
|
1398
|
+
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.
|
1399
|
+
|
1400
|
+
*Eileen M. Uchitelle*
|
1401
|
+
|
1402
|
+
* Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
|
960
1403
|
|
961
1404
|
*Kir Shatrov*
|
962
1405
|
|
963
|
-
*
|
1406
|
+
* Stop trying to read yaml file fixtures when loading Active Record fixtures.
|
1407
|
+
|
1408
|
+
*Gannon McGibbon*
|
1409
|
+
|
1410
|
+
* Deprecate `.reorder(nil)` with `.first` / `.first!` taking non-deterministic result.
|
1411
|
+
|
1412
|
+
To continue taking non-deterministic result, use `.take` / `.take!` instead.
|
964
1413
|
|
965
1414
|
*Ryuta Kamizono*
|
966
1415
|
|
967
|
-
*
|
1416
|
+
* Preserve user supplied joins order as much as possible.
|
1417
|
+
|
1418
|
+
Fixes #36761, #34328, #24281, #12953.
|
968
1419
|
|
969
1420
|
*Ryuta Kamizono*
|
970
1421
|
|
971
|
-
*
|
1422
|
+
* Allow `matches_regex` and `does_not_match_regexp` on the MySQL Arel visitor.
|
972
1423
|
|
973
|
-
|
1424
|
+
*James Pearson*
|
974
1425
|
|
975
|
-
|
1426
|
+
* Allow specifying fixtures to be ignored by setting `ignore` in YAML file's '_fixture' section.
|
976
1427
|
|
977
|
-
*
|
978
|
-
in `ActiveSupport::Cache`. This also means that `ActiveRecord::Base#cache_key` will now return a stable key
|
979
|
-
that does not include a timestamp any more.
|
1428
|
+
*Tongfei Gao*
|
980
1429
|
|
981
|
-
|
982
|
-
until you set `ActiveRecord::Base.cache_versioning = true`. That's the setting for all new apps on Rails 5.2+
|
1430
|
+
* Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
|
983
1431
|
|
984
|
-
*
|
1432
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
985
1433
|
|
986
|
-
*
|
1434
|
+
* Add a warning for enum elements with 'not_' prefix.
|
987
1435
|
|
988
|
-
|
1436
|
+
class Foo
|
1437
|
+
enum status: [:sent, :not_sent]
|
1438
|
+
end
|
989
1439
|
|
990
|
-
*
|
1440
|
+
*Edu Depetris*
|
991
1441
|
|
992
|
-
|
1442
|
+
* Make currency symbols optional for money column type in PostgreSQL.
|
993
1443
|
|
994
|
-
*
|
1444
|
+
*Joel Schneider*
|
995
1445
|
|
996
|
-
*
|
1446
|
+
* Add support for beginless ranges, introduced in Ruby 2.7.
|
997
1447
|
|
998
|
-
*
|
1448
|
+
*Josh Goodall*
|
999
1449
|
|
1000
|
-
*
|
1001
|
-
when the current migration does not exist.
|
1450
|
+
* Add `database_exists?` method to connection adapters to check if a database exists.
|
1002
1451
|
|
1003
|
-
*
|
1452
|
+
*Guilherme Mansur*
|
1004
1453
|
|
1005
|
-
*
|
1454
|
+
* Loading the schema for a model that has no `table_name` raises a `TableNotSpecified` error.
|
1006
1455
|
|
1007
|
-
*
|
1456
|
+
*Guilherme Mansur*, *Eugene Kenny*
|
1008
1457
|
|
1009
|
-
*
|
1458
|
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
1010
1459
|
|
1011
|
-
|
1012
|
-
See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
|
1460
|
+
Fixes #36022.
|
1013
1461
|
|
1014
1462
|
*Ryuta Kamizono*
|
1015
1463
|
|
1016
|
-
*
|
1464
|
+
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
1017
1465
|
|
1018
|
-
|
1466
|
+
Fixes #36465.
|
1467
|
+
|
1468
|
+
*Jeff Doering*
|
1469
|
+
|
1470
|
+
* Add support for multiple databases to `rails db:abort_if_pending_migrations`.
|
1471
|
+
|
1472
|
+
*Mark Lee*
|
1473
|
+
|
1474
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
1475
|
+
|
1476
|
+
*Martin R. Schuster*
|
1477
|
+
|
1478
|
+
* Fix invalid schema when primary key column has a comment.
|
1479
|
+
|
1480
|
+
Fixes #29966.
|
1481
|
+
|
1482
|
+
*Guilherme Goettems Schneider*
|
1483
|
+
|
1484
|
+
* Fix table comment also being applied to the primary key column.
|
1485
|
+
|
1486
|
+
*Guilherme Goettems Schneider*
|
1019
1487
|
|
1020
|
-
*
|
1021
|
-
Previously this method always returned an empty array.
|
1488
|
+
* Allow generated `create_table` migrations to include or skip timestamps.
|
1022
1489
|
|
1023
|
-
*
|
1490
|
+
*Michael Duchemin*
|
1024
1491
|
|
1025
1492
|
|
1026
|
-
Please check [
|
1493
|
+
Please check [6-0-stable](https://github.com/rails/rails/blob/6-0-stable/activerecord/CHANGELOG.md) for previous changes.
|