aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract
Commit message (Collapse)AuthorAgeFilesLines
* Replacement cycle for readabilityMolchanov Andrey2016-05-091-2/+2
|
* Followup to #24844Jon Moss2016-05-071-0/+2
| | | | | | | Some slight documentation edits and fixes. Also, run remove unnecessary `RuntimeError`. r? @arthurnn
* Update docs for connection handlerArthur Neves2016-05-061-2/+5
| | | | [skip ci]
* s/specification_id/specification_nameArthur Neves2016-05-051-16/+16
|
* inline retrive_conn_pool methodArthur Neves2016-05-051-12/+8
|
* Refactor connection handlerArthur Neves2016-05-051-37/+20
| | | | | | | | | | | | | | | ConnectionHandler will not have any knowlodge of AR models now, it will only know about the specs. Like that we can decouple the two, and allow the same model to use more than one connection. Historically, folks used to create abstract AR classes on the fly in order to have multiple connections for the same model, and override the connection methods. With this, now we can override the `specificiation_id` method in the model, to return a key, that will be used to find the connection_pool from the handler.
* Move remaining current_savepoint_name to savepoints moduleVipul A M2016-04-251-0/+4
|
* Add Expression Indexes and Operator Classes support for PostgreSQLRyuta Kamizono2016-04-241-3/+17
| | | | | | | | | | | | | | | | Example: create_table :users do |t| t.string :name t.index 'lower(name) varchar_pattern_ops' end Fixes #19090. Fixes #21765. Fixes #21819. Fixes #24359. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* remove_index do not fetch indexes if name is specifiedSeva Orlov2016-04-241-1/+7
| | | | | | There is no need to fetch all table indexes in remove_index if name is specified. If name is wrong, then StatementInvalid will be raised. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Include the Savepoints module in all adapters.Vipul A M2016-04-242-8/+1
| | | | | Adapters override `#supports_savepoints?` to return `true` if they support transaction savepoints. Defaults to `false`.
* Merge pull request #24708 from ↵Jeremy Daer2016-04-231-1/+1
|\ | | | | | | | | | | kamipo/move_select_rows_implementation_to_super_class Move `select_rows` implementation to super class
| * Move `select_rows` implementation to super classRyuta Kamizono2016-04-241-1/+1
| |
* | Merge pull request #24705 from kamipo/add_nodoc_to_insert_versions_sqlGuillermo Iguaran2016-04-231-1/+1
|\ \ | | | | | | Add `:nodoc:` to `insert_versions_sql` [ci skip]
| * | Add `:nodoc:` to `insert_versions_sql` [ci skip]Ryuta Kamizono2016-04-241-1/+1
| |/ | | | | | | Follow up to #24685. `insert_versions_sql` is not public API.
* / Remove in the doc about MySQL versions below 5 [ci skip]Ryuta Kamizono2016-04-241-3/+1
|/ | | | | Follow up to #23458. Active Record supports MySQL >= 5.0 now.
* Schema load: Fix dupe version insertJeremy Daer2016-04-221-1/+1
| | | | Re. 6e098284e97250eaed6f30f5c7c362d87da986b0
* https://github.com/rails/rails/commit/42dd2336b31a8d98776d039a2b9fd7f834156a ↵Vipul A M2016-04-231-4/+16
| | | | | | | | | 78 changed INSERT INTO versions to run in 1 single query. This breaks for sqlite versions < 3.7.11, which is especially the case on Ubuntu 12.04 LTS, that has SQLite version 3.7.9 as default. So we check for support for multi insert, before performing single query inserts, else fallback to older version of running multiple queries. [Vipul A M & Yasuo Honda]
* Revert "add doc for `:type` option of `#create_join_table` [ci skip]"प्रथमेश Sonpatki2016-04-211-2/+0
|
* add doc for `:type` option of `#create_join_table` [ci skip]yuuji.yaginuma2016-04-211-0/+2
| | | | Follow up to #24221.
* Merge pull request #24221 from gregmolnar/uuidKasper Timm Hansen2016-04-201-2/+3
|\ | | | | create_join_table should work with uuid
| * add column type option to create_join_table to support uuidGreg Molnar2016-03-171-2/+3
| |
* | `undef_method` is not neededRyuta Kamizono2016-04-191-2/+3
| |
* | Database comments: Treat blank comments as no comment. Don't dump blank ↵Jeremy Daer2016-04-191-1/+1
| | | | | | | | comments.
* | `foreign_key` respects `table_name_prefix` and `table_name_suffix`Ryuta Kamizono2016-04-191-0/+3
| |
* | Merge pull request #23622 from kamipo/primary_key_should_be_not_nullJeremy Daer2016-04-181-1/+1
|\ \ | | | | | | | | | Primary key should be `NOT NULL`
| * | Primary key should be `NOT NULL`Ryuta Kamizono2016-03-121-1/+1
| |/ | | | | | | | | | | | | Follow up to #18228. In MySQL and PostgreSQL, primary key is to be `NOT NULL` implicitly. But in SQLite it must be specified `NOT NULL` explicitly.
* | Database comments: switch to keyword args for new table optionsJeremy Daer2016-04-183-23/+24
| | | | | | | | | | | | * Switch to keyword args where we can without breaking compat. * Use add_table_options! for :options, too. * Some code polish.
* | Merge pull request #22911 from Envek/database_commentsJeremy Daer2016-04-164-11/+51
|\ \ | | | | | | | | | Add support for specifying comments for tables, columns, and indexes in database itself
| * | Add support for specifying comments for tables, columns, and indexes.Andrey Novikov2016-04-164-11/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Comments are specified in migrations, stored in database itself (in its schema), and dumped into db/schema.rb file. This allows to generate good documentation and explain columns and tables' purpose to everyone from new developers to database administrators. For PostgreSQL and MySQL only. SQLite does not support comments at the moment. See docs for PostgreSQL: http://www.postgresql.org/docs/current/static/sql-comment.html See docs for MySQL: http://dev.mysql.com/doc/refman/5.7/en/create-table.html
* | | documentation for add_references index option [ci skip]Vipul A M2016-04-171-1/+10
|\ \ \ | |/ / |/| | documentation for add_references index option [ci skip]
| * | [ci skip] docs for add_references index optionAlex Handley2016-04-161-1/+10
| | | | | | | | | | | | | | | | | | - Add link for finding the addional options for index. - Add example for unique index as this is a common requirement. - Add link in guide for index options.
* | | Add `quoted_time` for truncating the date part of a time column valueRyuta Kamizono2016-04-141-0/+6
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Context #24522. TIME column on MariaDB doesn't ignore the date part of the string when it coerces to time. ``` root@localhost [test] > CREATE TABLE `foos` (`id` int AUTO_INCREMENT PRIMARY KEY, `start` time(0), `finish` time(4)) ENGINE=InnoDB; Query OK, 0 rows affected (0.02 sec) root@localhost [test] > INSERT INTO `foos` (`start`, `finish`) VALUES ('2000-01-01 12:30:00', '2000-01-01 12:30:00.999900'); Query OK, 1 row affected, 2 warnings (0.00 sec) Note (Code 1265): Data truncated for column 'start' at row 1 Note (Code 1265): Data truncated for column 'finish' at row 1 root@localhost [test] > SELECT `foos`.* FROM `foos`; +----+----------+---------------+ | id | start | finish | +----+----------+---------------+ | 1 | 12:30:00 | 12:30:00.9999 | +----+----------+---------------+ 1 row in set (0.00 sec) root@localhost [test] > SELECT `foos`.* FROM `foos` WHERE `foos`.`start` = '2000-01-01 12:30:00' LIMIT 1; Empty set (0.00 sec) root@localhost [test] > SELECT `foos`.* FROM `foos` WHERE `foos`.`start` = '12:30:00' LIMIT 1; +----+----------+---------------+ | id | start | finish | +----+----------+---------------+ | 1 | 12:30:00 | 12:30:00.9999 | +----+----------+---------------+ 1 row in set (0.00 sec) ```
* | Move `@quoted_{column|table}_names` cache up to the abstract adapterRyuta Kamizono2016-03-311-1/+1
| |
* | Fix description for method ↵Bogdan2016-03-271-2/+2
|/ | | | ActiveRecord::ConnectionAdapters::SchemaStatements#add_timestamps [ci skip]
* Merge pull request #24054 from kamipo/extract_default_primary_keyRafael França2016-03-111-1/+5
|\ | | | | Extract `default_primary_key?` to refactor `column_spec_for_primary_key`
| * Extract `default_primary_key?` to refactor `column_spec_for_primary_key`Ryuta Kamizono2016-03-111-1/+5
| |
* | Dump `bigint` instead of `integer` with `limit: 8` for schema dumperRyuta Kamizono2016-03-111-2/+6
|/ | | | | | | | | | | | | | | | | | Before: ```ruby create_table "big_numbers", force: :cascade do |t| t.integer "bigint_column", limit: 8 end ``` After: ```ruby create_table "big_numbers", force: :cascade do |t| t.bigint "bigint_column" end ```
* Fixed comments of add_foreign_key methodSalman Afzal Siddiqui2016-03-101-2/+2
| | | The comments of add_foreign_key method was displaying incorrect constraint name.
* Deprecate `{insert|update|delete}_sql` in `DatabaseStatements`Ryuta Kamizono2016-03-021-0/+3
| | | | | Originally, `{insert|update|delete}_sql` is protected methods. We can use the `{insert|update|delete}` public methods instead.
* Merge pull request #23961 from ↵Rafael França2016-03-011-6/+6
|\ | | | | | | | | kamipo/exclude_name_and_type_from_prepare_column_options Exclude `:name` and `:type` from `prepare_column_options`
| * Exclude `:name` and `:type` from `prepare_column_options`Ryuta Kamizono2016-02-291-6/+6
| | | | | | | | Actually `:name` and `:type` are not column options.
* | Merge pull request #23953 from ↵Rafael França2016-03-011-1/+1
|\ \ | | | | | | | | | | | | kamipo/fix_tests_failure_with_prepared_statements_false Fix tests failure with `prepared_statements: false`
| * | Fix `NoMethodError: undefined method `preparable'`Ryuta Kamizono2016-02-291-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The error occurs with `prepared_statements: false`: ``` $ ARCONN=postgresql bundle exec ruby -w -Itest test/cases/associations_test.rb Using postgresql Run options: --seed 27753 ...E.................................... Finished in 0.713115s, 56.0919 runs/s, 91.1494 assertions/s. 1) Error: AssociationsTest#test_force_reload_is_uncached: NoMethodError: undefined method `preparable' for #<Arel::Visitors::PostgreSQL:0x007f8699702570> /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `block in select_all' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:83:in `cache_sql' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:68:in `select_all' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/querying.rb:39:in `find_by_sql' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:699:in `exec_queries' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/association_relation.rb:32:in `exec_queries' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:580:in `load' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:260:in `records' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation.rb:256:in `to_a' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_association.rb:458:in `get_records' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_association.rb:473:in `find_target' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_association.rb:412:in `load_target' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_proxy.rb:45:in `load_target' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/associations/collection_proxy.rb:983:in `records' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/relation/delegation.rb:39:in `each' test/cases/associations_test.rb:116:in `block (2 levels) in test_force_reload_is_uncached' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:32:in `cache' /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/query_cache.rb:9:in `cache' test/cases/associations_test.rb:115:in `block in test_force_reload_is_uncached' /Users/kamipo/src/github.com/rails/rails/activesupport/lib/active_support/deprecation/reporting.rb:36:in `silence' /Users/kamipo/src/github.com/rails/rails/activesupport/lib/active_support/deprecation/instance_delegator.rb:19:in `silence' test/cases/associations_test.rb:114:in `test_force_reload_is_uncached' ```
* | Merge pull request #23807 from matthewd/executorMatthew Draper2016-03-021-19/+0
|\ \ | | | | | | Publish AS::Executor and AS::Reloader APIs
| * | Publish AS::Executor and AS::Reloader APIsMatthew Draper2016-03-021-19/+0
| |/ | | | | | | | | | | These should allow external code to run blocks of user code to do "work", at a similar unit size to a web request, without needing to get intimate with ActionDipatch.
* | Merge pull request #22170 from ↵Matthew Draper2016-03-021-1/+13
|\ \ | |/ |/| | | | | samphilipd/sam/properly_deallocate_prepared_statements_outside_of_transaction Correctly deallocate prepared statements if we fail inside a transaction
| * Correctly deallocate prepared statements if we fail inside a transactionSam Davies2015-11-051-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Addresses issue #12330 Overview ======== Cached postgres prepared statements become invalidated if the schema changes in a way that it affects the returned result. Examples: - adding or removing a column then doing a 'SELECT *' - removing the foo column then doing a 'SELECT bar.foo' In normal operation this isn't a problem, we can rescue the error, deallocate the prepared statement and re-issue the command. However in PostgreSQL transactions, once any command fails, the transaction becomes 'poisoned' and any subsequent commands will raise InFailedSQLTransaction. This includes DEALLOCATE statements, so the default deallocation strategy instead of removing the cached prepared statement instead raises InFailedSQLTransaction. Why this is bad =============== 1. InFailedSQLTransaction is a fairly cryptic error and doesn't communicate any useful information about what has actually gone wrong. 2. In the naive implementation the prepared statement never gets deallocated - it stays alive for the length of the session taking up memory on the postgres server. 3. It is unsafe to retry the transaction because the bad prepared statement is still in the cache and we would see the exact same failure repeated. Solution ======== If we are outside a transaction we can continue to handle these failures gracefully in the usual way. Inside a transaction instead of issuing a DEALLOCATE command that will certainly fail, we now raise ActiveRecord::PreparedStatementCacheExpired. This can be handled further up the stack, notably inside TransactionManager#within_new_transaction. Here we can make sure to first rollback the transaction, then safely issue DEALLOCATE statements to invalidate the rest of the cached prepared statements. This also allows the user (or some gem) the opportunity to catch this error and voluntarily retry the transaction if a schema change causes the prepared statement cache to become invalidated. Because the outdated statement has been deallocated, we can expect the transaction to succeed on the second try.
* | Merge pull request #22748 from Azzurrio/masterMatthew Draper2016-02-221-1/+1
|\ \ | | | | | | Fix NoMethodError preparable for Arel::Visitors::PostgreSQL
| * | Fix NoMethodError preparable for Arel::Visitors in case prepared statements ↵Azzurrio2016-02-221-1/+1
| | | | | | | | | | | | is falsy
* | | Let t.foreign_key use the same `to_table` twiceGeorge Millo2016-02-151-2/+2
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously if you used `t.foreign_key` twice within the same `create_table` block using the same `to_table`, all statements except the final one would fail silently. For example, the following code: def change create_table :flights do |t| t.integer :from_id, index: true, null: false t.integer :to_id, index: true, null: false t.foreign_key :airports, column: :from_id t.foreign_key :airports, column: :to_id end end Would only create one foreign key, on the column `from_id`. This commit allows multiple foreign keys to the same table to be created within one `create_table` block.