aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
Commit message (Collapse)AuthorAgeFilesLines
* Arel: Implemented DB-aware NULL-safe comparison (#34451)Dmytro Shteflyuk2018-11-1523-1/+492
| | | | | | | | | * 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]
* Merge pull request #34437 from kbrock/union_all_parenRafael Mendonça França2018-11-134-42/+41
|\ | | | | | | Fix: Arel now emits a single pair of parens for UNION and UNION ALL
| * Emit single pair of parens for UNION and UNION ALLKeenan Brock2018-11-134-42/+41
| | | | | | | | | | | | | | | | 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
* | Merge pull request #34436 from gmcgibbon/fix_default_max_bind_length_sqliteRafael França2018-11-132-0/+26
|\ \ | |/ |/| Adjust bind length of SQLite to default (999)
| * Adjust bind length of SQLite to default (999)Gannon McGibbon2018-11-132-0/+26
| | | | | | | | | | Change `#bind_params_length` in SQLite adapter to return the default maximum amount (999). See https://www.sqlite.org/limits.html
* | Merge pull request #34429 from ↵Rafael França2018-11-131-3/+21
|\ \ | | | | | | | | | | | | bogdanvlviv/ensure-that-connected_to-establish_connection Ensure that `ActiveRecord::Base#connected_to` with `:database` establishes connection
| * | Ensure that `ActiveRecord::Base#connected_to` with `:database` establishes ↵bogdanvlviv2018-11-121-3/+21
| | | | | | | | | | | | | | | | | | connection Related to #34052
* | | Add support for UNLOGGED Postgresql tablesJacob Evelyn2018-11-135-1/+110
| |/ |/| | | | | | | | | | | | | | | | | | | 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.
* | Remove ensure from with_transaction_returning_statusEugene Kenny2018-11-111-4/+0
|/ | | | | | | | | | | | | | | | | 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.
* Fix test case for money schema defaultRyuta Kamizono2018-11-121-1/+1
| | | | | | | | Follow up a741208f80dd33420a56486bd9ed2b0b9862234a. Since a741208, `Decimal#serialize` which is superclass of `Money` type is no longer no-op, so it consistently serialize/deserialize a value as a decimal even if schema default.
* Ensure casting by decimal attribute when queryingRyuta Kamizono2018-11-121-2/+8
| | | | | | | | | | Related 34cc301f03aea2e579d6687a9ea9782afc1089a0. `QueryAttribute#value_for_database` calls only `type.serialize`, and `Decimal#serialize` is a no-op unlike other attribute types. Whether or not `serialize` will invoke `cast` is undefined in our test cases, but it actually does not work properly unless it does so for now.
* Deprecate `t.indexes = [...]` which is not by designRyuta Kamizono2018-11-091-2/+5
| | | | Use `t.index ...` instead.
* Refactor to initialize `TableDefinition` by kwargsRyuta Kamizono2018-11-092-4/+14
|
* Test prepared statement cache only if prepared statements is enabledRyuta Kamizono2018-11-091-1/+1
|
* PostgreSQL: Properly quote all `Infinity` and `NaN`Ryuta Kamizono2018-11-092-6/+26
| | | | Since quoted `Infinity` and `NaN` are valid data for PostgreSQL.
* Add an :if_not_exists option to create_tablefatkodima2018-11-085-4/+59
| | | | [fatkodima & Stefan Kanev]
* Guard Enums against definitions with blank label namesChristophe Maximin2018-11-073-1/+27
|
* Add multi-db support to schema cache dump and clearGannon McGibbon2018-11-073-5/+26
| | | | | Adds support for multiple databases to `rails db:schema:cache:dump` and `rails db:schema:cache:clear`.
* Always add records to parent of nested transactionEugene Kenny2018-11-072-1/+12
| | | | | | | | | | | | | | | | | | | 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]
* Amend CVE note and security guide section wordingsGannon McGibbon2018-11-061-3/+3
| | | | | | | Reword first sentence of dep management and CVE section of security guide. Also, reword and move gemspec notes above deps. [ci skip]
* Add CVE note to security guide and gemspecsGannon McGibbon2018-11-061-0/+3
| | | | [ci skip]
* Fix inspect with non-primary key id attributeEugene Kenny2018-11-065-3/+26
| | | | | | | | | | | 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.
* Move `resolve_sti_reflections` which is table row related code into `TableRow`Ryuta Kamizono2018-11-032-89/+78
|
* Don't pass useless `table_name` to `ModelMetadata.new`Ryuta Kamizono2018-11-033-13/+4
| | | | | | | 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`.
* Don't pass unused `connection` to `FixtureSet.new`Ryuta Kamizono2018-11-032-14/+11
| | | | | | | | | | 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`.
* Checking boundable not only `IN` clause but also `NOT IN` clauseRyuta Kamizono2018-11-034-8/+24
|
* Updating sample code on ActiveRecord#before_destroy callback [ci skip]Espartaco Palma2018-10-311-1/+1
| | | | It was executing a delete_all method with wrong parameter
* Fix "warning: shadowing outer local variable - role"Ryuta Kamizono2018-10-311-9/+13
| | | | Caused at #34196.
* Merge pull request #34353 from gmcgibbon/fix_lock_docs_locking_clauseRafael França2018-10-301-3/+3
|\ | | | | Fix example for database-specific locking clause
| * Fix example for database-specific locking clauseGannon McGibbon2018-10-301-3/+3
| | | | | | | | [ci skip]
* | Fix failing testSean Griffin2018-10-301-0/+1
|/ | | | | b63701e moved the assignment before the query, but we need to capture our old id before assignment in case we are assigning the id.
* `update_columns` raises if the column is unknownSean Griffin2018-10-303-4/+15
| | | | | | | | | 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`.
* Merge pull request #19388 from yakara-ltd/fix-habtm-fixture-orderRyuta Kamizono2018-10-302-0/+7
|\ | | | | Avoid violating key constraints in fixture HABTM associations
| * Avoid violating key constraints in fixture HABTM associationsJames Le Cuirot2018-10-292-0/+7
| | | | | | | | | | | | | | | | | | 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.
* | Merge pull request #34196 from gmcgibbon/connection_switch_string_nameEileen M. Uchitelle2018-10-303-6/+63
|\ \ | | | | | | Add support for hash and url configs to be used in connected_to
| * | Add support for hash and url configs in connected_toGannon McGibbon2018-10-263-6/+63
| | | | | | | | | | | | | | | Add support for hash and url configs in database hash of `ActiveRecord::Base.connected_to`.
* | | Exercise HABTM fixtures with foreign key constraintsRyuta Kamizono2018-10-302-45/+52
| | |
* | | Document exception from restrict_with_exception [ci skip]Malcolm Locke2018-10-291-2/+2
| |/ |/|
* | `exists?` with string argument is not invalid typeRyuta Kamizono2018-10-271-5/+13
| | | | | | | | | | | | Any type can be a primary key, so blank string is also valid value. Closes #26356.
* | `create_table` with `:primary_key` option has no effect if `id: false` is givenRyuta Kamizono2018-10-273-8/+6
| | | | | | | | Use column definition with `primary_key: true` instead.
* | Ignore empty condition on #construct_relation_for_existsr7kamura2018-10-272-1/+5
|/ | | | | | | | | | | | | | | | | | | | | | | | 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!`.
* Merge pull request #34208 from yskkin/inspect_with_parameter_filterRyuta Kamizono2018-10-264-32/+90
|\ | | | | Implement AR#inspect using ParameterFilter
| * Implement AR#inspect using ParamterFilter.Yoshiyuki Kinjo2018-10-194-32/+90
| | | | | | | | | | | | | | | | | | 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.
* | Merge pull request #34307 from kamipo/mysql_expression_supportRyuta Kamizono2018-10-268-11/+83
|\ \ | | | | | | Support default expression and expression indexes for MySQL
| * | Support default expression for MySQLRyuta Kamizono2018-10-255-4/+34
| | | | | | | | | | | | | | | | | | | | | 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
| * | Support expression indexes for MySQLRyuta Kamizono2018-10-255-7/+49
| | | | | | | | | | | | | | | | | | | | | 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
* | | Partly revert #31819bogdanvlviv2018-10-261-26/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | The PR#31819 changed `#preloaders_on` and added some test, then #33938 reverted changes that were added to the method in #31819. Since changes in the method were reverted and as mentioned in the comment https://github.com/rails/rails/pull/31819#discussion_r221847481 that titles of the tests added in #31819 don't reflect implementation I think we can remove those test for now.
* | | `assert_called_with` should require `args` argumentbogdanvlviv2018-10-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two main reasons why `assert_called_with` should require `args` argument: 1) If we want to assert that some method should be called and we don't need to check with which arguments it should be called then we should use `assert_called`. 2) `assert_called_with` without `args` argument doesn't assert anything! ```ruby assert_called_with(@object, :increment) do @object.decrement end ``` It causes false assertions in tests that could cause regressions in the project. I found this bug by working on [minitest-mock_expectations](https://github.com/bogdanvlviv/minitest-mock_expectations) gem. This gem is an extension for minitest that provides almost the same method call assertions. I was wondering whether you would consider adding "minitest-mock_expectations" to `rails/rails` instead of private `ActiveSupport::Testing::MethodCallAssertions` module. If yes, I'll send a patch - https://github.com/bogdanvlviv/rails/commit/a970ecc42c3a9637947599f2c13e3762e4b59208
* | | Deterministic connection collation in testsRyuta Kamizono2018-10-251-0/+1
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The default collation for utf8mb4 is changed to utf8mb4_0900_ai_ci in MySQL 8.0, so `test_mysql_connection_collation_is_configured` is affected by MySQL version and/or default_collation_for_utf8mb4 system variable. https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_collation_for_utf8mb4 ``` % ARCONN=mysql2 be ruby -w -Itest test/cases/adapters/mysql2/connection_test.rb -n test_mysql_connection_collation_is_configured Using mysql2 Run options: -n test_mysql_connection_collation_is_configured --seed 10421 # Running: F Failure: Mysql2ConnectionTest#test_mysql_connection_collation_is_configured [test/cases/adapters/mysql2/connection_test.rb:108]: Expected: "utf8mb4_general_ci" Actual: "utf8mb4_0900_ai_ci" rails test test/cases/adapters/mysql2/connection_test.rb:106 Finished in 0.013842s, 72.2450 runs/s, 144.4900 assertions/s. 1 runs, 2 assertions, 1 failures, 0 errors, 0 skips ```
* | Merge pull request #34303 from kamipo/lazy_checking_boundableRafael França2018-10-246-9/+18
|\ \ | | | | | | Lazy checking whether or not values in IN clause are boundable