activerecord 6.0.0.beta1 → 6.0.1.rc1
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 +529 -10
- data/README.rdoc +3 -1
- data/lib/active_record.rb +7 -1
- data/lib/active_record/association_relation.rb +15 -6
- data/lib/active_record/associations.rb +4 -3
- data/lib/active_record/associations/association.rb +27 -2
- data/lib/active_record/associations/builder/association.rb +14 -18
- data/lib/active_record/associations/builder/belongs_to.rb +5 -2
- data/lib/active_record/associations/builder/collection_association.rb +5 -15
- data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +1 -1
- data/lib/active_record/associations/builder/has_many.rb +2 -0
- data/lib/active_record/associations/builder/has_one.rb +35 -1
- data/lib/active_record/associations/builder/singular_association.rb +2 -0
- data/lib/active_record/associations/collection_association.rb +5 -6
- data/lib/active_record/associations/collection_proxy.rb +13 -42
- data/lib/active_record/associations/has_many_association.rb +1 -9
- data/lib/active_record/associations/has_many_through_association.rb +4 -11
- data/lib/active_record/associations/join_dependency.rb +14 -9
- data/lib/active_record/associations/join_dependency/join_association.rb +21 -7
- data/lib/active_record/associations/preloader.rb +12 -7
- data/lib/active_record/associations/preloader/association.rb +37 -34
- data/lib/active_record/associations/preloader/through_association.rb +48 -39
- data/lib/active_record/attribute_methods.rb +3 -53
- data/lib/active_record/attribute_methods/before_type_cast.rb +4 -1
- data/lib/active_record/attribute_methods/dirty.rb +47 -14
- data/lib/active_record/attribute_methods/primary_key.rb +7 -15
- data/lib/active_record/attribute_methods/query.rb +2 -3
- data/lib/active_record/attribute_methods/read.rb +3 -9
- data/lib/active_record/attribute_methods/write.rb +6 -12
- data/lib/active_record/attributes.rb +13 -0
- data/lib/active_record/autosave_association.rb +21 -7
- data/lib/active_record/base.rb +0 -1
- data/lib/active_record/callbacks.rb +3 -3
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +134 -23
- data/lib/active_record/connection_adapters/abstract/database_limits.rb +8 -4
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +105 -70
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +12 -5
- data/lib/active_record/connection_adapters/abstract/quoting.rb +63 -6
- data/lib/active_record/connection_adapters/abstract/schema_creation.rb +5 -2
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +51 -40
- data/lib/active_record/connection_adapters/abstract/schema_dumper.rb +1 -1
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +95 -30
- data/lib/active_record/connection_adapters/abstract/transaction.rb +17 -6
- data/lib/active_record/connection_adapters/abstract_adapter.rb +115 -35
- data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +106 -138
- data/lib/active_record/connection_adapters/column.rb +17 -13
- data/lib/active_record/connection_adapters/connection_specification.rb +2 -2
- data/lib/active_record/connection_adapters/determine_if_preparable_visitor.rb +3 -3
- data/lib/active_record/connection_adapters/mysql/database_statements.rb +48 -8
- data/lib/active_record/connection_adapters/mysql/quoting.rb +44 -7
- data/lib/active_record/connection_adapters/mysql/schema_definitions.rb +40 -32
- data/lib/active_record/connection_adapters/mysql/schema_dumper.rb +14 -6
- data/lib/active_record/connection_adapters/mysql/schema_statements.rb +66 -5
- data/lib/active_record/connection_adapters/mysql/type_metadata.rb +6 -10
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +18 -5
- data/lib/active_record/connection_adapters/postgresql/column.rb +17 -30
- data/lib/active_record/connection_adapters/postgresql/database_statements.rb +8 -2
- data/lib/active_record/connection_adapters/postgresql/oid/money.rb +2 -2
- data/lib/active_record/connection_adapters/postgresql/oid/range.rb +1 -1
- data/lib/active_record/connection_adapters/postgresql/oid/uuid.rb +6 -3
- data/lib/active_record/connection_adapters/postgresql/quoting.rb +40 -3
- data/lib/active_record/connection_adapters/postgresql/schema_creation.rb +36 -0
- data/lib/active_record/connection_adapters/postgresql/schema_definitions.rb +98 -89
- data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +47 -63
- data/lib/active_record/connection_adapters/postgresql/type_metadata.rb +23 -27
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +95 -24
- data/lib/active_record/connection_adapters/schema_cache.rb +32 -14
- data/lib/active_record/connection_adapters/sql_type_metadata.rb +11 -8
- data/lib/active_record/connection_adapters/sqlite3/database_statements.rb +120 -0
- data/lib/active_record/connection_adapters/sqlite3/quoting.rb +38 -2
- data/lib/active_record/connection_adapters/sqlite3/schema_statements.rb +28 -2
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +73 -118
- data/lib/active_record/connection_handling.rb +40 -17
- data/lib/active_record/core.rb +35 -24
- data/lib/active_record/database_configurations.rb +99 -50
- data/lib/active_record/database_configurations/hash_config.rb +11 -11
- data/lib/active_record/database_configurations/url_config.rb +21 -16
- data/lib/active_record/dynamic_matchers.rb +1 -1
- data/lib/active_record/enum.rb +15 -0
- data/lib/active_record/errors.rb +18 -13
- data/lib/active_record/fixtures.rb +11 -6
- data/lib/active_record/gem_version.rb +2 -2
- data/lib/active_record/inheritance.rb +1 -1
- data/lib/active_record/insert_all.rb +179 -0
- data/lib/active_record/integration.rb +13 -1
- data/lib/active_record/internal_metadata.rb +5 -1
- data/lib/active_record/locking/optimistic.rb +3 -4
- data/lib/active_record/log_subscriber.rb +1 -1
- data/lib/active_record/middleware/database_selector.rb +75 -0
- data/lib/active_record/middleware/database_selector/resolver.rb +88 -0
- data/lib/active_record/middleware/database_selector/resolver/session.rb +45 -0
- data/lib/active_record/migration.rb +62 -44
- data/lib/active_record/migration/command_recorder.rb +28 -14
- data/lib/active_record/migration/compatibility.rb +72 -63
- data/lib/active_record/model_schema.rb +3 -0
- data/lib/active_record/persistence.rb +212 -19
- data/lib/active_record/querying.rb +18 -14
- data/lib/active_record/railtie.rb +9 -1
- data/lib/active_record/railties/collection_cache_association_loading.rb +3 -3
- data/lib/active_record/railties/databases.rake +124 -25
- data/lib/active_record/reflection.rb +18 -32
- data/lib/active_record/relation.rb +185 -35
- data/lib/active_record/relation/calculations.rb +40 -44
- data/lib/active_record/relation/delegation.rb +23 -31
- data/lib/active_record/relation/finder_methods.rb +23 -14
- data/lib/active_record/relation/merger.rb +11 -16
- data/lib/active_record/relation/query_attribute.rb +5 -3
- data/lib/active_record/relation/query_methods.rb +230 -69
- data/lib/active_record/relation/spawn_methods.rb +1 -1
- data/lib/active_record/relation/where_clause.rb +10 -10
- data/lib/active_record/sanitization.rb +33 -4
- data/lib/active_record/schema.rb +1 -1
- data/lib/active_record/schema_dumper.rb +10 -1
- data/lib/active_record/schema_migration.rb +1 -1
- data/lib/active_record/scoping.rb +6 -7
- data/lib/active_record/scoping/default.rb +7 -15
- data/lib/active_record/scoping/named.rb +10 -2
- data/lib/active_record/statement_cache.rb +2 -2
- data/lib/active_record/store.rb +48 -0
- data/lib/active_record/table_metadata.rb +9 -13
- data/lib/active_record/tasks/database_tasks.rb +109 -6
- data/lib/active_record/tasks/mysql_database_tasks.rb +3 -1
- data/lib/active_record/test_databases.rb +1 -16
- data/lib/active_record/test_fixtures.rb +2 -2
- data/lib/active_record/timestamp.rb +35 -19
- data/lib/active_record/touch_later.rb +4 -2
- data/lib/active_record/transactions.rb +56 -46
- data/lib/active_record/type_caster/connection.rb +16 -10
- data/lib/active_record/validations.rb +1 -0
- data/lib/active_record/validations/uniqueness.rb +4 -4
- data/lib/arel.rb +18 -4
- data/lib/arel/insert_manager.rb +3 -3
- data/lib/arel/nodes.rb +2 -1
- data/lib/arel/nodes/and.rb +1 -1
- data/lib/arel/nodes/case.rb +1 -1
- data/lib/arel/nodes/comment.rb +29 -0
- data/lib/arel/nodes/select_core.rb +16 -12
- data/lib/arel/nodes/unary.rb +1 -0
- data/lib/arel/nodes/values_list.rb +2 -17
- data/lib/arel/select_manager.rb +10 -10
- data/lib/arel/visitors/depth_first.rb +7 -2
- data/lib/arel/visitors/dot.rb +7 -2
- data/lib/arel/visitors/ibm_db.rb +13 -0
- data/lib/arel/visitors/informix.rb +6 -0
- data/lib/arel/visitors/mssql.rb +15 -1
- data/lib/arel/visitors/oracle12.rb +4 -5
- data/lib/arel/visitors/postgresql.rb +4 -10
- data/lib/arel/visitors/to_sql.rb +107 -131
- data/lib/arel/visitors/visitor.rb +9 -5
- data/lib/rails/generators/active_record/migration/migration_generator.rb +1 -1
- data/lib/rails/generators/active_record/migration/templates/create_table_migration.rb.tt +1 -1
- data/lib/rails/generators/active_record/migration/templates/migration.rb.tt +4 -2
- data/lib/rails/generators/active_record/model/model_generator.rb +1 -1
- data/lib/rails/generators/active_record/model/templates/model.rb.tt +10 -1
- metadata +19 -12
- data/lib/active_record/collection_cache_key.rb +0 -53
- data/lib/arel/nodes/values.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be3ff760985818a549e4ba996b816dc1c370e35e60ce2c608a30c5c8f6c91f7b
|
4
|
+
data.tar.gz: a5748dd47536b784c658a9af54dfe44dd6065e2f0ad9be44b64f26f44ab97255
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae9991aa99daa69c7a493ca957ec586f5def10a74b768225ee2fcbd6d20136d16b87d5ef88de7f4a9cef15f7e67df860530965f1b43f080741ee22ca94d89879
|
7
|
+
data.tar.gz: '098af13801ae75f56682d5aabbcc5318dbdbaada30512850e9b0ab4db15b6dd7168fb2ad48b994af04d2554195a062a84ac0caf17ffd1c31bc622a8a30e48884'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,522 @@
|
|
1
|
+
## Rails 6.0.1.rc1 (October 31, 2019) ##
|
2
|
+
|
3
|
+
* Common Table Expressions are allowed on read-only Postgresql connections.
|
4
|
+
|
5
|
+
*Chris Morris*
|
6
|
+
|
7
|
+
* New record instantiation respects `unscope`.
|
8
|
+
|
9
|
+
*Ryuta Kamizono*
|
10
|
+
|
11
|
+
* Fixed a case where `find_in_batches` could halt too early.
|
12
|
+
|
13
|
+
*Takayuki Nakata*
|
14
|
+
|
15
|
+
* Autosaved associations always perform validations when a custom validation
|
16
|
+
context is used.
|
17
|
+
|
18
|
+
*Tekin Suleyman*
|
19
|
+
|
20
|
+
* `sql.active_record` notifications now include the `:connection` in
|
21
|
+
their payloads.
|
22
|
+
|
23
|
+
*Eugene Kenny*
|
24
|
+
|
25
|
+
* A rollback encountered in an `after_commit` callback does not reset
|
26
|
+
previously-committed record state.
|
27
|
+
|
28
|
+
*Ryuta Kamizono*
|
29
|
+
|
30
|
+
* Fixed that join order was lost when eager-loading.
|
31
|
+
|
32
|
+
*Ryuta Kamizono*
|
33
|
+
|
34
|
+
* `DESCRIBE` queries are allowed on read-only connections.
|
35
|
+
|
36
|
+
*Dylan Thacker-Smith*
|
37
|
+
|
38
|
+
* Fixed that records that had been `inspect`ed could not be marshaled.
|
39
|
+
|
40
|
+
*Eugene Kenny*
|
41
|
+
|
42
|
+
* The connection pool reaper thread is respawned in forked processes. This
|
43
|
+
fixes that idle connections in forked processes wouldn't be reaped.
|
44
|
+
|
45
|
+
*John Hawthorn*
|
46
|
+
|
47
|
+
* The memoized result of `ActiveRecord::Relation#take` is properly cleared
|
48
|
+
when `ActiveRecord::Relation#reset` or `ActiveRecord::Relation#reload`
|
49
|
+
is called.
|
50
|
+
|
51
|
+
*Anmol Arora*
|
52
|
+
|
53
|
+
* Fixed the performance regression for `primary_keys` introduced MySQL 8.0.
|
54
|
+
|
55
|
+
*Hiroyuki Ishii*
|
56
|
+
|
57
|
+
* `insert`, `insert_all`, `upsert`, and `upsert_all` now clear the query cache.
|
58
|
+
|
59
|
+
*Eugene Kenny*
|
60
|
+
|
61
|
+
* Call `while_preventing_writes` directly from `connected_to`.
|
62
|
+
|
63
|
+
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)`.
|
64
|
+
|
65
|
+
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.
|
66
|
+
|
67
|
+
*Eileen M. Uchitelle*
|
68
|
+
|
69
|
+
* Improve detection of ActiveRecord::StatementTimeout with mysql2 adapter in the edge case when the query is terminated during filesort.
|
70
|
+
|
71
|
+
*Kir Shatrov*
|
72
|
+
|
73
|
+
|
74
|
+
## Rails 6.0.0 (August 16, 2019) ##
|
75
|
+
|
76
|
+
* Preserve user supplied joins order as much as possible.
|
77
|
+
|
78
|
+
Fixes #36761, #34328, #24281, #12953.
|
79
|
+
|
80
|
+
*Ryuta Kamizono*
|
81
|
+
|
82
|
+
* Make the DATABASE_URL env variable only affect the primary connection. Add new env variables for multiple databases.
|
83
|
+
|
84
|
+
*John Crepezzi*, *Eileen Uchitelle*
|
85
|
+
|
86
|
+
* Add a warning for enum elements with 'not_' prefix.
|
87
|
+
|
88
|
+
class Foo
|
89
|
+
enum status: [:sent, :not_sent]
|
90
|
+
end
|
91
|
+
|
92
|
+
*Edu Depetris*
|
93
|
+
|
94
|
+
* Make currency symbols optional for money column type in PostgreSQL
|
95
|
+
|
96
|
+
*Joel Schneider*
|
97
|
+
|
98
|
+
|
99
|
+
## Rails 6.0.0.rc2 (July 22, 2019) ##
|
100
|
+
|
101
|
+
* Add database_exists? method to connection adapters to check if a database exists.
|
102
|
+
|
103
|
+
*Guilherme Mansur*
|
104
|
+
|
105
|
+
* PostgreSQL: Fix GROUP BY with ORDER BY virtual count attribute.
|
106
|
+
|
107
|
+
Fixes #36022.
|
108
|
+
|
109
|
+
*Ryuta Kamizono*
|
110
|
+
|
111
|
+
* Make ActiveRecord `ConnectionPool.connections` method thread-safe.
|
112
|
+
|
113
|
+
Fixes #36465.
|
114
|
+
|
115
|
+
*Jeff Doering*
|
116
|
+
|
117
|
+
* Fix sqlite3 collation parsing when using decimal columns.
|
118
|
+
|
119
|
+
*Martin R. Schuster*
|
120
|
+
|
121
|
+
* Fix invalid schema when primary key column has a comment.
|
122
|
+
|
123
|
+
Fixes #29966.
|
124
|
+
|
125
|
+
*Guilherme Goettems Schneider*
|
126
|
+
|
127
|
+
* Fix table comment also being applied to the primary key column.
|
128
|
+
|
129
|
+
*Guilherme Goettems Schneider*
|
130
|
+
|
131
|
+
* Fix merging left_joins to maintain its own `join_type` context.
|
132
|
+
|
133
|
+
Fixes #36103.
|
134
|
+
|
135
|
+
*Ryuta Kamizono*
|
136
|
+
|
137
|
+
|
138
|
+
## Rails 6.0.0.rc1 (April 24, 2019) ##
|
139
|
+
|
140
|
+
* Add `touch` option to `has_one` association.
|
141
|
+
|
142
|
+
*Abhay Nikam*
|
143
|
+
|
144
|
+
* Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1.
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
|
148
|
+
assert_equal all, PriceEstimate.all.map(&:estimate_of)
|
149
|
+
```
|
150
|
+
|
151
|
+
In Rails 6.0:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
sapphire = treasures(:sapphire)
|
155
|
+
|
156
|
+
nor = all.reject { |e|
|
157
|
+
e.estimate_of_type == sapphire.class.polymorphic_name
|
158
|
+
}.reject { |e|
|
159
|
+
e.estimate_of_id == sapphire.id
|
160
|
+
}
|
161
|
+
assert_equal [cars(:honda)], nor
|
162
|
+
|
163
|
+
without_sapphire = PriceEstimate.where.not(
|
164
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
165
|
+
)
|
166
|
+
assert_equal nor, without_sapphire.map(&:estimate_of)
|
167
|
+
```
|
168
|
+
|
169
|
+
In Rails 6.1:
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
sapphire = treasures(:sapphire)
|
173
|
+
|
174
|
+
nand = all - [sapphire]
|
175
|
+
assert_equal [treasures(:diamond), cars(:honda)], nand
|
176
|
+
|
177
|
+
without_sapphire = PriceEstimate.where.not(
|
178
|
+
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
|
179
|
+
)
|
180
|
+
assert_equal nand, without_sapphire.map(&:estimate_of)
|
181
|
+
```
|
182
|
+
|
183
|
+
*Ryuta Kamizono*
|
184
|
+
|
185
|
+
* Fix dirty tracking after rollback.
|
186
|
+
|
187
|
+
Fixes #15018, #30167, #33868.
|
188
|
+
|
189
|
+
*Ryuta Kamizono*
|
190
|
+
|
191
|
+
* Add `ActiveRecord::Relation#cache_version` to support recyclable cache keys via
|
192
|
+
the versioned entries in `ActiveSupport::Cache`. This also means that
|
193
|
+
`ActiveRecord::Relation#cache_key` will now return a stable key that does not
|
194
|
+
include the max timestamp or count any more.
|
195
|
+
|
196
|
+
NOTE: This feature is turned off by default, and `cache_key` will still return
|
197
|
+
cache keys with timestamps until you set `ActiveRecord::Base.collection_cache_versioning = true`.
|
198
|
+
That's the setting for all new apps on Rails 6.0+
|
199
|
+
|
200
|
+
*Lachlan Sylvester*
|
201
|
+
|
202
|
+
* Fix dirty tracking for `touch` to track saved changes.
|
203
|
+
|
204
|
+
Fixes #33429.
|
205
|
+
|
206
|
+
*Ryuta Kamzono*
|
207
|
+
|
208
|
+
* `change_column_comment` and `change_table_comment` are invertible only if
|
209
|
+
`to` and `from` options are specified.
|
210
|
+
|
211
|
+
*Yoshiyuki Kinjo*
|
212
|
+
|
213
|
+
* Don't call commit/rollback callbacks when a record isn't saved.
|
214
|
+
|
215
|
+
Fixes #29747.
|
216
|
+
|
217
|
+
*Ryuta Kamizono*
|
218
|
+
|
219
|
+
* Fix circular `autosave: true` causes invalid records to be saved.
|
220
|
+
|
221
|
+
Prior to the fix, when there was a circular series of `autosave: true`
|
222
|
+
associations, the callback for a `has_many` association was run while
|
223
|
+
another instance of the same callback on the same association hadn't
|
224
|
+
finished running. When control returned to the first instance of the
|
225
|
+
callback, the instance variable had changed, and subsequent associated
|
226
|
+
records weren't saved correctly. Specifically, the ID field for the
|
227
|
+
`belongs_to` corresponding to the `has_many` was `nil`.
|
228
|
+
|
229
|
+
Fixes #28080.
|
230
|
+
|
231
|
+
*Larry Reid*
|
232
|
+
|
233
|
+
* Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options.
|
234
|
+
|
235
|
+
Before:
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
239
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
240
|
+
add_column :items, :attr3, :integer, limit: 10 # => ActiveRecordError
|
241
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
|
242
|
+
```
|
243
|
+
|
244
|
+
After:
|
245
|
+
|
246
|
+
```ruby
|
247
|
+
add_column :items, :attr1, :binary, size: 10 # => ArgumentError
|
248
|
+
add_column :items, :attr2, :decimal, scale: 10 # => ArgumentError
|
249
|
+
add_column :items, :attr3, :integer, limit: 10 # => ArgumentError
|
250
|
+
add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
|
251
|
+
```
|
252
|
+
|
253
|
+
*Ryuta Kamizono*
|
254
|
+
|
255
|
+
* Association loading isn't to be affected by scoping consistently
|
256
|
+
whether preloaded / eager loaded or not, with the exception of `unscoped`.
|
257
|
+
|
258
|
+
Before:
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
Post.where("1=0").scoping do
|
262
|
+
Comment.find(1).post # => nil
|
263
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
264
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
265
|
+
end
|
266
|
+
```
|
267
|
+
|
268
|
+
After:
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
Post.where("1=0").scoping do
|
272
|
+
Comment.find(1).post # => #<Post id: 1, ...>
|
273
|
+
Comment.preload(:post).find(1).post # => #<Post id: 1, ...>
|
274
|
+
Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
|
275
|
+
end
|
276
|
+
```
|
277
|
+
|
278
|
+
Fixes #34638, #35398.
|
279
|
+
|
280
|
+
*Ryuta Kamizono*
|
281
|
+
|
282
|
+
* Add `rails db:prepare` to migrate or setup a database.
|
283
|
+
|
284
|
+
Runs `db:migrate` if the database exists or `db:setup` if it doesn't.
|
285
|
+
|
286
|
+
*Roberto Miranda*
|
287
|
+
|
288
|
+
* Add `after_save_commit` callback as shortcut for `after_commit :hook, on: [ :create, :update ]`.
|
289
|
+
|
290
|
+
*DHH*
|
291
|
+
|
292
|
+
* Assign all attributes before calling `build` to ensure the child record is visible in
|
293
|
+
`before_add` and `after_add` callbacks for `has_many :through` associations.
|
294
|
+
|
295
|
+
Fixes #33249.
|
296
|
+
|
297
|
+
*Ryan H. Kerr*
|
298
|
+
|
299
|
+
* Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation.
|
300
|
+
|
301
|
+
```
|
302
|
+
account.memberships.extract_associated(:user)
|
303
|
+
# => Returns collection of User records
|
304
|
+
```
|
305
|
+
|
306
|
+
*DHH*
|
307
|
+
|
308
|
+
* Add `ActiveRecord::Relation#annotate` for adding SQL comments to its queries.
|
309
|
+
|
310
|
+
For example:
|
311
|
+
|
312
|
+
```
|
313
|
+
Post.where(id: 123).annotate("this is a comment").to_sql
|
314
|
+
# SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */
|
315
|
+
```
|
316
|
+
|
317
|
+
This can be useful in instrumentation or other analysis of issued queries.
|
318
|
+
|
319
|
+
*Matt Yoho*
|
320
|
+
|
321
|
+
* Support Optimizer Hints.
|
322
|
+
|
323
|
+
In most databases, a way to control the optimizer is by using optimizer hints,
|
324
|
+
which can be specified within individual statements.
|
325
|
+
|
326
|
+
Example (for MySQL):
|
327
|
+
|
328
|
+
Topic.optimizer_hints("MAX_EXECUTION_TIME(50000)", "NO_INDEX_MERGE(topics)")
|
329
|
+
# SELECT /*+ MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(topics) */ `topics`.* FROM `topics`
|
330
|
+
|
331
|
+
Example (for PostgreSQL with pg_hint_plan):
|
332
|
+
|
333
|
+
Topic.optimizer_hints("SeqScan(topics)", "Parallel(topics 8)")
|
334
|
+
# SELECT /*+ SeqScan(topics) Parallel(topics 8) */ "topics".* FROM "topics"
|
335
|
+
|
336
|
+
See also:
|
337
|
+
|
338
|
+
* https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html
|
339
|
+
* https://pghintplan.osdn.jp/pg_hint_plan.html
|
340
|
+
* https://docs.oracle.com/en/database/oracle/oracle-database/12.2/tgsql/influencing-the-optimizer.html
|
341
|
+
* https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-query?view=sql-server-2017
|
342
|
+
* https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.perf.doc/doc/c0070117.html
|
343
|
+
|
344
|
+
*Ryuta Kamizono*
|
345
|
+
|
346
|
+
* Fix query attribute method on user-defined attribute to be aware of typecasted value.
|
347
|
+
|
348
|
+
For example, the following code no longer return false as casted non-empty string:
|
349
|
+
|
350
|
+
```
|
351
|
+
class Post < ActiveRecord::Base
|
352
|
+
attribute :user_defined_text, :text
|
353
|
+
end
|
354
|
+
|
355
|
+
Post.new(user_defined_text: "false").user_defined_text? # => true
|
356
|
+
```
|
357
|
+
|
358
|
+
*Yuji Kamijima*
|
359
|
+
|
360
|
+
* Quote empty ranges like other empty enumerables.
|
361
|
+
|
362
|
+
*Patrick Rebsch*
|
363
|
+
|
364
|
+
* Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
|
365
|
+
allowing bulk inserts akin to the bulk updates provided by `update_all` and
|
366
|
+
bulk deletes by `delete_all`.
|
367
|
+
|
368
|
+
Supports skipping or upserting duplicates through the `ON CONFLICT` syntax
|
369
|
+
for PostgreSQL (9.5+) and SQLite (3.24+) and `ON DUPLICATE KEY UPDATE` syntax
|
370
|
+
for MySQL.
|
371
|
+
|
372
|
+
*Bob Lail*
|
373
|
+
|
374
|
+
* Add `rails db:seed:replant` that truncates tables of each database
|
375
|
+
for current environment and loads the seeds.
|
376
|
+
|
377
|
+
*bogdanvlviv*, *DHH*
|
378
|
+
|
379
|
+
* Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.
|
380
|
+
|
381
|
+
*bogdanvlviv*
|
382
|
+
|
383
|
+
* Deprecate mismatched collation comparison for uniqueness validator.
|
384
|
+
|
385
|
+
Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.
|
386
|
+
To continue case sensitive comparison on the case insensitive column,
|
387
|
+
pass `case_sensitive: true` option explicitly to the uniqueness validator.
|
388
|
+
|
389
|
+
*Ryuta Kamizono*
|
390
|
+
|
391
|
+
* Add `reselect` method. This is a short-hand for `unscope(:select).select(fields)`.
|
392
|
+
|
393
|
+
Fixes #27340.
|
394
|
+
|
395
|
+
*Willian Gustavo Veiga*
|
396
|
+
|
397
|
+
* Add negative scopes for all enum values.
|
398
|
+
|
399
|
+
Example:
|
400
|
+
|
401
|
+
class Post < ActiveRecord::Base
|
402
|
+
enum status: %i[ drafted active trashed ]
|
403
|
+
end
|
404
|
+
|
405
|
+
Post.not_drafted # => where.not(status: :drafted)
|
406
|
+
Post.not_active # => where.not(status: :active)
|
407
|
+
Post.not_trashed # => where.not(status: :trashed)
|
408
|
+
|
409
|
+
*DHH*
|
410
|
+
|
411
|
+
* Fix different `count` calculation when using `size` with manual `select` with DISTINCT.
|
412
|
+
|
413
|
+
Fixes #35214.
|
414
|
+
|
415
|
+
*Juani Villarejo*
|
416
|
+
|
417
|
+
|
418
|
+
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
419
|
+
|
420
|
+
* No changes.
|
421
|
+
|
422
|
+
|
423
|
+
## Rails 6.0.0.beta2 (February 25, 2019) ##
|
424
|
+
|
425
|
+
* Fix prepared statements caching to be enabled even when query caching is enabled.
|
426
|
+
|
427
|
+
*Ryuta Kamizono*
|
428
|
+
|
429
|
+
* Ensure `update_all` series cares about optimistic locking.
|
430
|
+
|
431
|
+
*Ryuta Kamizono*
|
432
|
+
|
433
|
+
* Don't allow `where` with non numeric string matches to 0 values.
|
434
|
+
|
435
|
+
*Ryuta Kamizono*
|
436
|
+
|
437
|
+
* Introduce `ActiveRecord::Relation#destroy_by` and `ActiveRecord::Relation#delete_by`.
|
438
|
+
|
439
|
+
`destroy_by` allows relation to find all the records matching the condition and perform
|
440
|
+
`destroy_all` on the matched records.
|
441
|
+
|
442
|
+
Example:
|
443
|
+
|
444
|
+
Person.destroy_by(name: 'David')
|
445
|
+
Person.destroy_by(name: 'David', rating: 4)
|
446
|
+
|
447
|
+
david = Person.find_by(name: 'David')
|
448
|
+
david.posts.destroy_by(id: [1, 2, 3])
|
449
|
+
|
450
|
+
`delete_by` allows relation to find all the records matching the condition and perform
|
451
|
+
`delete_all` on the matched records.
|
452
|
+
|
453
|
+
Example:
|
454
|
+
|
455
|
+
Person.delete_by(name: 'David')
|
456
|
+
Person.delete_by(name: 'David', rating: 4)
|
457
|
+
|
458
|
+
david = Person.find_by(name: 'David')
|
459
|
+
david.posts.delete_by(id: [1, 2, 3])
|
460
|
+
|
461
|
+
*Abhay Nikam*
|
462
|
+
|
463
|
+
* Don't allow `where` with invalid value matches to nil values.
|
464
|
+
|
465
|
+
Fixes #33624.
|
466
|
+
|
467
|
+
*Ryuta Kamizono*
|
468
|
+
|
469
|
+
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`.
|
470
|
+
|
471
|
+
*Ryuta Kamizono*
|
472
|
+
|
473
|
+
* Deprecate using class level querying methods if the receiver scope
|
474
|
+
regarded as leaked. Use `klass.unscoped` to avoid the leaking scope.
|
475
|
+
|
476
|
+
*Ryuta Kamizono*
|
477
|
+
|
478
|
+
* Allow applications to automatically switch connections.
|
479
|
+
|
480
|
+
Adds a middleware and configuration options that can be used in your
|
481
|
+
application to automatically switch between the writing and reading
|
482
|
+
database connections.
|
483
|
+
|
484
|
+
`GET` and `HEAD` requests will read from the replica unless there was
|
485
|
+
a write in the last 2 seconds, otherwise they will read from the primary.
|
486
|
+
Non-get requests will always write to the primary. The middleware accepts
|
487
|
+
an argument for a Resolver class and an Operations class where you are able
|
488
|
+
to change how the auto-switcher works to be most beneficial for your
|
489
|
+
application.
|
490
|
+
|
491
|
+
To use the middleware in your application you can use the following
|
492
|
+
configuration options:
|
493
|
+
|
494
|
+
```
|
495
|
+
config.active_record.database_selector = { delay: 2.seconds }
|
496
|
+
config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
|
497
|
+
config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
|
498
|
+
```
|
499
|
+
|
500
|
+
To change the database selection strategy, pass a custom class to the
|
501
|
+
configuration options:
|
502
|
+
|
503
|
+
```
|
504
|
+
config.active_record.database_selector = { delay: 10.seconds }
|
505
|
+
config.active_record.database_resolver = MyResolver
|
506
|
+
config.active_record.database_resolver_context = MyResolver::MyCookies
|
507
|
+
```
|
508
|
+
|
509
|
+
*Eileen M. Uchitelle*
|
510
|
+
|
511
|
+
* MySQL: Support `:size` option to change text and blob size.
|
512
|
+
|
513
|
+
*Ryuta Kamizono*
|
514
|
+
|
515
|
+
* Make `t.timestamps` with precision by default.
|
516
|
+
|
517
|
+
*Ryuta Kamizono*
|
518
|
+
|
519
|
+
|
1
520
|
## Rails 6.0.0.beta1 (January 18, 2019) ##
|
2
521
|
|
3
522
|
* Remove deprecated `#set_state` from the transaction object.
|
@@ -32,7 +551,7 @@
|
|
32
551
|
|
33
552
|
*Rafael Mendonça França*
|
34
553
|
|
35
|
-
* Deprecate `config.
|
554
|
+
* Deprecate `config.active_record.sqlite3.represent_boolean_as_integer`.
|
36
555
|
|
37
556
|
*Rafael Mendonça França*
|
38
557
|
|
@@ -120,7 +639,7 @@
|
|
120
639
|
|
121
640
|
*Gannon McGibbon*
|
122
641
|
|
123
|
-
* Cached columns_hash fields should be excluded from ResultSet#column_types
|
642
|
+
* Cached `columns_hash` fields should be excluded from `ResultSet#column_types`.
|
124
643
|
|
125
644
|
PR #34528 addresses the inconsistent behaviour when attribute is defined for an ignored column. The following test
|
126
645
|
was passing for SQLite and MySQL, but failed for PostgreSQL:
|
@@ -151,12 +670,12 @@
|
|
151
670
|
|
152
671
|
* Make the implicit order column configurable.
|
153
672
|
|
154
|
-
When calling ordered finder methods such as
|
673
|
+
When calling ordered finder methods such as `first` or `last` without an
|
155
674
|
explicit order clause, ActiveRecord sorts records by primary key. This can
|
156
675
|
result in unpredictable and surprising behaviour when the primary key is
|
157
676
|
not an auto-incrementing integer, for example when it's a UUID. This change
|
158
677
|
makes it possible to override the column used for implicit ordering such
|
159
|
-
that
|
678
|
+
that `first` and `last` will return more predictable results.
|
160
679
|
|
161
680
|
Example:
|
162
681
|
|
@@ -226,7 +745,7 @@
|
|
226
745
|
|
227
746
|
*Sean Griffin*
|
228
747
|
|
229
|
-
* Add support for hash and
|
748
|
+
* Add support for hash and URL configs in database hash of `ActiveRecord::Base.connected_to`.
|
230
749
|
|
231
750
|
````
|
232
751
|
User.connected_to(database: { writing: "postgres://foo" }) do
|
@@ -302,10 +821,10 @@
|
|
302
821
|
|
303
822
|
* Enum raises on invalid definition values
|
304
823
|
|
305
|
-
When defining a Hash enum it can be easy to use [] instead of {}
|
824
|
+
When defining a Hash enum it can be easy to use `[]` instead of `{}`. This
|
306
825
|
commit checks that only valid definition values are provided, those can
|
307
826
|
be a Hash, an array of Symbols or an array of Strings. Otherwise it
|
308
|
-
raises an ArgumentError
|
827
|
+
raises an `ArgumentError`.
|
309
828
|
|
310
829
|
Fixes #33961
|
311
830
|
|
@@ -399,7 +918,7 @@
|
|
399
918
|
*Darwin Wu*
|
400
919
|
|
401
920
|
* Configuration item `config.filter_parameters` could also filter out
|
402
|
-
sensitive values of database columns when
|
921
|
+
sensitive values of database columns when calling `#inspect`.
|
403
922
|
We also added `ActiveRecord::Base::filter_attributes`/`=` in order to
|
404
923
|
specify sensitive attributes to specific model.
|
405
924
|
|
@@ -454,8 +973,8 @@
|
|
454
973
|
|
455
974
|
Iterating over the database configurations has also changed. Instead of
|
456
975
|
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
|
458
|
-
`spec_name` arguments are optional. For example these return an array of
|
976
|
+
been provided that allows you to select the correct configuration. `env_name` and
|
977
|
+
`spec_name` arguments are optional. For example, these return an array of
|
459
978
|
database config objects for the requested environment and a single database config object
|
460
979
|
will be returned for the requested environment and specification name respectively.
|
461
980
|
|