| Commit message (Collapse) | Author | Age | Files | Lines |
|\
| |
| | |
Exercise `connected_to` and `connects_to` methods
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Since both methods are public API I think it makes sense to add these tests
in order to prevent any regression in the behavior of those methods after the 6.0 release.
Exercise `connected_to`
- Ensure that the method raises with both `database` and `role` arguments
- Ensure that the method raises without `database` and `role`
Exercise `connects_to`
- Ensure that the method returns an array of established connections(as mentioned
in the docs of the method)
Related to #34052
|
| |
| |
| |
| |
| |
| | |
This commit fixes a small typo in documentation of the
"UNLOGGED" table option for PostgreSQL databases, and
clarifies the documentation slightly.
|
| |
| |
| | |
[ci skip]
|
|/
|
|
|
|
|
|
|
| |
* Arel: Implemented DB-aware NULL-safe comparison
* Fixed where clause inversion for NULL-safe comparison
* Renaming "null_safe_eq" to "is_not_distinct_from", "null_safe_not_eq" to "is_distinct_from"
[Dmytro Shteflyuk + Rafael Mendonça França]
|
|\
| |
| |
| | |
Fix: Arel now emits a single pair of parens for UNION and UNION ALL
|
| |
| |
| |
| |
| |
| |
| |
| | |
mysql has a great implementation to suppress multiple parens for union
sql statements.
This moves that functionality to the generic implementation
This also introduces that functionality for UNION ALL
|
|\ \
| |/
|/| |
Adjust bind length of SQLite to default (999)
|
| |
| |
| |
| |
| | |
Change `#bind_params_length` in SQLite adapter to return the default
maximum amount (999). See https://www.sqlite.org/limits.html
|
|/
|
|
|
|
|
|
|
|
|
| |
This commit adds support for the
`ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables`
setting, which turns `CREATE TABLE` SQL statements into
`CREATE UNLOGGED TABLE` statements.
This can improve PostgreSQL performance but at the
cost of data durability, and thus it is highly recommended
that you *DO NOT* enable this in a production environment.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
The test added in 12b0b26df7560ab5199ba830586864085441508f passes even
without this code since 9b8c7796a9c2048208aa843ad3dc477dffa8bdee, as the
call to `id` in `remember_transaction_record_state` now triggers a
`sync_with_transaction_state` which discards the leftover state from the
previous transaction.
This issue had already been fixed for `save!`, `destroy` and `touch` in
caae79a385ce112245262a17414bcd96bea013c2, but continued to affect `save`
because the call to `rollback_active_record_state!` in that method would
increment the transaction level before `add_to_transaction` could clear
it, preventing the fix from working correctly.
As `rollback_active_record_state!` was removed entirely in
48007d5390db47fc1223f57c8e7ab3ebb7c3a3d7, this code is no longer needed.
|
|
|
|
| |
Use `t.index ...` instead.
|
| |
|
|
|
|
| |
Since quoted `Infinity` and `NaN` are valid data for PostgreSQL.
|
|
|
|
| |
[fatkodima & Stefan Kanev]
|
| |
|
|
|
|
|
| |
Adds support for multiple databases to `rails db:schema:cache:dump`
and `rails db:schema:cache:clear`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
When a record with transactional callbacks is saved, it's attached to
the current transaction so that the callbacks can be run when the
transaction is committed. Records can also be added manually with
`add_transaction_record`, even if they have no transactional callbacks.
When a nested transaction is committed, its records are transferred to
the parent transaction, as transactional callbacks should only be run
when the outermost transaction is committed (the "real" transaction).
However, this currently only happens when the record has transactional
callbacks, and not when added manually with `add_transaction_record`.
If a record is added to a nested transaction, we should always attach it
to the parent transaction when the nested transaction is committed,
regardless of whether it has any transactional callbacks.
[Eugene Kenny & Ryuta Kamizono]
|
|
|
|
|
|
|
|
|
|
|
| |
The `read_attribute` method always returns the primary key when asked to
read the `id` attribute, even if the primary key isn't named `id`, and
even if another attribute named `id` exists.
For the `inspect`, `attribute_for_inspect` and `pretty_print` methods,
this behaviour is undesirable, as they're used to examine the internal
state of the record. By using `_read_attribute` instead, we'll get the
real value of the `id` attribute.
|
| |
|
|
|
|
|
|
|
| |
The `model_metadata` is only used if `model_class` is given.
If `model_class` is given, the `table_name` is always
`model_class.table_name`.
|
|
|
|
|
|
|
|
|
|
| |
The `@connection` is no longer used since ee5ab22.
Originally the `@connection` was useless because it is only used in
`timestamp_column_names`, which is only used if `model_class` is given.
If `model_class` is given, the `@connection` is always
`model_class.connection`.
|
| |
|
|
|
|
| |
It was executing a delete_all method with wrong parameter
|
|
|
|
| |
Caused at #34196.
|
|\
| |
| | |
Fix example for database-specific locking clause
|
| |
| |
| |
| | |
[ci skip]
|
|/
|
|
|
| |
b63701e moved the assignment before the query, but we need to capture
our old id before assignment in case we are assigning the id.
|
|
|
|
|
|
|
|
|
| |
Previosly, `update_columns` would just take whatever keys you gave it
and tried to run the update query. Most likely this would result in an
error from the database. However, if the column actually did exist, but
was in `ignored_columns`, this would result in the method returning
successfully when it should have raised, and an attribute that should
not exist written to `@attributes`.
|
|\
| |
| | |
Avoid violating key constraints in fixture HABTM associations
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
When loading fixtures, Ruby 1.9's hash key ordering means that HABTM
join table rows are always loaded before the parent table rows,
violating foreign key constraints that may be in place. This very
simple change ensures that the parent table's key appears first in the
hash. Violations may still occur if fixtures are loaded in the wrong
order but those instances can be avoided unlike this one.
|
|\ \
| | |
| | | |
Add support for hash and url configs to be used in connected_to
|
| | |
| | |
| | |
| | |
| | | |
Add support for hash and url configs in database hash
of `ActiveRecord::Base.connected_to`.
|
| |/
|/| |
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
At https://github.com/rails/rails/commit/fc0e3354af7e7878bdd905a95ce4c1491113af9a,
```rb
relation = relation.where(conditions)
```
was rewritten to:
```rb
relation.where!(condition)
```
This change accidentally changed the result of `Topic.exists?({})` from true to false.
To fix this regression, first I moved the blank check logic (`opts.blank?`) from `#where` to `#where!`,
because I thought `#where!` should be identical to `#where`, except that instead of returning a new relation,
it adds the condition to the existing relation.
But on second thought after some discussion on https://github.com/rails/rails/pull/34329,
I started to think that just fixing `#construct_relation_for_exists` is more preferable
than changing `#where` and `#where!`.
|
|\
| |
| | |
Implement AR#inspect using ParameterFilter
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
AR instance support `filter_parameters` since #33756.
Though Regex or Proc is valid as `filter_parameters`,
they are not supported as AR#inspect.
I also add :mask option and #filter_params to
`ActiveSupport::ParameterFilter#new` to implement this.
|
| |
| |
| |
| |
| |
| |
| | |
MySQL 8.0.13 and higher supports default value to be a function or
expression.
https://dev.mysql.com/doc/refman/8.0/en/create-table.html
|
| |
| |
| |
| |
| |
| |
| | |
MySQL 8.0.13 and higher supports functional key parts that index
expression values rather than column or column prefix values.
https://dev.mysql.com/doc/refman/8.0/en/create-index.html
|
|\ \
| | |
| | | |
Lazy checking whether or not values in IN clause are boundable
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Since #33844, eager loading/preloading with too many and/or too large
ids won't be broken by pre-checking whether the value is constructable
or not.
But the pre-checking caused the type to be evaluated at relation build
time instead of at the query execution time, that is breaking an
expectation for some apps.
I've made the pre-cheking lazy as much as possible, that is no longer
happend at relation build time.
|
| | | |
|
| | | |
|
|/ /
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
when user has no parent table access privileges
Refer https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-13.html#mysqld-8-0-13-errors
>>
* Previously, the ER_NO_REFERENCED_ROW_2 and ER_ROW_IS_REFERENCED_2 error messages
for foreign key operations were displayed and revealed information about parent tables,
even when the user had no parent table access privileges. Error handling for this situation has been revised:
* If the user does have table-level privileges for all parent tables,
ER_NO_REFERENCED_ROW_2 and ER_ROW_IS_REFERENCED_2 are displayed, the same as before.
* If the user does not have table-level privileges for all parent tables,
more generic error messages are displayed instead (ER_NO_REFERENCED_ROW and ER_ROW_IS_REFERENCED).
<<
This pull request addresses these 3 failures:
```ruby
$ ARCONN=mysql2 bundle exec ruby -w -Itest test/cases/adapter_test.rb -n /foreign/
Using mysql2
Run options: -n /foreign/ --seed 14251
F
Failure:
ActiveRecord::AdapterForeignKeyTest#test_foreign_key_violations_are_translated_to_specific_exception_with_validate_false [test/cases/adapter_test.rb:348]:
[ActiveRecord::InvalidForeignKey] exception expected, not
Class: <ActiveRecord::StatementInvalid>
Message: <"Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails: INSERT INTO `fk_test_has_fk` (`fk_id`) VALUES (1231231231)">
... snip ...
rails test test/cases/adapter_test.rb:343
F
Failure:
ActiveRecord::AdapterForeignKeyTest#test_foreign_key_violations_on_delete_are_translated_to_specific_exception [test/cases/adapter_test.rb:368]:
[ActiveRecord::InvalidForeignKey] exception expected, not
Class: <ActiveRecord::StatementInvalid>
Message: <"Mysql2::Error: Cannot delete or update a parent row: a foreign key constraint fails: DELETE FROM fk_test_has_pk WHERE pk_id = 1">
... snip ...
rails test test/cases/adapter_test.rb:365
F
Failure:
ActiveRecord::AdapterForeignKeyTest#test_foreign_key_violations_on_insert_are_translated_to_specific_exception [test/cases/adapter_test.rb:358]:
[ActiveRecord::InvalidForeignKey] exception expected, not
Class: <ActiveRecord::StatementInvalid>
Message: <"Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails: INSERT INTO fk_test_has_fk (fk_id) VALUES (0)">
... snip ...
rails test test/cases/adapter_test.rb:357
Finished in 0.087370s, 34.3366 runs/s, 34.3366 assertions/s.
3 runs, 3 assertions, 3 failures, 0 errors, 0 skips
$
```
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
When `attr_name` is passed as a symbol, it's currently converted to a
string by `attribute_alias?`, and potentially also `attribute_alias`,
as well as by the `read_attribute`/`write_attribute` method itself.
By converting `attr_name` to a string up front, the extra allocations
related to attribute aliases can be avoided.
|
| | |
|
|\ \
| | |
| | | |
ActiveRecord#respond_to? No longer allocates strings
|
| |/
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
This is an alternative to https://github.com/rails/rails/pull/34195
The active record `respond_to?` method needs to do two things if `super` does not say that the method exists. It has to see if the "name" being passed in represents a column in the table. If it does then it needs to pass it to `has_attribute?` to see if the key exists in the current object. The reason why this is slow is that `has_attribute?` needs a string and most (almost all) objects passed in are symbols.
The only time we need to allocate a string in this method is if the column does exist in the database, and since these are a limited number of strings (since column names are a finite set) then we can pre-generate all of them and use the same string.
We generate a list hash of column names and convert them to symbols, and store the value as the string name. This allows us to both check if the "name" exists as a column, but also provides us with a string object we can use for the `has_attribute?` call.
I then ran the test suite and found there was only one case where we're intentionally passing in a string and changed it to a symbol. (However there are tests where we are using a string key, but they don't ship with rails).
As re-written this method should never allocate unless the user passes in a string key, which is fairly uncommon with `respond_to?`.
This also eliminates the need to special case every common item that might come through the method via the `case` that was originally added in https://github.com/rails/rails/commit/f80aa5994603e684e3fecd3f53bfbf242c73a107 (by me) and then with an attempt to extend in https://github.com/rails/rails/pull/34195.
As a bonus this reduces 6,300 comparisons (in the CodeTriage app homepage) to 450 as we also no longer need to loop through the column array to check for an `include?`.
|
| |
| |
| |
| | |
Follow up #32146.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
`init_with` and `init_from_db` are almost the same code except decode
`coder`.
And also, named `init_from_db` is a little misreading, a raw values hash
from the database is already converted to an attributes object by
`attributes_builder.build_from_database`, so passed `attributes` in that
method is just an attributes object.
I renamed that method to `init_with_attributes` since the method is
shared with `init_with` to initialize an empty model object.
|