activerecord 5.2.8.1 → 6.0.0.beta1
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 +299 -816
- data/MIT-LICENSE +3 -1
- data/README.rdoc +1 -1
- data/examples/performance.rb +1 -1
- data/lib/active_record/aggregations.rb +4 -2
- data/lib/active_record/associations/association.rb +35 -19
- data/lib/active_record/associations/association_scope.rb +4 -6
- data/lib/active_record/associations/belongs_to_association.rb +36 -42
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +0 -4
- data/lib/active_record/associations/builder/belongs_to.rb +14 -50
- data/lib/active_record/associations/builder/collection_association.rb +3 -3
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +17 -38
- data/lib/active_record/associations/collection_association.rb +11 -25
- data/lib/active_record/associations/collection_proxy.rb +32 -6
- data/lib/active_record/associations/foreign_association.rb +7 -0
- data/lib/active_record/associations/has_many_association.rb +1 -1
- data/lib/active_record/associations/has_many_through_association.rb +25 -18
- data/lib/active_record/associations/has_one_association.rb +28 -30
- data/lib/active_record/associations/has_one_through_association.rb +5 -5
- data/lib/active_record/associations/join_dependency/join_association.rb +11 -26
- data/lib/active_record/associations/join_dependency/join_part.rb +2 -2
- data/lib/active_record/associations/join_dependency.rb +15 -20
- data/lib/active_record/associations/preloader/association.rb +1 -2
- data/lib/active_record/associations/preloader.rb +32 -29
- data/lib/active_record/associations/singular_association.rb +2 -16
- data/lib/active_record/associations.rb +16 -12
- data/lib/active_record/attribute_assignment.rb +7 -10
- data/lib/active_record/attribute_methods/dirty.rb +64 -26
- data/lib/active_record/attribute_methods/primary_key.rb +8 -7
- data/lib/active_record/attribute_methods/read.rb +16 -48
- data/lib/active_record/attribute_methods/serialization.rb +1 -1
- data/lib/active_record/attribute_methods/time_zone_conversion.rb +1 -1
- data/lib/active_record/attribute_methods/write.rb +15 -16
- data/lib/active_record/attribute_methods.rb +34 -56
- data/lib/active_record/autosave_association.rb +7 -21
- data/lib/active_record/base.rb +2 -2
- data/lib/active_record/callbacks.rb +3 -17
- data/lib/active_record/coders/yaml_column.rb +1 -13
- data/lib/active_record/collection_cache_key.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +13 -36
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +9 -0
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +25 -84
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +17 -14
- data/lib/active_record/connection_adapters/abstract/quoting.rb +5 -11
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +15 -11
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +30 -13
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +0 -2
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +41 -27
- data/lib/active_record/connection_adapters/abstract/transaction.rb +81 -52
- data/lib/active_record/connection_adapters/abstract_adapter.rb +95 -31
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +65 -90
- data/lib/active_record/connection_adapters/connection_specification.rb +52 -42
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +5 -9
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +29 -7
- data/lib/active_record/connection_adapters/mysql/quoting.rb +1 -1
- data/lib/active_record/connection_adapters/mysql/schema_creation.rb +3 -4
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +65 -10
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +8 -4
- data/lib/active_record/connection_adapters/postgresql/column.rb +1 -2
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +16 -1
- data/lib/active_record/connection_adapters/postgresql/oid/array.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/bit.rb +1 -4
- data/lib/active_record/connection_adapters/postgresql/oid/hstore.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/legacy_point.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/point.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/type_map_initializer.rb +9 -7
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +4 -4
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +11 -36
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +9 -2
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +38 -20
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +2 -1
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +75 -56
- data/lib/active_record/connection_adapters/schema_cache.rb +5 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +5 -5
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +14 -9
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +95 -62
- data/lib/active_record/connection_handling.rb +132 -26
- data/lib/active_record/core.rb +75 -52
- data/lib/active_record/counter_cache.rb +4 -29
- 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 +74 -0
- data/lib/active_record/database_configurations.rb +184 -0
- data/lib/active_record/enum.rb +22 -7
- data/lib/active_record/errors.rb +24 -21
- data/lib/active_record/explain.rb +1 -1
- 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 +153 -0
- data/lib/active_record/fixture_set/table_rows.rb +47 -0
- data/lib/active_record/fixtures.rb +140 -472
- data/lib/active_record/gem_version.rb +4 -4
- data/lib/active_record/inheritance.rb +12 -2
- data/lib/active_record/integration.rb +56 -16
- data/lib/active_record/internal_metadata.rb +5 -1
- data/lib/active_record/locking/optimistic.rb +2 -2
- data/lib/active_record/locking/pessimistic.rb +3 -3
- data/lib/active_record/log_subscriber.rb +7 -26
- data/lib/active_record/migration/command_recorder.rb +35 -5
- data/lib/active_record/migration/compatibility.rb +34 -16
- data/lib/active_record/migration.rb +38 -37
- data/lib/active_record/model_schema.rb +30 -9
- data/lib/active_record/nested_attributes.rb +2 -2
- data/lib/active_record/no_touching.rb +7 -0
- data/lib/active_record/persistence.rb +18 -7
- data/lib/active_record/query_cache.rb +11 -4
- data/lib/active_record/querying.rb +19 -11
- data/lib/active_record/railtie.rb +71 -60
- data/lib/active_record/railties/collection_cache_association_loading.rb +34 -0
- data/lib/active_record/railties/controller_runtime.rb +30 -35
- data/lib/active_record/railties/databases.rake +94 -43
- data/lib/active_record/reflection.rb +60 -44
- data/lib/active_record/relation/batches.rb +13 -10
- data/lib/active_record/relation/calculations.rb +38 -28
- data/lib/active_record/relation/delegation.rb +4 -13
- data/lib/active_record/relation/finder_methods.rb +12 -25
- data/lib/active_record/relation/merger.rb +2 -6
- data/lib/active_record/relation/predicate_builder/array_handler.rb +5 -4
- data/lib/active_record/relation/predicate_builder/association_query_value.rb +1 -4
- data/lib/active_record/relation/predicate_builder/base_handler.rb +1 -2
- data/lib/active_record/relation/predicate_builder/basic_object_handler.rb +1 -2
- data/lib/active_record/relation/predicate_builder/polymorphic_array_value.rb +1 -4
- data/lib/active_record/relation/predicate_builder/range_handler.rb +3 -23
- data/lib/active_record/relation/predicate_builder.rb +4 -6
- data/lib/active_record/relation/query_attribute.rb +15 -12
- data/lib/active_record/relation/query_methods.rb +29 -52
- data/lib/active_record/relation/where_clause.rb +4 -0
- data/lib/active_record/relation/where_clause_factory.rb +1 -2
- data/lib/active_record/relation.rb +150 -69
- data/lib/active_record/result.rb +30 -11
- data/lib/active_record/sanitization.rb +2 -39
- data/lib/active_record/schema.rb +1 -10
- data/lib/active_record/schema_dumper.rb +12 -6
- data/lib/active_record/schema_migration.rb +4 -0
- data/lib/active_record/scoping/default.rb +10 -3
- data/lib/active_record/scoping/named.rb +10 -14
- data/lib/active_record/scoping.rb +9 -8
- data/lib/active_record/statement_cache.rb +32 -5
- data/lib/active_record/store.rb +39 -8
- data/lib/active_record/table_metadata.rb +1 -4
- data/lib/active_record/tasks/database_tasks.rb +89 -23
- data/lib/active_record/tasks/mysql_database_tasks.rb +2 -4
- data/lib/active_record/tasks/postgresql_database_tasks.rb +5 -7
- data/lib/active_record/tasks/sqlite_database_tasks.rb +2 -8
- data/lib/active_record/test_databases.rb +38 -0
- data/lib/active_record/test_fixtures.rb +224 -0
- data/lib/active_record/timestamp.rb +4 -6
- data/lib/active_record/transactions.rb +3 -22
- data/lib/active_record/translation.rb +1 -1
- data/lib/active_record/type/adapter_specific_registry.rb +1 -8
- data/lib/active_record/type.rb +3 -4
- data/lib/active_record/type_caster/connection.rb +1 -6
- data/lib/active_record/type_caster/map.rb +1 -4
- data/lib/active_record/validations/uniqueness.rb +13 -25
- data/lib/active_record.rb +2 -1
- 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/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 +63 -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 +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.rb +16 -0
- data/lib/arel/nodes/values_list.rb +24 -0
- data/lib/arel/nodes/window.rb +126 -0
- data/lib/arel/nodes/with.rb +11 -0
- data/lib/arel/nodes.rb +67 -0
- data/lib/arel/order_predications.rb +13 -0
- data/lib/arel/predications.rb +257 -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 +199 -0
- data/lib/arel/visitors/dot.rb +292 -0
- data/lib/arel/visitors/ibm_db.rb +21 -0
- data/lib/arel/visitors/informix.rb +56 -0
- data/lib/arel/visitors/mssql.rb +143 -0
- data/lib/arel/visitors/mysql.rb +83 -0
- data/lib/arel/visitors/oracle.rb +159 -0
- data/lib/arel/visitors/oracle12.rb +67 -0
- data/lib/arel/visitors/postgresql.rb +116 -0
- data/lib/arel/visitors/sqlite.rb +39 -0
- data/lib/arel/visitors/to_sql.rb +913 -0
- data/lib/arel/visitors/visitor.rb +42 -0
- data/lib/arel/visitors/where_sql.rb +23 -0
- data/lib/arel/visitors.rb +20 -0
- data/lib/arel/window_predications.rb +9 -0
- data/lib/arel.rb +44 -0
- data/lib/rails/generators/active_record/migration/migration_generator.rb +2 -5
- data/lib/rails/generators/active_record/migration.rb +14 -1
- data/lib/rails/generators/active_record/model/model_generator.rb +1 -0
- metadata +107 -29
data/CHANGELOG.md
CHANGED
@@ -1,171 +1,80 @@
|
|
1
|
-
## Rails
|
2
|
-
|
3
|
-
* Change ActiveRecord::Coders::YAMLColumn default to safe_load
|
4
|
-
|
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
|
-
```
|
25
|
-
|
26
|
-
[CVE-2022-32224]
|
27
|
-
|
28
|
-
|
29
|
-
## Rails 5.2.8 (May 09, 2022) ##
|
30
|
-
|
31
|
-
* No changes.
|
32
|
-
|
33
|
-
|
34
|
-
## Rails 5.2.7.1 (April 26, 2022) ##
|
35
|
-
|
36
|
-
* No changes.
|
37
|
-
|
38
|
-
|
39
|
-
## Rails 5.2.7 (March 10, 2022) ##
|
40
|
-
|
41
|
-
* No changes.
|
42
|
-
|
43
|
-
|
44
|
-
## Rails 5.2.6.3 (March 08, 2022) ##
|
45
|
-
|
46
|
-
* No changes.
|
47
|
-
|
48
|
-
|
49
|
-
## Rails 5.2.6.2 (February 11, 2022) ##
|
50
|
-
|
51
|
-
* No changes.
|
52
|
-
|
53
|
-
|
54
|
-
## Rails 5.2.6.1 (February 11, 2022) ##
|
55
|
-
|
56
|
-
* No changes.
|
57
|
-
|
58
|
-
|
59
|
-
## Rails 5.2.6 (May 05, 2021) ##
|
60
|
-
|
61
|
-
* No changes.
|
1
|
+
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
62
2
|
|
3
|
+
* Remove deprecated `#set_state` from the transaction object.
|
63
4
|
|
64
|
-
|
65
|
-
|
66
|
-
* No changes.
|
67
|
-
|
68
|
-
|
69
|
-
## Rails 5.2.4.6 (May 05, 2021) ##
|
70
|
-
|
71
|
-
* No changes.
|
72
|
-
|
73
|
-
|
74
|
-
## Rails 5.2.4.5 (February 10, 2021) ##
|
75
|
-
|
76
|
-
* Fix possible DoS vector in PostgreSQL money type
|
77
|
-
|
78
|
-
Carefully crafted input can cause a DoS via the regular expressions used
|
79
|
-
for validating the money format in the PostgreSQL adapter. This patch
|
80
|
-
fixes the regexp.
|
81
|
-
|
82
|
-
Thanks to @dee-see from Hackerone for this patch!
|
83
|
-
|
84
|
-
[CVE-2021-22880]
|
85
|
-
|
86
|
-
*Aaron Patterson*
|
87
|
-
|
88
|
-
|
89
|
-
## Rails 5.2.4.4 (September 09, 2020) ##
|
90
|
-
|
91
|
-
* No changes.
|
92
|
-
|
93
|
-
|
94
|
-
## Rails 5.2.4.3 (May 18, 2020) ##
|
5
|
+
*Rafael Mendonça França*
|
95
6
|
|
96
|
-
*
|
7
|
+
* Remove deprecated `#supports_statement_cache?` from the database adapters.
|
97
8
|
|
98
|
-
|
9
|
+
*Rafael Mendonça França*
|
99
10
|
|
100
|
-
*
|
11
|
+
* Remove deprecated `#insert_fixtures` from the database adapters.
|
101
12
|
|
13
|
+
*Rafael Mendonça França*
|
102
14
|
|
103
|
-
|
15
|
+
* Remove deprecated `ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?`.
|
104
16
|
|
105
|
-
*
|
17
|
+
*Rafael Mendonça França*
|
106
18
|
|
19
|
+
* Do not allow passing the column name to `sum` when a block is passed.
|
107
20
|
|
108
|
-
|
21
|
+
*Rafael Mendonça França*
|
109
22
|
|
110
|
-
*
|
23
|
+
* Do not allow passing the column name to `count` when a block is passed.
|
111
24
|
|
112
|
-
|
113
|
-
associations, the callback for a `has_many` association was run while
|
114
|
-
another instance of the same callback on the same association hadn't
|
115
|
-
finished running. When control returned to the first instance of the
|
116
|
-
callback, the instance variable had changed, and subsequent associated
|
117
|
-
records weren't saved correctly. Specifically, the ID field for the
|
118
|
-
`belongs_to` corresponding to the `has_many` was `nil`.
|
25
|
+
*Rafael Mendonça França*
|
119
26
|
|
120
|
-
|
27
|
+
* Remove delegation of missing methods in a relation to arel.
|
121
28
|
|
122
|
-
*
|
29
|
+
*Rafael Mendonça França*
|
123
30
|
|
124
|
-
*
|
31
|
+
* Remove delegation of missing methods in a relation to private methods of the class.
|
125
32
|
|
126
|
-
|
33
|
+
*Rafael Mendonça França*
|
127
34
|
|
128
|
-
|
35
|
+
* Deprecate `config.activerecord.sqlite3.represent_boolean_as_integer`.
|
129
36
|
|
130
|
-
*
|
37
|
+
*Rafael Mendonça França*
|
131
38
|
|
132
|
-
|
39
|
+
* Change `SQLite3Adapter` to always represent boolean values as integers.
|
133
40
|
|
134
|
-
*
|
41
|
+
*Rafael Mendonça França*
|
135
42
|
|
136
|
-
|
43
|
+
* Remove ability to specify a timestamp name for `#cache_key`.
|
137
44
|
|
138
|
-
*
|
45
|
+
*Rafael Mendonça França*
|
139
46
|
|
140
|
-
*
|
141
|
-
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
47
|
+
* Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
|
142
48
|
|
143
|
-
|
49
|
+
*Rafael Mendonça França*
|
144
50
|
|
145
|
-
|
51
|
+
* Remove deprecated `expand_hash_conditions_for_aggregates`.
|
146
52
|
|
53
|
+
*Rafael Mendonça França*
|
147
54
|
|
148
|
-
|
55
|
+
* Set polymorphic type column to NULL on `dependent: :nullify` strategy.
|
149
56
|
|
150
|
-
|
57
|
+
On polymorphic associations both the foreign key and the foreign type columns will be set to NULL.
|
151
58
|
|
152
|
-
|
59
|
+
*Laerti Papa*
|
153
60
|
|
154
|
-
|
61
|
+
* Allow permitted instance of `ActionController::Parameters` as argument of `ActiveRecord::Relation#exists?`.
|
155
62
|
|
156
|
-
*
|
63
|
+
*Gannon McGibbon*
|
157
64
|
|
158
|
-
|
65
|
+
* Add support for endless ranges introduces in Ruby 2.6.
|
159
66
|
|
160
|
-
*
|
67
|
+
*Greg Navis*
|
161
68
|
|
162
|
-
|
69
|
+
* Deprecate passing `migrations_paths` to `connection.assume_migrated_upto_version`.
|
163
70
|
|
164
71
|
*Ryuta Kamizono*
|
165
72
|
|
166
|
-
*
|
73
|
+
* MySQL: `ROW_FORMAT=DYNAMIC` create table option by default.
|
167
74
|
|
168
|
-
|
75
|
+
Since MySQL 5.7.9, the `innodb_default_row_format` option defines the default row
|
76
|
+
format for InnoDB tables. The default setting is `DYNAMIC`.
|
77
|
+
The row format is required for indexing on `varchar(255)` with `utf8mb4` columns.
|
169
78
|
|
170
79
|
*Ryuta Kamizono*
|
171
80
|
|
@@ -173,6 +82,10 @@
|
|
173
82
|
|
174
83
|
*Gannon McGibbon*
|
175
84
|
|
85
|
+
* Allow disabling scopes generated by `ActiveRecord.enum`.
|
86
|
+
|
87
|
+
*Alfred Dominic*
|
88
|
+
|
176
89
|
* Ensure that `delete_all` on collection proxy returns affected count.
|
177
90
|
|
178
91
|
*Ryuta Kamizono*
|
@@ -181,17 +94,21 @@
|
|
181
94
|
|
182
95
|
*Gannon McGibbon*
|
183
96
|
|
97
|
+
* Add the ability to prevent writes to a database for the duration of a block.
|
184
98
|
|
185
|
-
|
99
|
+
Allows the application to prevent writes to a database. This can be useful when
|
100
|
+
you're building out multiple databases and want to make sure you're not sending
|
101
|
+
writes when you want a read.
|
186
102
|
|
187
|
-
|
103
|
+
If `while_preventing_writes` is called and the query is considered a write
|
104
|
+
query the database will raise an exception regardless of whether the database
|
105
|
+
user is able to write.
|
188
106
|
|
107
|
+
This is not meant to be a catch-all for write queries but rather a way to enforce
|
108
|
+
read-only queries without opening a second connection. One purpose of this is to
|
109
|
+
catch accidental writes, not all writes.
|
189
110
|
|
190
|
-
|
191
|
-
|
192
|
-
* Do not ignore the scoping with query methods in the scope block.
|
193
|
-
|
194
|
-
*Ryuta Kamizono*
|
111
|
+
*Eileen M. Uchitelle*
|
195
112
|
|
196
113
|
* Allow aliased attributes to be used in `#update_columns` and `#update`.
|
197
114
|
|
@@ -199,8 +116,7 @@
|
|
199
116
|
|
200
117
|
* Allow spaces in postgres table names.
|
201
118
|
|
202
|
-
Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres
|
203
|
-
adapter.
|
119
|
+
Fixes issue where "user post" is misinterpreted as "\"user\".\"post\"" when quoting table names with the postgres adapter.
|
204
120
|
|
205
121
|
*Gannon McGibbon*
|
206
122
|
|
@@ -233,852 +149,419 @@
|
|
233
149
|
|
234
150
|
*Dmitry Tsepelev*
|
235
151
|
|
236
|
-
*
|
237
|
-
|
238
|
-
*Emmanuel Byrd*
|
239
|
-
|
240
|
-
* `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
|
241
|
-
if the attribute does not exist.
|
242
|
-
|
243
|
-
*Sean Griffin*
|
244
|
-
|
245
|
-
* Do not use prepared statement in queries that have a large number of binds.
|
246
|
-
|
247
|
-
*Ryuta Kamizono*
|
248
|
-
|
249
|
-
* Fix query cache to load before first request.
|
250
|
-
|
251
|
-
*Eileen M. Uchitelle*
|
252
|
-
|
253
|
-
* Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
|
254
|
-
|
255
|
-
Fixes #33056.
|
256
|
-
|
257
|
-
*Federico Martinez*
|
258
|
-
|
259
|
-
* Fix duplicated record creation when using nested attributes with `create_with`.
|
260
|
-
|
261
|
-
*Darwin Wu*
|
262
|
-
|
263
|
-
* Fix regression setting children record in parent `before_save` callback.
|
264
|
-
|
265
|
-
*Guo Xiang Tan*
|
266
|
-
|
267
|
-
* Prevent leaking of user's DB credentials on `rails db:create` failure.
|
268
|
-
|
269
|
-
*bogdanvlviv*
|
270
|
-
|
271
|
-
* Clear mutation tracker before continuing the around callbacks.
|
272
|
-
|
273
|
-
*Yuya Tanaka*
|
274
|
-
|
275
|
-
* Prevent deadlocks when waiting for connection from pool.
|
152
|
+
* Make the implicit order column configurable.
|
276
153
|
|
277
|
-
|
154
|
+
When calling ordered finder methods such as +first+ or +last+ without an
|
155
|
+
explicit order clause, ActiveRecord sorts records by primary key. This can
|
156
|
+
result in unpredictable and surprising behaviour when the primary key is
|
157
|
+
not an auto-incrementing integer, for example when it's a UUID. This change
|
158
|
+
makes it possible to override the column used for implicit ordering such
|
159
|
+
that +first+ and +last+ will return more predictable results.
|
278
160
|
|
279
|
-
|
280
|
-
|
281
|
-
*Ryuta Kamizono*
|
282
|
-
|
283
|
-
* Fix numericality validator not to be affected by custom getter.
|
284
|
-
|
285
|
-
*Ryuta Kamizono*
|
286
|
-
|
287
|
-
* Fix bulk change table ignores comment option on PostgreSQL.
|
288
|
-
|
289
|
-
*Yoshiyuki Kinjo*
|
290
|
-
|
291
|
-
|
292
|
-
## Rails 5.2.1.1 (November 27, 2018) ##
|
293
|
-
|
294
|
-
* No changes.
|
295
|
-
|
296
|
-
|
297
|
-
## Rails 5.2.1 (August 07, 2018) ##
|
298
|
-
|
299
|
-
* PostgreSQL: Support new relkind for partitioned tables.
|
300
|
-
|
301
|
-
Fixes #33008.
|
302
|
-
|
303
|
-
*Yannick Schutz*
|
304
|
-
|
305
|
-
* Rollback parent transaction when children fails to update.
|
306
|
-
|
307
|
-
*Guillaume Malette*
|
308
|
-
|
309
|
-
* Fix default value for MySQL time types with specified precision.
|
310
|
-
|
311
|
-
*Nikolay Kondratyev*
|
312
|
-
|
313
|
-
* Fix `touch` option to behave consistently with `Persistence#touch` method.
|
314
|
-
|
315
|
-
*Ryuta Kamizono*
|
316
|
-
|
317
|
-
* Fix `save` in `after_create_commit` won't invoke extra `after_create_commit`.
|
318
|
-
|
319
|
-
Fixes #32831.
|
320
|
-
|
321
|
-
*Ryuta Kamizono*
|
322
|
-
|
323
|
-
* Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
|
324
|
-
|
325
|
-
*Brian Durand*
|
326
|
-
|
327
|
-
* Fix parent record should not get saved with duplicate children records.
|
328
|
-
|
329
|
-
Fixes #32940.
|
330
|
-
|
331
|
-
*Santosh Wadghule*
|
332
|
-
|
333
|
-
* Fix that association's after_touch is not called with counter cache.
|
334
|
-
|
335
|
-
Fixes #31559.
|
336
|
-
|
337
|
-
*Ryuta Kamizono*
|
338
|
-
|
339
|
-
* `becomes` should clear the mutation tracker which is created in `after_initialize`.
|
340
|
-
|
341
|
-
Fixes #32867.
|
342
|
-
|
343
|
-
*Ryuta Kamizono*
|
344
|
-
|
345
|
-
* Allow a belonging to parent object to be created from a new record.
|
346
|
-
|
347
|
-
*Jolyon Pawlyn*
|
348
|
-
|
349
|
-
* Fix that building record with assigning multiple has_one associations
|
350
|
-
wrongly persists through record.
|
351
|
-
|
352
|
-
Fixes #32511.
|
353
|
-
|
354
|
-
*Sam DeCesare*
|
355
|
-
|
356
|
-
* Fix relation merging when one of the relations is going to skip the
|
357
|
-
query cache.
|
358
|
-
|
359
|
-
*James Williams*
|
360
|
-
|
361
|
-
|
362
|
-
## Rails 5.2.0 (April 09, 2018) ##
|
363
|
-
|
364
|
-
* MySQL: Support mysql2 0.5.x.
|
365
|
-
|
366
|
-
*Aaron Stone*
|
367
|
-
|
368
|
-
* Apply time column precision on assignment.
|
369
|
-
|
370
|
-
PR #20317 changed the behavior of datetime columns so that when they
|
371
|
-
have a specified precision then on assignment the value is rounded to
|
372
|
-
that precision. This behavior is now applied to time columns as well.
|
373
|
-
|
374
|
-
Fixes #30301.
|
375
|
-
|
376
|
-
*Andrew White*
|
377
|
-
|
378
|
-
* Normalize time column values for SQLite database.
|
379
|
-
|
380
|
-
For legacy reasons, time columns in SQLite are stored as full datetimes
|
381
|
-
because until #24542 the quoting for time columns didn't remove the date
|
382
|
-
component. To ensure that values are consistent we now normalize the
|
383
|
-
date component to 2001-01-01 on reading and writing.
|
384
|
-
|
385
|
-
*Andrew White*
|
386
|
-
|
387
|
-
* Ensure that the date component is removed when quoting times.
|
388
|
-
|
389
|
-
PR #24542 altered the quoting for time columns so that the date component
|
390
|
-
was removed however it only removed it when it was 2001-01-01. Now the
|
391
|
-
date component is removed irrespective of what the date is.
|
392
|
-
|
393
|
-
*Andrew White*
|
394
|
-
|
395
|
-
* Fix `dependent: :destroy` issue for has_one/belongs_to relationship where
|
396
|
-
the parent class was getting deleted when the child was not.
|
397
|
-
|
398
|
-
Fixes #32022.
|
399
|
-
|
400
|
-
*Fernando Gorodscy*
|
401
|
-
|
402
|
-
* Whitelist `NULLS FIRST` and `NULLS LAST` in order clauses too.
|
403
|
-
|
404
|
-
*Xavier Noria*
|
405
|
-
|
406
|
-
* Fix that after commit callbacks on update does not triggered when optimistic locking is enabled.
|
407
|
-
|
408
|
-
*Ryuta Kamizono*
|
161
|
+
Example:
|
409
162
|
|
410
|
-
|
411
|
-
|
412
|
-
|
163
|
+
class Project < ActiveRecord::Base
|
164
|
+
self.implicit_order_column = "created_at"
|
165
|
+
end
|
413
166
|
|
414
|
-
|
167
|
+
*Tekin Suleyman*
|
415
168
|
|
416
|
-
|
169
|
+
* Bump minimum PostgreSQL version to 9.3.
|
417
170
|
|
418
|
-
*
|
171
|
+
*Yasuo Honda*
|
419
172
|
|
420
|
-
|
173
|
+
* Values of enum are frozen, raising an error when attempting to modify them.
|
421
174
|
|
422
|
-
*
|
175
|
+
*Emmanuel Byrd*
|
423
176
|
|
424
|
-
*
|
177
|
+
* Move `ActiveRecord::StatementInvalid` SQL to error property and include binds as separate error property.
|
425
178
|
|
426
|
-
|
179
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception_class` now requires `binds` to be passed as the last argument.
|
427
180
|
|
428
|
-
|
429
|
-
Using a `Relation` for performing queries is the prefered API.
|
181
|
+
`ActiveRecord::ConnectionAdapters::AbstractAdapter#translate_exception` now requires `message`, `sql`, and `binds` to be passed as keyword arguments.
|
430
182
|
|
431
|
-
|
183
|
+
Subclasses of `ActiveRecord::StatementInvalid` must now provide `sql:` and `binds:` arguments to `super`.
|
432
184
|
|
433
|
-
|
185
|
+
Example:
|
434
186
|
|
435
187
|
```
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
188
|
+
class MySubclassedError < ActiveRecord::StatementInvalid
|
189
|
+
def initialize(message, sql:, binds:)
|
190
|
+
super(message, sql: sql, binds: binds)
|
191
|
+
end
|
192
|
+
end
|
441
193
|
```
|
442
194
|
|
443
|
-
|
444
|
-
|
445
|
-
*Yutaro Kanagawa*
|
446
|
-
|
447
|
-
* Fix `count(:all)` with eager loading and having an order other than the driving table.
|
448
|
-
|
449
|
-
Fixes #31783.
|
450
|
-
|
451
|
-
*Ryuta Kamizono*
|
452
|
-
|
453
|
-
* Clear the transaction state when an Active Record object is duped.
|
454
|
-
|
455
|
-
Fixes #31670.
|
456
|
-
|
457
|
-
*Yuriy Ustushenko*
|
458
|
-
|
459
|
-
* Support for PostgreSQL foreign tables.
|
460
|
-
|
461
|
-
*fatkodima*
|
462
|
-
|
463
|
-
* Fix relation merger issue with `left_outer_joins`.
|
464
|
-
|
465
|
-
*Mehmet Emin İNAÇ*
|
466
|
-
|
467
|
-
* Don't allow destroyed object mutation after `save` or `save!` is called.
|
468
|
-
|
469
|
-
*Ryuta Kamizono*
|
470
|
-
|
471
|
-
* Take into account association conditions when deleting through records.
|
472
|
-
|
473
|
-
Fixes #18424.
|
474
|
-
|
475
|
-
*Piotr Jakubowski*
|
195
|
+
*Gannon McGibbon*
|
476
196
|
|
477
|
-
*
|
197
|
+
* Add an `:if_not_exists` option to `create_table`.
|
478
198
|
|
479
|
-
|
199
|
+
Example:
|
480
200
|
|
481
|
-
|
482
|
-
|
483
|
-
has_many :books, through: :author
|
484
|
-
has_many :subscriptions, through: :books
|
201
|
+
create_table :posts, if_not_exists: true do |t|
|
202
|
+
t.string :title
|
485
203
|
end
|
486
204
|
|
487
|
-
|
488
|
-
has_one :post
|
489
|
-
has_many :books
|
490
|
-
has_many :subscriptions, through: :books
|
491
|
-
end
|
205
|
+
That would execute:
|
492
206
|
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
end
|
207
|
+
CREATE TABLE IF NOT EXISTS posts (
|
208
|
+
...
|
209
|
+
)
|
497
210
|
|
498
|
-
|
499
|
-
|
500
|
-
end
|
211
|
+
If the table already exists, `if_not_exists: false` (the default) raises an
|
212
|
+
exception whereas `if_not_exists: true` does nothing.
|
501
213
|
|
502
|
-
|
214
|
+
*fatkodima*, *Stefan Kanev*
|
503
215
|
|
504
|
-
|
216
|
+
* Defining an Enum as a Hash with blank key, or as an Array with a blank value, now raises an `ArgumentError`.
|
505
217
|
|
506
|
-
|
218
|
+
*Christophe Maximin*
|
507
219
|
|
508
|
-
|
509
|
-
just like it would if `post` were persisted.
|
220
|
+
* Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
|
510
221
|
|
511
|
-
|
222
|
+
*Gannon McGibbon*
|
512
223
|
|
513
|
-
|
224
|
+
* `update_columns` now correctly raises `ActiveModel::MissingAttributeError`
|
225
|
+
if the attribute does not exist.
|
514
226
|
|
515
|
-
*
|
516
|
-
The `first(n)` finder now respects the `limit()`, making it consistent
|
517
|
-
with `relation.to_a.first(n)`, and also with the behavior of `last(n)`.
|
227
|
+
*Sean Griffin*
|
518
228
|
|
519
|
-
|
229
|
+
* Add support for hash and url configs in database hash of `ActiveRecord::Base.connected_to`.
|
520
230
|
|
521
|
-
|
231
|
+
````
|
232
|
+
User.connected_to(database: { writing: "postgres://foo" }) do
|
233
|
+
User.create!(name: "Gannon")
|
234
|
+
end
|
522
235
|
|
523
|
-
|
524
|
-
|
236
|
+
config = { "adapter" => "sqlite3", "database" => "db/readonly.sqlite3" }
|
237
|
+
User.connected_to(database: { reading: config }) do
|
238
|
+
User.count
|
239
|
+
end
|
240
|
+
````
|
525
241
|
|
526
|
-
*
|
242
|
+
*Gannon McGibbon*
|
527
243
|
|
528
|
-
*
|
244
|
+
* Support default expression for MySQL.
|
529
245
|
|
530
|
-
|
246
|
+
MySQL 8.0.13 and higher supports default value to be a function or expression.
|
531
247
|
|
532
|
-
|
248
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-table.html
|
533
249
|
|
534
250
|
*Ryuta Kamizono*
|
535
251
|
|
536
|
-
*
|
252
|
+
* Support expression indexes for MySQL.
|
537
253
|
|
538
|
-
|
254
|
+
MySQL 8.0.13 and higher supports functional key parts that index
|
255
|
+
expression values rather than column or column prefix values.
|
539
256
|
|
540
|
-
|
541
|
-
information.
|
257
|
+
https://dev.mysql.com/doc/refman/8.0/en/create-index.html
|
542
258
|
|
543
|
-
*
|
259
|
+
*Ryuta Kamizono*
|
544
260
|
|
545
|
-
*
|
261
|
+
* Fix collection cache key with limit and custom select to avoid ambiguous timestamp column error.
|
546
262
|
|
547
|
-
|
548
|
-
of database queries in the log to facilitate N+1 query resolution
|
549
|
-
and other debugging.
|
263
|
+
Fixes #33056.
|
550
264
|
|
551
|
-
|
552
|
-
recommended for use in the production environment since it relies
|
553
|
-
on Ruby's `Kernel#caller_locations` which is fairly slow.
|
265
|
+
*Federico Martinez*
|
554
266
|
|
555
|
-
|
267
|
+
* Add basic API for connection switching to support multiple databases.
|
556
268
|
|
557
|
-
|
269
|
+
1) Adds a `connects_to` method for models to connect to multiple databases. Example:
|
558
270
|
|
559
271
|
```
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
# end
|
565
|
-
class Post < ApplicationRecord
|
272
|
+
class AnimalsModel < ApplicationRecord
|
273
|
+
self.abstract_class = true
|
274
|
+
|
275
|
+
connects_to database: { writing: :animals_primary, reading: :animals_replica }
|
566
276
|
end
|
567
277
|
|
568
|
-
|
569
|
-
|
570
|
-
# end
|
571
|
-
class Comment < ApplicationRecord
|
572
|
-
belongs_to :post, touch: true, counter_cache: true
|
278
|
+
class Dog < AnimalsModel
|
279
|
+
# connected to both the animals_primary db for writing and the animals_replica for reading
|
573
280
|
end
|
574
281
|
```
|
575
282
|
|
576
|
-
|
283
|
+
2) Adds a `connected_to` block method for switching connection roles or connecting to
|
284
|
+
a database that the model didn't connect to. Connecting to the database in this block is
|
285
|
+
useful when you have another defined connection, for example `slow_replica` that you don't
|
286
|
+
want to connect to by default but need in the console, or a specific code block.
|
287
|
+
|
577
288
|
```
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
commit transaction
|
583
|
-
|
584
|
-
comment = Comment.create!(post: post)
|
585
|
-
# => begin transaction
|
586
|
-
INSERT INTO "comments" ("post_id") VALUES (1)
|
587
|
-
|
588
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
|
589
|
-
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
590
|
-
|
591
|
-
UPDATE "posts" SET "updated_at" = '2017-12-11 21:27:11.398330',
|
592
|
-
"lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
|
593
|
-
rollback transaction
|
594
|
-
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
595
|
-
|
596
|
-
Comment.take.destroy!
|
597
|
-
# => begin transaction
|
598
|
-
DELETE FROM "comments" WHERE "comments"."id" = 1
|
599
|
-
|
600
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
|
601
|
-
"lock_version" = COALESCE("lock_version", 0) + 1 WHERE "posts"."id" = 1
|
602
|
-
|
603
|
-
UPDATE "posts" SET "updated_at" = '2017-12-11 21:42:47.785901',
|
604
|
-
"lock_version" = 1 WHERE "posts"."id" = 1 AND "posts"."lock_version" = 0
|
605
|
-
rollback transaction
|
606
|
-
# => ActiveRecord::StaleObjectError: Attempted to touch a stale object: Post.
|
289
|
+
ActiveRecord::Base.connected_to(role: :reading) do
|
290
|
+
Dog.first # finds dog from replica connected to AnimalsBase
|
291
|
+
Book.first # doesn't have a reading connection, will raise an error
|
292
|
+
end
|
607
293
|
```
|
608
294
|
|
609
|
-
After:
|
610
295
|
```
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
VALUES ("2017-12-11 21:27:11.387397", "2017-12-11 21:27:11.387397", 0)
|
615
|
-
commit transaction
|
616
|
-
|
617
|
-
comment = Comment.create!(post: post)
|
618
|
-
# => begin transaction
|
619
|
-
INSERT INTO "comments" ("post_id") VALUES (1)
|
620
|
-
|
621
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) + 1,
|
622
|
-
"lock_version" = COALESCE("lock_version", 0) + 1,
|
623
|
-
"updated_at" = '2017-12-11 21:37:09.802642' WHERE "posts"."id" = 1
|
624
|
-
commit transaction
|
625
|
-
|
626
|
-
comment.destroy!
|
627
|
-
# => begin transaction
|
628
|
-
DELETE FROM "comments" WHERE "comments"."id" = 1
|
629
|
-
|
630
|
-
UPDATE "posts" SET "comments_count" = COALESCE("comments_count", 0) - 1,
|
631
|
-
"lock_version" = COALESCE("lock_version", 0) + 1,
|
632
|
-
"updated_at" = '2017-12-11 21:39:02.685520' WHERE "posts"."id" = 1
|
633
|
-
commit transaction
|
296
|
+
ActiveRecord::Base.connected_to(database: :slow_replica) do
|
297
|
+
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
|
298
|
+
end
|
634
299
|
```
|
635
300
|
|
636
|
-
|
637
|
-
|
638
|
-
*bogdanvlviv*
|
639
|
-
|
640
|
-
* Add support for PostgreSQL operator classes to `add_index`.
|
641
|
-
|
642
|
-
Example:
|
643
|
-
|
644
|
-
add_index :users, :name, using: :gist, opclass: { name: :gist_trgm_ops }
|
645
|
-
|
646
|
-
*Greg Navis*
|
647
|
-
|
648
|
-
* Don't allow scopes to be defined which conflict with instance methods on `Relation`.
|
649
|
-
|
650
|
-
Fixes #31120.
|
651
|
-
|
652
|
-
*kinnrot*
|
653
|
-
|
654
|
-
* Add new error class `QueryCanceled` which will be raised
|
655
|
-
when canceling statement due to user request.
|
301
|
+
*Eileen M. Uchitelle*
|
656
302
|
|
657
|
-
|
303
|
+
* Enum raises on invalid definition values
|
658
304
|
|
659
|
-
|
660
|
-
|
305
|
+
When defining a Hash enum it can be easy to use [] instead of {}. This
|
306
|
+
commit checks that only valid definition values are provided, those can
|
307
|
+
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
308
|
+
raises an ArgumentError.
|
661
309
|
|
662
|
-
|
310
|
+
Fixes #33961
|
663
311
|
|
664
|
-
*
|
665
|
-
relation query methods.
|
312
|
+
*Alberto Almagro*
|
666
313
|
|
667
|
-
|
668
|
-
```
|
669
|
-
Article.order("LENGTH(title)")
|
670
|
-
```
|
314
|
+
* Reloading associations now clears the Query Cache like `Persistence#reload` does.
|
671
315
|
|
672
|
-
After:
|
673
316
|
```
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
mistaken belief that only column names will be accepted.
|
680
|
-
|
681
|
-
Raw SQL strings will now cause a deprecation warning, which will
|
682
|
-
become an UnknownAttributeReference error in Rails 6.0. Applications
|
683
|
-
can opt in to the future behavior by setting `allow_unsafe_raw_sql`
|
684
|
-
to `:disabled`.
|
317
|
+
class Post < ActiveRecord::Base
|
318
|
+
has_one :category
|
319
|
+
belongs_to :author
|
320
|
+
has_many :comments
|
321
|
+
end
|
685
322
|
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
323
|
+
# Each of the following will now clear the query cache.
|
324
|
+
post.reload_category
|
325
|
+
post.reload_author
|
326
|
+
post.comments.reload
|
690
327
|
```
|
691
328
|
|
692
|
-
*
|
693
|
-
|
694
|
-
* `update_all` will now pass its values to `Type#cast` before passing them to
|
695
|
-
`Type#serialize`. This means that `update_all(foo: 'true')` will properly
|
696
|
-
persist a boolean.
|
697
|
-
|
698
|
-
*Sean Griffin*
|
699
|
-
|
700
|
-
* Add new error class `StatementTimeout` which will be raised
|
701
|
-
when statement timeout exceeded.
|
702
|
-
|
703
|
-
*Ryuta Kamizono*
|
704
|
-
|
705
|
-
* Fix `bin/rails db:migrate` with specified `VERSION`.
|
706
|
-
`bin/rails db:migrate` with empty VERSION behaves as without `VERSION`.
|
707
|
-
Check a format of `VERSION`: Allow a migration version number
|
708
|
-
or name of a migration file. Raise error if format of `VERSION` is invalid.
|
709
|
-
Raise error if target migration doesn't exist.
|
710
|
-
|
711
|
-
*bogdanvlviv*
|
712
|
-
|
713
|
-
* Fixed a bug where column orders for an index weren't written to
|
714
|
-
`db/schema.rb` when using the sqlite adapter.
|
715
|
-
|
716
|
-
Fixes #30902.
|
717
|
-
|
718
|
-
*Paul Kuruvilla*
|
719
|
-
|
720
|
-
* Remove deprecated method `#sanitize_conditions`.
|
721
|
-
|
722
|
-
*Rafael Mendonça França*
|
723
|
-
|
724
|
-
* Remove deprecated method `#scope_chain`.
|
725
|
-
|
726
|
-
*Rafael Mendonça França*
|
727
|
-
|
728
|
-
* Remove deprecated configuration `.error_on_ignored_order_or_limit`.
|
329
|
+
*Christophe Maximin*
|
729
330
|
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
*Rafael Mendonça França*
|
735
|
-
|
736
|
-
* Remove deprecated argument `name` from `#indexes`.
|
737
|
-
|
738
|
-
*Rafael Mendonça França*
|
739
|
-
|
740
|
-
* Remove deprecated method `ActiveRecord::Migrator.schema_migrations_table_name`.
|
331
|
+
* Added `index` option for `change_table` migration helpers.
|
332
|
+
With this change you can create indexes while adding new
|
333
|
+
columns into the existing tables.
|
741
334
|
|
742
|
-
|
335
|
+
Example:
|
743
336
|
|
744
|
-
|
337
|
+
change_table(:languages) do |t|
|
338
|
+
t.string :country_code, index: true
|
339
|
+
end
|
745
340
|
|
746
|
-
*
|
341
|
+
*Mehmet Emin İNAÇ*
|
747
342
|
|
748
|
-
*
|
343
|
+
* Fix `transaction` reverting for migrations.
|
749
344
|
|
750
|
-
|
345
|
+
Before: Commands inside a `transaction` in a reverted migration ran uninverted.
|
346
|
+
Now: This change fixes that by reverting commands inside `transaction` block.
|
751
347
|
|
752
|
-
*
|
348
|
+
*fatkodima*, *David Verhasselt*
|
753
349
|
|
754
|
-
|
350
|
+
* Raise an error instead of scanning the filesystem root when `fixture_path` is blank.
|
755
351
|
|
756
|
-
*
|
352
|
+
*Gannon McGibbon*, *Max Albrecht*
|
757
353
|
|
758
|
-
|
354
|
+
* Allow `ActiveRecord::Base.configurations=` to be set with a symbolized hash.
|
759
355
|
|
760
|
-
*
|
356
|
+
*Gannon McGibbon*
|
761
357
|
|
762
|
-
|
358
|
+
* Don't update counter cache unless the record is actually saved.
|
763
359
|
|
764
|
-
|
360
|
+
Fixes #31493, #33113, #33117.
|
765
361
|
|
766
|
-
*
|
362
|
+
*Ryuta Kamizono*
|
767
363
|
|
768
|
-
*
|
364
|
+
* Deprecate `ActiveRecord::Result#to_hash` in favor of `ActiveRecord::Result#to_a`.
|
769
365
|
|
770
|
-
*
|
366
|
+
*Gannon McGibbon*, *Kevin Cheng*
|
771
367
|
|
772
|
-
*
|
773
|
-
ar_internal_metadata's data for a test database.
|
368
|
+
* SQLite3 adapter supports expression indexes.
|
774
369
|
|
775
|
-
Before:
|
776
|
-
```
|
777
|
-
$ RAILS_ENV=test rails dbconsole
|
778
|
-
> SELECT * FROM ar_internal_metadata;
|
779
|
-
key|value|created_at|updated_at
|
780
|
-
environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
|
781
370
|
```
|
371
|
+
create_table :users do |t|
|
372
|
+
t.string :email
|
373
|
+
end
|
782
374
|
|
783
|
-
|
375
|
+
add_index :users, 'lower(email)', name: 'index_users_on_email', unique: true
|
784
376
|
```
|
785
|
-
$ RAILS_ENV=test rails dbconsole
|
786
|
-
> SELECT * FROM ar_internal_metadata;
|
787
|
-
key|value|created_at|updated_at
|
788
|
-
environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
|
789
|
-
```
|
790
|
-
|
791
|
-
Fixes #26731.
|
792
|
-
|
793
|
-
*bogdanvlviv*
|
794
|
-
|
795
|
-
* Fix longer sequence name detection for serial columns.
|
796
|
-
|
797
|
-
Fixes #28332.
|
798
|
-
|
799
|
-
*Ryuta Kamizono*
|
800
|
-
|
801
|
-
* MySQL: Don't lose `auto_increment: true` in the `db/schema.rb`.
|
802
|
-
|
803
|
-
Fixes #30894.
|
804
|
-
|
805
|
-
*Ryuta Kamizono*
|
806
|
-
|
807
|
-
* Fix `COUNT(DISTINCT ...)` for `GROUP BY` with `ORDER BY` and `LIMIT`.
|
808
377
|
|
809
|
-
|
378
|
+
*Gray Kemmey*
|
810
379
|
|
811
|
-
|
812
|
-
|
813
|
-
* PostgreSQL `tsrange` now preserves subsecond precision.
|
814
|
-
|
815
|
-
PostgreSQL 9.1+ introduced range types, and Rails added support for using
|
816
|
-
this datatype in Active Record. However, the serialization of
|
817
|
-
`PostgreSQL::OID::Range` was incomplete, because it did not properly
|
818
|
-
cast the bounds that make up the range. This led to subseconds being
|
819
|
-
dropped in SQL commands:
|
820
|
-
|
821
|
-
Before:
|
822
|
-
|
823
|
-
connection.type_cast(tsrange.serialize(range_value))
|
824
|
-
# => "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)"
|
825
|
-
|
826
|
-
Now:
|
380
|
+
* Allow subclasses to redefine autosave callbacks for associated records.
|
827
381
|
|
828
|
-
|
829
|
-
# => "[2010-01-01 13:30:00.670277,2011-02-02 19:30:00.745125)"
|
382
|
+
Fixes #33305.
|
830
383
|
|
831
|
-
*
|
384
|
+
*Andrey Subbota*
|
832
385
|
|
833
|
-
*
|
834
|
-
array.
|
386
|
+
* Bump minimum MySQL version to 5.5.8.
|
835
387
|
|
836
|
-
*
|
388
|
+
*Yasuo Honda*
|
837
389
|
|
838
|
-
* Use
|
390
|
+
* Use MySQL utf8mb4 character set by default.
|
839
391
|
|
840
|
-
|
392
|
+
`utf8mb4` character set with 4-Byte encoding supports supplementary characters including emoji.
|
393
|
+
The previous default 3-Byte encoding character set `utf8` is not enough to support them.
|
841
394
|
|
842
|
-
*
|
395
|
+
*Yasuo Honda*
|
843
396
|
|
844
|
-
*
|
845
|
-
more descriptive.
|
397
|
+
* Fix duplicated record creation when using nested attributes with `create_with`.
|
846
398
|
|
847
|
-
|
399
|
+
*Darwin Wu*
|
848
400
|
|
849
|
-
|
401
|
+
* Configuration item `config.filter_parameters` could also filter out
|
402
|
+
sensitive values of database columns when call `#inspect`.
|
403
|
+
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
404
|
+
specify sensitive attributes to specific model.
|
850
405
|
|
851
|
-
|
852
|
-
|
406
|
+
```
|
407
|
+
Rails.application.config.filter_parameters += [:credit_card_number, /phone/]
|
408
|
+
Account.last.inspect # => #<Account id: 123, name: "DHH", credit_card_number: [FILTERED], telephone_number: [FILTERED] ...>
|
409
|
+
SecureAccount.filter_attributes += [:name]
|
410
|
+
SecureAccount.last.inspect # => #<SecureAccount id: 42, name: [FILTERED], credit_card_number: [FILTERED] ...>
|
411
|
+
```
|
853
412
|
|
854
|
-
*
|
413
|
+
*Zhang Kang*, *Yoshiyuki Kinjo*
|
855
414
|
|
856
|
-
*
|
415
|
+
* Deprecate `column_name_length`, `table_name_length`, `columns_per_table`,
|
416
|
+
`indexes_per_table`, `columns_per_multicolumn_index`, `sql_query_length`,
|
417
|
+
and `joins_per_query` methods in `DatabaseLimits`.
|
857
418
|
|
858
419
|
*Ryuta Kamizono*
|
859
420
|
|
860
|
-
*
|
421
|
+
* `ActiveRecord::Base.configurations` now returns an object.
|
861
422
|
|
862
|
-
|
423
|
+
`ActiveRecord::Base.configurations` used to return a hash, but this
|
424
|
+
is an inflexible data model. In order to improve multiple-database
|
425
|
+
handling in Rails, we've changed this to return an object. Some methods
|
426
|
+
are provided to make the object behave hash-like in order to ease the
|
427
|
+
transition process. Since most applications don't manipulate the hash
|
428
|
+
we've decided to add backwards-compatible functionality that will throw
|
429
|
+
a deprecation warning if used, however calling `ActiveRecord::Base.configurations`
|
430
|
+
will use the new version internally and externally.
|
863
431
|
|
864
|
-
|
432
|
+
For example, the following `database.yml`:
|
865
433
|
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
*Atsushi Yoshida*
|
873
|
-
|
874
|
-
* When using `Relation#or`, extract the common conditions and put them before the OR condition.
|
875
|
-
|
876
|
-
*Maxime Handfield Lapointe*
|
877
|
-
|
878
|
-
* `Relation#or` now accepts two relations who have different values for
|
879
|
-
`references` only, as `references` can be implicitly called by `where`.
|
880
|
-
|
881
|
-
Fixes #29411.
|
882
|
-
|
883
|
-
*Sean Griffin*
|
884
|
-
|
885
|
-
* `ApplicationRecord` is no longer generated when generating models. If you
|
886
|
-
need to generate it, it can be created with `rails g application_record`.
|
887
|
-
|
888
|
-
*Lisa Ugray*
|
889
|
-
|
890
|
-
* Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT` to keep the existing select list.
|
891
|
-
|
892
|
-
*Ryuta Kamizono*
|
893
|
-
|
894
|
-
* When a `has_one` association is destroyed by `dependent: destroy`,
|
895
|
-
`destroyed_by_association` will now be set to the reflection, matching the
|
896
|
-
behaviour of `has_many` associations.
|
434
|
+
```
|
435
|
+
development:
|
436
|
+
adapter: sqlite3
|
437
|
+
database: db/development.sqlite3
|
438
|
+
```
|
897
439
|
|
898
|
-
|
440
|
+
Used to become a hash:
|
899
441
|
|
900
|
-
|
442
|
+
```
|
443
|
+
{ "development" => { "adapter" => "sqlite3", "database" => "db/development.sqlite3" } }
|
444
|
+
```
|
901
445
|
|
902
|
-
|
903
|
-
bind values used by the `or` instead. (possibly other cases too)
|
446
|
+
Is now converted into the following object:
|
904
447
|
|
905
448
|
```
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
# SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 1 OR "posts"."id" = 2)
|
449
|
+
#<ActiveRecord::DatabaseConfigurations:0x00007fd1acbdf800 @configurations=[
|
450
|
+
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10 @env_name="development",
|
451
|
+
@spec_name="primary", @config={"adapter"=>"sqlite3", "database"=>"db/development.sqlite3"}>
|
452
|
+
]
|
911
453
|
```
|
912
454
|
|
913
|
-
|
455
|
+
Iterating over the database configurations has also changed. Instead of
|
456
|
+
calling hash methods on the `configurations` hash directly, a new method `configs_for` has
|
457
|
+
been provided that allows you to select the correct configuration. `env_name`, and
|
458
|
+
`spec_name` arguments are optional. For example these return an array of
|
459
|
+
database config objects for the requested environment and a single database config object
|
460
|
+
will be returned for the requested environment and specification name respectively.
|
914
461
|
|
915
|
-
|
916
|
-
|
462
|
+
```
|
463
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development")
|
464
|
+
ActiveRecord::Base.configurations.configs_for(env_name: "development", spec_name: "primary")
|
465
|
+
```
|
917
466
|
|
918
|
-
*
|
467
|
+
*Eileen M. Uchitelle*, *Aaron Patterson*
|
919
468
|
|
920
|
-
*
|
921
|
-
`current_scope`, with the exception of `unscoped`.
|
469
|
+
* Add database configuration to disable advisory locks.
|
922
470
|
|
923
|
-
|
471
|
+
```
|
472
|
+
production:
|
473
|
+
adapter: postgresql
|
474
|
+
advisory_locks: false
|
475
|
+
```
|
924
476
|
|
925
|
-
*
|
477
|
+
*Guo Xiang*
|
926
478
|
|
927
|
-
*
|
479
|
+
* SQLite3 adapter `alter_table` method restores foreign keys.
|
928
480
|
|
929
|
-
|
930
|
-
recognize 't' and 'f' as was previously serialized.
|
481
|
+
*Yasuo Honda*
|
931
482
|
|
932
|
-
|
933
|
-
for SQLite databases, so it's implemented behind a configuration flag
|
934
|
-
whose default false value is deprecated.
|
483
|
+
* Allow `:to_table` option to `invert_remove_foreign_key`.
|
935
484
|
|
936
|
-
|
485
|
+
Example:
|
937
486
|
|
938
|
-
|
939
|
-
`in_batches`).
|
487
|
+
remove_foreign_key :accounts, to_table: :owners
|
940
488
|
|
941
|
-
|
942
|
-
until the end of the request or job.
|
489
|
+
*Nikolay Epifanov*, *Rich Chen*
|
943
490
|
|
944
|
-
|
491
|
+
* Add environment & load_config dependency to `bin/rake db:seed` to enable
|
492
|
+
seed load in environments without Rails and custom DB configuration
|
945
493
|
|
946
|
-
*
|
947
|
-
`ActiveRecord::StatementInvalid` exceptions.
|
494
|
+
*Tobias Bielohlawek*
|
948
495
|
|
949
|
-
|
496
|
+
* Fix default value for mysql time types with specified precision.
|
950
497
|
|
951
|
-
*
|
498
|
+
*Nikolay Kondratyev*
|
952
499
|
|
953
|
-
|
500
|
+
* Fix `touch` option to behave consistently with `Persistence#touch` method.
|
954
501
|
|
955
502
|
*Ryuta Kamizono*
|
956
503
|
|
957
|
-
*
|
504
|
+
* Migrations raise when duplicate column definition.
|
958
505
|
|
959
|
-
|
960
|
-
inner transaction would still be marked as persisted.
|
506
|
+
Fixes #33024.
|
961
507
|
|
962
|
-
|
963
|
-
parent transaction is rolledback. This will correctly mark records from the inner transaction as not persisted.
|
964
|
-
|
965
|
-
*Eileen M. Uchitelle*, *Aaron Patterson*
|
966
|
-
|
967
|
-
* Deprecate `set_state` method in `TransactionState`.
|
968
|
-
|
969
|
-
Deprecated the `set_state` method in favor of setting the state via specific methods. If you need to mark the
|
970
|
-
state of the transaction you can now use `rollback!`, `commit!` or `nullify!` instead of
|
971
|
-
`set_state(:rolledback)`, `set_state(:committed)`, or `set_state(nil)`.
|
972
|
-
|
973
|
-
*Eileen M. Uchitelle*, *Aaron Patterson*
|
974
|
-
|
975
|
-
* Deprecate delegating to `arel` in `Relation`.
|
976
|
-
|
977
|
-
*Ryuta Kamizono*
|
508
|
+
*Federico Martinez*
|
978
509
|
|
979
|
-
*
|
980
|
-
without being connected.
|
510
|
+
* Bump minimum SQLite version to 3.8
|
981
511
|
|
982
|
-
*
|
512
|
+
*Yasuo Honda*
|
983
513
|
|
984
|
-
*
|
985
|
-
if the child records were deleted before the parent was saved, they would
|
986
|
-
still be persisted. Now, if child records are deleted before the parent is saved
|
987
|
-
on a `has_many :through` association, the child records will not be persisted.
|
514
|
+
* Fix parent record should not get saved with duplicate children records.
|
988
515
|
|
989
|
-
|
516
|
+
Fixes #32940.
|
990
517
|
|
991
|
-
*
|
992
|
-
the merged relation into LEFT OUTER JOIN.
|
518
|
+
*Santosh Wadghule*
|
993
519
|
|
994
|
-
|
520
|
+
* Fix logic on disabling commit callbacks so they are not called unexpectedly when errors occur.
|
995
521
|
|
996
|
-
|
997
|
-
Author.joins(:posts).merge(Post.joins(:comments))
|
998
|
-
# Before the change:
|
999
|
-
#=> SELECT ... FROM authors INNER JOIN posts ON ... LEFT OUTER JOIN comments ON...
|
522
|
+
*Brian Durand*
|
1000
523
|
|
1001
|
-
|
1002
|
-
|
1003
|
-
```
|
524
|
+
* Ensure `Associations::CollectionAssociation#size` and `Associations::CollectionAssociation#empty?`
|
525
|
+
use loaded association ids if present.
|
1004
526
|
|
1005
|
-
*
|
527
|
+
*Graham Turner*
|
1006
528
|
|
1007
|
-
*
|
1008
|
-
`locking_column`, without default value, is null in the database.
|
529
|
+
* Add support to preload associations of polymorphic associations when not all the records have the requested associations.
|
1009
530
|
|
1010
|
-
*
|
531
|
+
*Dana Sherson*
|
1011
532
|
|
1012
|
-
*
|
1013
|
-
`locking_column` is null in the database.
|
533
|
+
* Add `touch_all` method to `ActiveRecord::Relation`.
|
1014
534
|
|
1015
|
-
|
535
|
+
Example:
|
1016
536
|
|
1017
|
-
|
537
|
+
Person.where(name: "David").touch_all(time: Time.new(2020, 5, 16, 0, 0, 0))
|
1018
538
|
|
1019
|
-
*
|
539
|
+
*fatkodima*, *duggiefresh*
|
1020
540
|
|
1021
|
-
*
|
541
|
+
* Add `ActiveRecord::Base.base_class?` predicate.
|
1022
542
|
|
1023
|
-
*
|
543
|
+
*Bogdan Gusiev*
|
1024
544
|
|
1025
|
-
*
|
545
|
+
* Add custom prefix/suffix options to `ActiveRecord::Store.store_accessor`.
|
1026
546
|
|
1027
|
-
*
|
547
|
+
*Tan Huynh*, *Yukio Mizuta*
|
1028
548
|
|
1029
|
-
*
|
549
|
+
* Rails 6 requires Ruby 2.5.0 or newer.
|
1030
550
|
|
1031
|
-
|
551
|
+
*Jeremy Daer*, *Kasper Timm Hansen*
|
1032
552
|
|
1033
|
-
|
553
|
+
* Deprecate `update_attributes`/`!` in favor of `update`/`!`.
|
1034
554
|
|
1035
|
-
*
|
1036
|
-
in `ActiveSupport::Cache`. This also means that `ActiveRecord::Base#cache_key` will now return a stable key
|
1037
|
-
that does not include a timestamp any more.
|
555
|
+
*Eddie Lebow*
|
1038
556
|
|
1039
|
-
|
1040
|
-
|
557
|
+
* Add `ActiveRecord::Base.create_or_find_by`/`!` to deal with the SELECT/INSERT race condition in
|
558
|
+
`ActiveRecord::Base.find_or_create_by`/`!` by leaning on unique constraints in the database.
|
1041
559
|
|
1042
560
|
*DHH*
|
1043
561
|
|
1044
|
-
*
|
1045
|
-
|
1046
|
-
*Rusty Geldmacher*, *Guillermo Iguaran*
|
1047
|
-
|
1048
|
-
* Add type caster to `RuntimeReflection#alias_name`.
|
1049
|
-
|
1050
|
-
Fixes #28959.
|
1051
|
-
|
1052
|
-
*Jon Moss*
|
1053
|
-
|
1054
|
-
* Deprecate `supports_statement_cache?`.
|
1055
|
-
|
1056
|
-
*Ryuta Kamizono*
|
1057
|
-
|
1058
|
-
* Raise error `UnknownMigrationVersionError` on the movement of migrations
|
1059
|
-
when the current migration does not exist.
|
562
|
+
* Add `Relation#pick` as short-hand for single-value plucks.
|
1060
563
|
|
1061
|
-
*
|
1062
|
-
|
1063
|
-
* Fix `bin/rails db:forward` first migration.
|
1064
|
-
|
1065
|
-
*bogdanvlviv*
|
1066
|
-
|
1067
|
-
* Support Descending Indexes for MySQL.
|
1068
|
-
|
1069
|
-
MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored.
|
1070
|
-
See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
|
1071
|
-
|
1072
|
-
*Ryuta Kamizono*
|
1073
|
-
|
1074
|
-
* Fix inconsistency with changed attributes when overriding Active Record attribute reader.
|
1075
|
-
|
1076
|
-
*bogdanvlviv*
|
1077
|
-
|
1078
|
-
* When calling the dynamic fixture accessor method with no arguments, it now returns all fixtures of this type.
|
1079
|
-
Previously this method always returned an empty array.
|
1080
|
-
|
1081
|
-
*Kevin McPhillips*
|
564
|
+
*DHH*
|
1082
565
|
|
1083
566
|
|
1084
|
-
Please check [5-
|
567
|
+
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activerecord/CHANGELOG.md) for previous changes.
|