aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
Commit message (Collapse)AuthorAgeFilesLines
* Set `represent_boolean_as_integer` via `configuration`yuuji.yaginuma2017-07-161-1/+1
|
* Fix boolean column migration scriptyuuji.yaginuma2017-07-131-1/+1
|
* Merge pull request #29699 from lugray/represent_boolean_as_integerMatthew Draper2017-07-123-4/+38
|\ | | | | Change sqlite3 boolean serialization to use 1 and 0
| * Change sqlite3 boolean serialization to use 1 and 0Lisa Ugray2017-07-113-4/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Abstract boolean serialization has been using 't' and 'f', with MySQL overriding that to use 1 and 0. This has the advantage that SQLite natively recognizes 1 and 0 as true and false, but does not natively recognize 't' and 'f'. This change in serialization requires a migration of stored boolean data for SQLite databases, so it's implemented behind a configuration flag whose default false value is deprecated. The flag itself can be deprecated in a future version of Rails. While loaded models will give the correct result for boolean columns without migrating old data, where() clauses will interact incorrectly with old data. While working in this area, also change the abstract adapter to use `"TRUE"` and `"FALSE"` as quoted values and `true` and `false` for unquoted. These are supported by PostreSQL, and MySQL remains overriden.
* | [Action Record] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-111-0/+1
|/
* Merge pull request #29655 from kirs/frozen-friendly-ap-arMatthew Draper2017-07-101-1/+2
|\ | | | | Prepare AP and AR to be frozen string friendly
| * Prepare AP and AR to be frozen string friendlyKir Shatrov2017-07-061-1/+2
| |
* | Merge pull request #29715 from reverbdotcom/ptd/fix-invalid-uuidsMatthew Draper2017-07-091-1/+1
|\ \ | | | | | | Don't allow uuids with orphan curly braces
| * | Don't allow uuids with orphan curly bracespdebelak2017-07-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | The uuid validation regex was allowing uuids to have a single leading curly brace or single trailing curly brace. Saving with such a uuid would cause Postgres to generate an exception even though the record seemed valid. With this change, the regex requires both a leading *and* a trailing curly brace or neither to be valid.
* | | Merge pull request #29692 from fimmtiu/avoid-translating-non-database-exceptionsMatthew Draper2017-07-091-2/+4
|\ \ \ | | | | | | | | Don't translate non-database exceptions.
| * | | Don't translate non-database exceptions.Dennis Taylor2017-07-051-2/+4
| | | | | | | | | | | | | | | | The AbstractAdapter will translate all StandardErrors generated during the course of a query into ActiveRecord::StatementInvalids. Unfortunately, it'll also mangle non-database-related errors generated in ActiveSupport::Notification callbacks after the query has successfully completed. This should prevent it from translating errors from ActiveSupport::Notifications.
* | | | Merge pull request #29706 from ↵Matthew Draper2017-07-091-1/+1
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | kamipo/use_information_schema_to_extract_expression Use `information_schema` to extract `generation_expression` for MariaDB
| * | | | Use `information_schema` to extract `generation_expression` for MariaDBRyuta Kamizono2017-07-071-1/+1
| | |/ / | |/| | | | | | | | | | | | | | | | | | Since MariaDB 10.2.5, `information_schema` supports Virtual Columns. Fixes #29670.
* / | | Fix default `CURRENT_TIMESTAMP` in schema dumping for MariaDB 10.2Ryuta Kamizono2017-07-071-2/+2
|/ / / | | | | | | | | | | | | | | | | | | | | | Since MariaDB 10.2, `CURRENT_TIMESTAMP` is shown as a function (`current_timestamp()`). Fix matching column default to address that case. Fixes #29698.
* / / Fix extracting MariaDB versionRyuta Kamizono2017-07-071-2/+6
|/ / | | | | | | | | | | Currently `version` method always returns `5.5.5` because the `full_version` is `5.5.5-10.x.y-MariaDB...` since MariaDB 10.x. It should be ignored if the prefix is `5.5.5-`.
* / Remove database specific JSON typesRyuta Kamizono2017-07-053-14/+0
|/ | | | We already have database agnostic `Type::Json` since #29220.
* Merge branch 'master' into require_relative_2017Xavier Noria2017-07-0216-81/+130
|\
| * Fix removed version 5.2 to 6.0 in the deprecation messageRyuta Kamizono2017-07-021-1/+1
| | | | | | | | Because the deprecation message is not yet released.
| * Apply record state based on parent transaction stateeileencodes2017-07-011-2/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Let's say you have a nested transaction and both records are saved. Before the outer transaction closes, a rollback is performed. Previously the record in the outer transaction would get marked as not persisted but the inner transaction would get persisted. ```ruby Post.transaction do post_one.save # will get rolled back Post.transaction(requires_new: true) do post_two.save # incorrectly remains marked as persisted end raise ActiveRecord::Rollback end ``` To fix this the PR changes transaction handling to have the child transaction ask the parent how the records should be marked. When there are child transactions, it will always be a SavpointTransaction because the stack isn't empty. From there we pass the parent_transaction to the child SavepointTransaction where we add the children to the parent so the parent can mark the inner transaction as rolledback and thus mark the record as not persisted. `update_attributes_from_transaction_state` uses the `completed?` check to correctly mark all the transactions as rolledback and the inner record as not persisted. ```ruby Post.transaction do post_one.save # will get rolled back Post.transaction(requires_new: true) do post_two.save # with new behavior, correctly marked as not persisted on rollback end raise ActiveRecord::Rollback end ``` Fixes #29320
| * Deprecate and replace `set_state` methodeileencodes2017-07-011-6/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | `set_state` was directly setting the transaction state instance variable. It's better to set the state via specific methods (`rollback!` and `commit!` respectively. While undocumented and untested, it's possible someone is using `set_state` in their app or gem so I've added a deprecation notice to it. No where in the app do we use `nullify!` but I wanted to keep existing behavior while replacing the method with a better pattern.
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-0271-71/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-0271-0/+71
| |\ | | | | | | | | | Enforce frozen string in Rubocop
| | * Enforce frozen string in RubocopKir Shatrov2017-07-0171-0/+71
| | |
| * | Merge pull request #29506 from pat/frozen-string-literalsMatthew Draper2017-07-029-18/+18
| |\ \ | | | | | | | | | | | | Make ActiveSupport frozen-string-literal friendly.
| | * | Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-209-18/+18
| | | |
| * | | Don't cache queries for schema statementsRyuta Kamizono2017-06-3010-55/+70
| | |/ | |/| | | | | | | | | | | | | `test_middleware_caches` is sometimes failed since #29454. The failure is due to schema statements are affected by query caching. Bypassing query caching for schema statements to avoid the issue.
* / | [Active Record] require => require_relativeAkira Matsuda2017-07-017-63/+63
|/ /
* | Should use the same connection in using query cacheRyuta Kamizono2017-06-291-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `test_cache_is_available_when_using_a_not_connected_connection` is always failed if running only the test since #29609. ``` % ARCONN=mysql2 be ruby -w -Itest test/cases/query_cache_test.rb -n test_cache_is_available_when_using_a_not_connected_connection Using mysql2 Run options: -n test_cache_is_available_when_using_a_not_connected_connection --seed 15043 F Finished in 0.070519s, 14.1806 runs/s, 28.3612 assertions/s. 1) Failure: QueryCacheTest#test_cache_is_available_when_using_a_not_connected_connection [test/cases/query_cache_test.rb:336]: 2 instead of 1 queries were executed. Queries: SELECT `tasks`.* FROM `tasks` WHERE `tasks`.`id` = ? LIMIT ? SET NAMES utf8 COLLATE utf8_unicode_ci, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483. Expected: 1 Actual: 2 1 runs, 2 assertions, 1 failures, 0 errors, 0 skips ``` This failure is due to `LogSubscriber` will use not connected `ActiveRecord::Base.connection` even if `Task.connection` is connected. I fixed to always pass `type_casted_binds` to log subscriber to avoid the issue.
* | Merge pull request #29612 from kamipo/use_quote_method_rather_than_single_quoteRafael França2017-06-285-13/+12
|\ \ | | | | | | Use `quote` method rather than single quotes to identifiers in SQL
| * | Use `quote` method rather than single quotes to identifiers in SQLRyuta Kamizono2017-06-295-13/+12
| | | | | | | | | | | | | | | | | | Because identifiers in SQL could include a single quote. Related #24950, #26784.
* | | Merge pull request #29405 from kamipo/locked_should_not_build_arelRafael França2017-06-281-0/+1
|\ \ \ | |/ / |/| | `Relation#locked?` should not build arel
| * | Remove delegating to arel in a relationRyuta Kamizono2017-06-291-0/+1
| | | | | | | | | | | | | | | The delegation was needed since passing `relation` with `relation.bound_attributes`. It should use `relation.arel` in that case.
* | | Avoid begin/rescue in fixture quotingKir Shatrov2017-06-201-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Scalar values like arrays and hashes can't be inserted directly into table. Previously, the way to determine if the value is scalar was to try quoting it. If `quote` raised with an error than the value has to be converted to YAML. This flow is not very obvious. Ideally we could have a `quotable?` method in the connection, but I think that we can avoid begin/rescue block by simply checking if the value is Array or Hash. https://github.com/rails/rails/commit/aa31d21f5f4fc4d679e74a60f9df9706da7de373
* | | Use bulk INSERT to insert fixturesKir Shatrov2017-06-203-6/+73
|/ / | | | | | | | | | | | | | | Improves the performance from O(n) to O(1). Previously it would require 50 queries to insert 50 fixtures. Now it takes only one query. Disabled on sqlite which doesn't support multiple inserts.
* | Merge pull request #29454 from kamipo/fix_exists_queries_with_cacheRafael França2017-06-192-51/+0
|\ \ | | | | | | Fix `Relation#exists?` queries with query cache
| * | Ensure query caching for `select_*` methods in connection adaptersRyuta Kamizono2017-06-152-51/+0
| | |
* | | Merge pull request #29486 from kirs/fixtures-arelRafael França2017-06-191-4/+11
|\ \ \ | |_|/ |/| | Refactor #insert_fixtures to use Arel
| * | Refactor #insert_fixtures to use ArelKir Shatrov2017-06-191-4/+11
| | |
* | | Merge pull request #29455 from kirs/remove-column-with-fk-mysqlGuillermo Iguaran2017-06-161-0/+7
|\ \ \ | | | | | | | | Remove FK together with column in MySQL
| * | | Remove FK together with column in MySQLKir Shatrov2017-06-161-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Unlike with other databses, MySQL doesn't let you remove the column if there's a FK on this column. For better developer experience we want to remove the FK together with the column.
* | | | Merge pull request #29431 from kamipo/fix_create_table_with_query_from_relationMatthew Draper2017-06-171-1/+6
|\ \ \ \ | |_|/ / |/| | | Fix `create_table` with query from relation
| * | | Fix `create_table` with query from relationRyuta Kamizono2017-06-131-1/+6
| | |/ | |/| | | | | | | | | | If a relation has binds, `connection.to_sql(relation)` without binds will generate invalid SQL. It should use `relation.to_sql` in that case.
* / | Fix `dump_schema_information` with empty versionsRyuta Kamizono2017-06-151-1/+1
|/ / | | | | | | Fixes #29460.
* / Remove `null_allowed` option from doc [ci skip]yuuji.yaginuma2017-06-101-2/+1
|/ | | | This option was added in b9fa354. But it does not seem to work.
* [ci skip] Add missing `be`Prathamesh Sonpatki2017-06-031-1/+1
|
* Merge pull request #29135 from ↵Eileen M. Uchitelle2017-06-021-0/+19
|\ | | | | | | | | Nerian/document_support_for_composite_primary_keys Document support for composite primary keys
| * Document support for composite primary keysNerian2017-05-181-0/+19
| |
* | Merge pull request #29220 from kamipo/consolidate_database_specific_json_typesMatthew Draper2017-06-014-7/+5
|\ \ | | | | | | Consolidate database specific JSON types to `Type::Json`
| * | Consolidate database specific JSON types to `Type::Json`Ryuta Kamizono2017-05-304-7/+5
| | |
* | | Support PostgreSQL 10 `pg_sequence`Yasuo Honda2017-05-301-1/+9
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | Another fix for #28780 based on discussions at #28789 - In PostgreSQL 10 each sequence does not know its `min_value`. A new system catalog `pg_sequence` shows it as `seqmin`. Refer https://github.com/postgres/postgres/commit/1753b1b027035029c2a2a1649065762fafbf63f3 - `setval` 3rd argument needs to set to `false` only when the table has no rows to avoid `nextval(<sequence_name>)` returns `2` where `1` is expected. - `min_value` is only necessary when the table has no rows. It used to be necessary since the 3rd argument of `setval` is always `false`.