aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract
Commit message (Collapse)AuthorAgeFilesLines
* Change sqlite3 boolean serialization to use 1 and 0Lisa Ugray2017-07-111-4/+4
| | | | | | | | | | | | | | | | | | | | 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.
* Merge branch 'master' into require_relative_2017Xavier Noria2017-07-025-24/+72
|\
| * 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-0211-11/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-0211-0/+11
| |\ | | | | | | | | | Enforce frozen string in Rubocop
| | * Enforce frozen string in RubocopKir Shatrov2017-07-0111-0/+11
| | |
| * | Merge pull request #29506 from pat/frozen-string-literalsMatthew Draper2017-07-023-6/+6
| |\ \ | | | | | | | | | | | | Make ActiveSupport frozen-string-literal friendly.
| | * | Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-203-6/+6
| | | |
| * | | Don't cache queries for schema statementsRyuta Kamizono2017-06-302-10/+24
| | |/ | |/| | | | | | | | | | | | | `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-011-1/+1
|/ /
* | 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 #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-201-6/+50
|/ / | | | | | | | | | | | | | | 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 #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 #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 #29145 from kamipo/reference_type_should_be_not_nullMatthew Draper2017-05-241-1/+1
|\ \ | | | | | | Both reference id and type should be `NOT NULL` if `null: false` is specified
| * | Both reference id and type should be `NOT NULL` if `null: false` is specifiedRyuta Kamizono2017-05-191-1/+1
| |/ | | | | | | | | | | This is a regression due to #28282. Fixes #29136.
* / [Foreign Key] Don't worry about the building identifier if name is already ↵Mohit Natoo2017-05-101-2/+3
|/ | | | present.
* Clarify deprecation message for #quoted_idMatthew Draper2017-05-051-1/+8
| | | | | In this case, it's the method definition that's more at fault, rather than the current caller.
* Deprecate `supports_statement_cache?`Ryuta Kamizono2017-05-011-2/+3
| | | | | | | | | | | | | | `supports_statement_cache?` was introduced in 3.1.0.beta1 (104d0b2) for bind parameter substitution, but it is no longer used in 3.1.0.rc1 (73ff679). Originally it should respect `prepared_statements` rather than `supports_statement_cache?` (fd39847). One more thing, named `supports_statement_cache?` is pretty misreading. We have `StatementCache` and `StatementPool`. However, `supports_statement_cache?` doesn't mean `StatementCache`, but `StatementPool` unlike its name. https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/statement_cache.rb https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/connection_adapters/statement_pool.rb
* Lock connection before checking it inMatthew Draper2017-04-261-6/+8
|
* Fix typos [ci skip]Tobias Fankhänel2017-04-251-2/+2
| | | | | | | | | 'lookup' is the noun. 'to look up' is the verb. Looked it up just to be sure. cf. https://en.wiktionary.org/wiki/lookup https://en.wiktionary.org/wiki/look_up
* Fix the doc on the `IndexDefinition` [ci skip]Ryuta Kamizono2017-04-171-1/+1
| | | | Since 1a92ae83 all `indexes` methods are under the `SchemaStatements`.
* Refactor `indexes` things in connection adaptersRyuta Kamizono2017-04-161-1/+26
| | | | | | | * Use keyword arguments in `IndexDefinition` to ease to ignore unused options and to avoid to initialize incorrect empty value. * Place it in `SchemaStatements` for consistency. * And tiny tweaks.
* Add comprehensive locking around DB transactionsMatthew Draper2017-04-111-39/+49
| | | | | | | | | | | | | | | | | | Transactional-fixture using tests with racing threads and inter-thread synchronisation inside transaction blocks will now deadlock... but without this, they would just crash. In 5.0, the threads didn't share a connection at all, so it would've worked... but with the main thread inside the fixture transaction, they wouldn't've been able to see each other. So: as far as I can tell, the set of operations this "breaks" never had a compelling use case. Meanwhile, it provides an increased level of coherency to the operational feel of transactional fixtures. If this does cause anyone problems, they're probably best off disabling transactional fixtures on the affected tests, and managing transactions themselves.
* Fix example usage of ActiveRecord::Base.establish_connectionSimon Dawson2017-03-301-1/+1
| | | `ActiveRecord::Base.establish_connection` accepts a single symbol argument to specify a named connection; a single string argument appears to be interpreted as a connection URI
* Make internal methods to privateRyuta Kamizono2017-03-273-34/+51
|
* Fix `LogSubscriber` to allow legacy `binds`Ryuta Kamizono2017-03-231-8/+7
| | | | Follow up of #27939.
* Merge pull request #28487 from kamipo/remove_duplicated_columns_definitionRafael França2017-03-201-3/+5
|\ | | | | Remove duplicated `columns` definition
| * Remove duplicated `columns` definitionRyuta Kamizono2017-03-201-3/+5
| |
* | Merge pull request #27939 from kamipo/fix_select_all_with_legacy_bindsRafael França2017-03-201-1/+5
|\ \ | |/ |/| Fix `select_all` with legacy `binds`
| * Fix `select_all` with legacy `binds`Ryuta Kamizono2017-02-121-1/+5
| | | | | | | | Fixes #27923.
* | Merge pull request #28068 from kamipo/refactor_data_sourcesRafael França2017-03-131-2/+18
|\ \ | | | | | | Extract `data_source_sql` to refactor data source statements
| * | Extract `data_source_sql` to refactor data source statementsRyuta Kamizono2017-02-201-2/+18
| | |
* | | Extract `SchemaMigration.all_versions`Ryuta Kamizono2017-03-061-2/+2
| | | | | | | | | | | | | | | Use `SchemaMigration.all_versions` instead of `SchemaMigration.all.map(&:version)` to avoid to instantiate AR objects.
* | | Remove useless `Migrator.schema_migrations_table_name`Ryuta Kamizono2017-03-051-2/+2
| | | | | | | | | | | | Simply use `SchemaMigration.table_name` instead.
* | | Don't hide method that's been documented API since Rails 2.1Andrew White2017-03-041-3/+3
| | |
* | | Fix `rake db:schema:load` with subdirectoriesRyuta Kamizono2017-03-051-5/+4
| | | | | | | | | | | | | | | | | | | | | | | | Related #25174. `db:schema:load` doesn't work with subdirectories like previous `db:migrate:status`. `Migrator.migration_files` should be used in `assume_migrated_upto_version` to fix the issue.
* | | Don't share `options` with a reference type columnRyuta Kamizono2017-03-041-7/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Sharing `options` causes some unexpected behavior. If `limit: 2` is specified, this means that 2 bytes integer for a reference id column and 2 chars string for a reference type column. Another example, if `unsigned: true` is specified, this means that unsigned integer for a reference id column, but a invalid option for a reference type column. So `options` should not be shared with a reference type column.