| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|/ / / /
| | | |
| | | |
| | | |
| | | | |
Otherwise `save` method would raise the `ReadOnlyError` against `BEGIN`
and `ROLLBACK` queries.
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
Without this change, mysql2 adapter with prepared statements won't pass
`base_test.rb`.
```
% ARCONN=mysql2 be ruby -w -Itest test/cases/base_test.rb
Using mysql2
Run options: --seed 27614
# Running:
....S..............................F
Failure:
BasicsTest#test_creating_a_record_raises_if_preventing_writes [test/cases/base_test.rb:1493]:
ActiveRecord::ReadOnlyError expected but nothing was raised.
rails test test/cases/base_test.rb:1492
...F
Failure:
BasicsTest#test_deleting_a_record_raises_if_preventing_writes [test/cases/base_test.rb:1513]:
ActiveRecord::ReadOnlyError expected but nothing was raised.
rails test test/cases/base_test.rb:1510
............................................................................................................F
Failure:
BasicsTest#test_updating_a_record_raises_if_preventing_writes [test/cases/base_test.rb:1503]:
ActiveRecord::ReadOnlyError expected but nothing was raised.
rails test test/cases/base_test.rb:1500
..........
Finished in 2.534490s, 62.7345 runs/s, 149.5370 assertions/s.
159 runs, 379 assertions, 3 failures, 0 errors, 1 skips
```
|
| | | |
| | | |
| | | |
| | | | |
Follow up #34505.
|
|\ \ \ \
| | | | |
| | | | | |
Rename error that occurs when writing on a read
|
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
I originally named this `StatementInvalid` because that's what we do in
GitHub, but `@tenderlove` pointed out that this means apps can't test
for or explitly rescue this error. `StatementInvalid` is pretty broad so
I've renamed this to `ReadOnlyError`.
|
|/ / / /
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
* `#create_or_find_by/!`: add more tests
* Fix docs of `create_or_find_by`
This method uses `find_by!` internally.
|
| | | | |
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
`test_serialized_attribute_works_under_concurrent_initial_access` test
Since bd62389307e138ee0f274a9d62697567a3334ea0, isolate test of `test_serialized_attribute_works_under_concurrent_initial_access` fails.
```
$ ./bin/test -w test/cases/serialized_attribute_test.rb -n test_serialized_attribute_works_under_concurrent_initial_access
Using sqlite3
Run options: -n test_serialized_attribute_works_under_concurrent_initial_access --seed 32129
# Running:
E
Error:
SerializedAttributeTest#test_serialized_attribute_works_under_concurrent_initial_access:
ActiveRecord::StatementInvalid: SQLite3::SQLException: no such table:
```
If duplicate an unloaded model, it seems that method invocation for that class
is not guaranteed. Use the original class to avoid it.
|
|\ \ \ \
| | | | |
| | | | | |
Fix attribute decoration leak on serialized attribute test
|
| | | | | |
|
| | | | | |
|
|\ \ \ \ \
| | | | | |
| | | | | |
| | | | | | |
Ensure that `delete_all` on collection proxy returns affected count
|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
Unlike the `Relation#delete_all`, `delete_all` on collection proxy
doesn't return affected count. Since the `CollectionProxy` is a subclass
of the `Relation`, this inconsistency is probably not intended, so it
should return the count consistently.
|
|/ / / / /
| | | | |
| | | | |
| | | | |
| | | | | |
Reset scope after delete on collection association to clear stale
offsets of removed records.
|
|\ \ \ \ \
| | | | | |
| | | | | | |
Pass the `connection` to the `@instrumenter.instrument` method call
|
| | | | | | |
|
|\ \ \ \ \ \
| | | | | | |
| | | | | | | |
Fix NumericData.average test on 2.6.0-dev
|
| |/ / / / / |
|
|/ / / / /
| | | | |
| | | | |
| | | | | |
And hide the `READ_QUERY` internal constant.
|
| | | | |
| | | | |
| | | | |
| | | | | |
See: https://travis-ci.org/rails/rails/jobs/462233144#L1384
|
| | | | |
| | | | |
| | | | |
| | | | | |
[ci skip]
|
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
This PR adds the ability to prevent writes to a database even if the
database user is able to write (ie the database is a primary and not a
replica).
This is useful for a few reasons: 1) when converting your database from
a single db to a primary/replica setup - you can fix all the writes on
reads early on, 2) when we implement automatic database switching or
when an app is manually switching connections this feature can be used
to ensure reads are reading and writes are writing. We want to make sure
we raise if we ever try to write in read mode, regardless of database
type and 3) for local development if you don't want to set up multiple
databases but do want to support rw/ro queries.
This should be used in conjunction with `connected_to` in write mode.
For example:
```
ActiveRecord::Base.connected_to(role: :writing) do
Dog.connection.while_preventing_writes do
Dog.create! # will raise because we're preventing writes
end
end
ActiveRecord::Base.connected_to(role: :reading) do
Dog.connection.while_preventing_writes do
Dog.first # will not raise because we're not writing
end
end
```
|
|\ \ \ \ \
| | | | | |
| | | | | | |
Fix the scoping with query methods in the scope block
|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
Follow up #33394.
#33394 only fixes the case of scoping with klass methods in the scope
block which invokes `klass.all`.
Query methods in the scope block also need to invoke `klass.all` to be
affected by the scoping.
|
| | | | | | |
|
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
Allow aliased attributes to be used in `#update_columns` and `#update`.
|
|\ \ \ \ \ \
| | | | | | |
| | | | | | | |
Improve ActiveRecord::Querying documentation [ci skip]
|
| | |/ / / /
| |/| | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
* Break up long sentences
* Reword some sentences to clarify subject, predicate, and object
* Explain drawbacks of using count_by_sql
|
|/ / / / /
| | | | |
| | | | |
| | | | |
| | | | | |
Fixes issue where "user post" is misinterpreted as "\"user\".\"post\""
when quoting table names with the postgres adapter.
|
|\ \ \ \ \
| |_|_|/ /
|/| | | | |
Patch load error in case GemSpecError
|
| | | | | |
|
|\ \ \ \ \
| | | | | |
| | | | | | |
Use raw time string from DB to generate ActiveRecord#cache_version
|
| | | | | | |
|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
When an `updated_at` column exists on the model, but is not available on the instance (likely due to a select), we should raise an error rather than silently not generating a cache_version. Without this behavior it's likely that cache entries will not be able to be invalidated and this will happen without notice.
This behavior was reported and described by @lsylvester in https://github.com/rails/rails/pull/34197#issuecomment-429668759.
|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
Currently, the `updated_at` field is used to generate a `cache_version`. Some database adapters return this timestamp value as a string that must then be converted to a Time value. This process requires a lot of memory and even more CPU time. In the case where this value is only being used for a cache version, we can skip the Time conversion by using the string value directly.
- This PR preserves existing cache format by converting a UTC string from the database to `:usec` format.
- Some databases return an already converted Time object, in those instances, we can directly use `created_at`.
- The `updated_at_before_type_cast` can be a value that comes from either the database or the user. We only want to optimize the case where it is from the database.
- If the format of the cache version has been changed, we cannot apply this optimization, and it is skipped.
- If the format of the time in the database is not UTC, then we cannot use this optimization, and it is skipped.
Some databases (notably PostgreSQL) returns a variable length nanosecond value in the time string. If the value ends in a zero, then it is truncated For instance instead of `2018-10-12 05:00:00.000000` the value `2018-10-12 05:00:00` is returned. We detect this case and pad the remaining zeros to ensure consistent cache version generation.
Before: Total allocated: 743842 bytes (6626 objects)
After: Total allocated: 702955 bytes (6063 objects)
(743842 - 702955) / 743842.0 # => 5.4% ⚡️⚡️⚡️⚡️⚡️
Using the CodeTriage application and derailed benchmarks this PR shows between 9-11% (statistically significant) performance improvement versus the commit before it.
Special thanks to @lsylvester for helping to figure out a way to preserve the usec format and for helping with many implementation details.
|
|\ \ \ \ \ \
| |_|_|/ / /
|/| | | | | |
Additional types of ResultSet should not contain keys of #attributes_to_define_after_schema_loads
|
| | | | | | |
|
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
Follow up ba4e68f577efc76f351d30a2914e29942b97830e.
|
| | | | | | |
|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
This reverts commit f2ab8b64d4d46d7199f94c3e21021f414a4d259a, reversing
changes made to b9c7305dbe57931a153a540d49ae5d469af61a14.
Reason: `scope.take` is not the same with `scope.to_a.first`.
|
|\ \ \ \ \ \
| |/ / / / /
|/| | | | | |
Reuse code in AR::Association#find_target
|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
Before this patch, singular and collection associations
had different implementations of the #find_target method.
This patch reuses the code properly through extending the low level
methods.
|
|\ \ \ \ \ \
| | | | | | |
| | | | | | | |
Make it possible to override the implicit order column
|
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | | |
When calling ordered finder methods such as +first+ or +last+ without an
explicit order clause, ActiveRecord sorts records by primary key. This
can result in unpredictable and surprising behaviour when the primary
key is not an auto-incrementing integer, for example when it's a UUID.
This change makes it possible to override the column used for implicit
ordering such that +first+ and +last+ will return more predictable
results. For Example:
class Project < ActiveRecord::Base
self.implicit_order_column = "created_at"
end
|
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | | |
This reverts commit d52f74480ae46cd3de7ce697093136b01c7a2172.
Since 24adc20, the `Helpers` constant in the `ActiveRecord` namespace is
not referenced anymore.
|
|/ / / / / /
| | | | | |
| | | | | |
| | | | | | |
It should be referenced by full qualified name from Active Record.
|
|\ \ \ \ \ \
| | | | | | |
| | | | | | | |
Bump the minimum version of PostgreSQL to 9.3
|
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | | |
https://www.postgresql.org/support/versioning/
- 9.1 EOLed on September 2016.
- 9.2 EOLed on September 2017.
9.3 is also not supported since Nov 8, 2018. https://www.postgresql.org/about/news/1905/
I think it may be a little bit early to drop PostgreSQL 9.3 yet.
* Deprecated `supports_ranges?` since no other databases support range data type
* Add `supports_materialized_views?` to abstract adapter
Materialized views itself is supported by other databases, other connection adapters may support them
* Remove `with_manual_interventions`
It was only necessary for PostgreSQL 9.1 or earlier
* Drop CI against PostgreSQL 9.2
|
|\ \ \ \ \ \ \
| |_|/ / / / /
|/| | | | | | |
Test when using MySQL `exec_query` returns `ActiveRecord::Result` all…
|
| |/ / / / /
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
When running `exec_query` with `INSERT` (or other write commands), MySQL
returns `ActiveRecord::Result`.
|