aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract
Commit message (Collapse)AuthorAgeFilesLines
* Add support for UNLOGGED Postgresql tablesJacob Evelyn2018-11-131-1/+6
| | | | | | | | | | | 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.
* 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
|
* Add an :if_not_exists option to create_tablefatkodima2018-11-083-4/+10
| | | | [fatkodima & Stefan Kanev]
* Always add records to parent of nested transactionEugene Kenny2018-11-071-1/+1
| | | | | | | | | | | | | | | | | | | 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]
* Remove and flip `index: true` for `references` in the doc [ci skip]Ryuta Kamizono2018-10-172-8/+8
| | | | Follow up #32146.
* Move UPDATE/DELETE with JOIN handling to the Arel sideRyuta Kamizono2018-10-031-17/+0
|
* Merge pull request #23593 from meinac/add_index_option_for_change_tableRyuta Kamizono2018-10-011-0/+2
|\ | | | | | | index option added for change_table migrations
| * Index option added for change_table migrationsMehmet Emin INAC2018-09-221-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In case if we want to add a column into the existing table with index on it, we have to add column and index in two seperate lines. With this feature we don't need to write an extra line to add index for column. We can just use `index` option. Old behaviour in action: ``` change_table(:languages) do |t| t.string :country_code t.index: :country_code end ``` New behaviour in action: ``` change_table(:languages) do |t| t.string :country_code, index: true end ``` Exactly same behaviour is already exist for `create_table` migrations.
* | Merge pull request #32031 from yahonda/remove_redundant_freezeRyuta Kamizono2018-10-011-3/+3
|\ \ | | | | | | Add `Style/RedundantFreeze` to remove redudant `.freeze`
| * | Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-291-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since Rails 6.0 will support Ruby 2.4.1 or higher `# frozen_string_literal: true` magic comment is enough to make string object frozen. This magic comment is enabled by `Style/FrozenStringLiteralComment` cop. * Exclude these files not to auto correct false positive `Regexp#freeze` - 'actionpack/lib/action_dispatch/journey/router/utils.rb' - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb' It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333 Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed. * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required - 'actionpack/test/controller/test_case_test.rb' - 'activemodel/test/cases/type/string_test.rb' - 'activesupport/lib/active_support/core_ext/string/strip.rb' - 'activesupport/test/core_ext/string_ext_test.rb' - 'railties/test/generators/actions_test.rb'
* | | Place `PartialQuery` and `PartialQueryCollector` in the same fileRyuta Kamizono2018-09-301-23/+1
|/ /
* / Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-234-7/+7
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
* Use utf8mb4 in all tests and examplesRyuta Kamizono2018-09-211-2/+2
| | | | | Since #33875, Rails dropped supporting MySQL 5.1 which does not support utf8mb4. We no longer need to use legacy utf8 (utf8mb3) conservatively.
* Fallback to unprepared statement only when bind params limit is exceededRyuta Kamizono2018-09-142-0/+10
| | | | | | | | | | | This is a follow up and/or an alternative of #33844. Unlike #33844, this would attempt to construct unprepared statement only when bind params limit (mysql2 65535, pg 65535, sqlite3 249999) is exceeded. I only defined 65535 as the limit, not defined 249999 for sqlite3, since it is an edge case, I'm not excited to add less worth extra code.
* Consistently use `visitor.compile`Ryuta Kamizono2018-09-091-3/+3
|
* Merge pull request #33809 from fidalgo/improve-remove-column-documentationRichard Schneeman2018-09-061-0/+1
|\ | | | | [ci skip] Improve remove_column documentation
| * [ci skip] Improve remove_column documentationPaulo Fidalgo2018-09-061-0/+1
| | | | | | | | | | | | | | | | Since when we remove one column it will also remove the associated indexes, we must ensure this behaviour is properly documented. In this commit we add a line to the documentation mentioning this behaviour.
* | Deprecate most methods which were never used in `DatabaseLimits`Ryuta Kamizono2018-09-051-0/+9
| | | | | | | | | | | | | | | | | | `DatabaseLimits` and those methods were introduced at 3809c80, but most methods were never used and never tested from the beginning (except `table_alias_length`, `index_name_length`, and `in_clause_length` (since 66c09372)). There is no reason to maintain unused those methods for about 8 years.
* | Add documentation for `:collation` column option (#33733)Nate Pinsky2018-08-271-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | * Add documentation for `:collation` option The table definition supports a `:collation` option for string and text columns, but this is not documented anywhere that I could find. I'm not sure if the "If not specified" part is accurate. From [this PR](https://github.com/rails/rails/commit/1515c4d98da3f730ef971fa5a13cad828bd9bef4), it looks like it passes `nil` and lets the database handle the collation, but I'm happy to change it if I misread the code. [ci skip] * FIX remove whitespace [Nate Pinsky + Rafael Mendonça França]
* | Merge pull request #31696 from BrentWheeldon/bmw-connection-pool-load-deadlockMatthew Draper2018-08-241-1/+3
|\ \ | | | | | | Prevent deadlocks when waiting for connection from pool.
| * | Prevent deadlocks when waiting for connection from pool.Brent Wheeldon2018-03-231-1/+3
| | | | | | | | | | | | | | | When a thread that had the load interlock but was blocked waiting to check a connection out of the connection pool but all of the threads using the available connections were blocked waiting to obtain the load interlock an `ActiveRecord::ConnectionTimeoutError` exception was be thrown by the thread waiting for the connection. When waiting for the connection to check out we should allow loading to proceed to avoid this deadlock.
* | | Merge pull request #32647 from eugeneius/lazy_transactionsMatthew Draper2018-08-232-14/+66
|\ \ \ | | | | | | | | Omit BEGIN/COMMIT statements for empty transactions
| * | | Omit BEGIN/COMMIT statements for empty transactionsEugene Kenny2018-08-132-14/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a transaction is opened and closed without any queries being run, we can safely omit the `BEGIN` and `COMMIT` statements, as they only exist to modify the connection's behaviour inside the transaction. This removes the overhead of those statements when saving a record with no changes, which makes workarounds like `save if changed?` unnecessary. This implementation buffers transactions inside the transaction manager and materializes them the next time the connection is used. For this to work, the adapter needs to guard all connection use with a call to `materialize_transactions`. Because of this, adapters must opt in to get this new behaviour by implementing `supports_lazy_transactions?`. If `raw_connection` is used to get a reference to the underlying database connection, the behaviour is disabled and transactions are opened eagerly, as we can't know how the connection will be used. However when the connection is checked back into the pool, we can assume that the application won't use the reference again and reenable lazy transactions. This prevents a single `raw_connection` call from disabling lazy transactions for the lifetime of the connection.
* | | | Follow up #33530bogdanvlviv2018-08-151-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Move changelog entry of #33530 up in order to preserve the chronology since we always add new entries on the top of a changelog file. - Clarify the changelog entry - Clarify the docs of remove_foreign_key - Ensure reversible of `remove_foreign_key` with `:primary_key` and `:to_table` options.
* | | | Allow `to_table` in `invert_remove_foreign_key`Rich2018-08-141-1/+8
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | remove_foreign_key supports - remove_foreign_key :accounts, :branches - remove_foreign_key :accounts, to_table: :branches but the second one is not reversible. This branch is to fix and allow second one to be reversible. [Nikolay Epifanov, Rich Chen]
* | | `retrieve_connection_pool` return a pool, not a connectionRyuta Kamizono2018-08-031-2/+2
| | |
* | | [ci skip] Tidy up formatting of examplesOrhan Toy2018-07-221-12/+3
| | | | | | | | | | | | The consecutive verbatim blocks were being merged making the output look weird.
* | | Implement change() to convert to "2001-01-01" firstSean Prashad2018-07-171-0/+1
| |/ |/| | | | | (cherry picked from commit da34d4766c33a042aeb92778a492fa810ec23001)
* | Add ability to configure cache notifications infoEileen Uchitelle2018-06-121-6/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This may seem like an unnecessary refactoring but some apps want / need to configure the information passed to the query cache logger. In order to do that we can add a method here that can be easily overridden by the app itself, rather than hacking the query cache logger to include that information. To override apps can call ``` def cache_notifications_info super.merge(connected_host: "hostname") end ``` This will take what's already in the query cache logger and add `@something="yea"` to the object. At GitHub we use this to log the number of queries that are cached, the connection host and the connection url.
* | Migrations will raise an exception if there are multiple column definitions ↵Federico Martinez2018-06-011-2/+6
| | | | | | | | (same name).
* | Bump minimum SQLite version to 3.8Yasuo Honda2018-05-211-7/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | These OS versions have SQLite 3.8 or higher by default. - macOS 10.10 (Yosemite) or higher - Ubuntu 14.04 LTS or higher Raising the minimum version of SQLite 3.8 introduces these changes: - All of bundled adapters support `supports_multi_insert?` - SQLite 3.8 always satisifies `supports_foreign_keys_in_create?` and `supports_partial_index?` - sqlite adapter can support `alter_table` method for foreign key referenced tables by #32865 - Deprecated `supports_multi_insert?` method
* | Finalize transaction record state after real transactionEugene Kenny2018-05-191-14/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After a real (non-savepoint) transaction has committed or rolled back, the original persistence-related state for all records modified in that transaction is discarded or restored, respectively. When the model has transactional callbacks, this happens synchronously in the `committed!` or `rolled_back!` methods; otherwise, it happens lazily the next time the record's persistence-related state is accessed. The synchronous code path always finalizes the state of the record, but the lazy code path only pops one "level" from the transaction counter, assuming it will always reach zero immediately after a real transaction. As the test cases included here demonstrate, that isn't always the case. By using the same logic as the synchronous code path, we ensure that the record's state is always updated after a real transaction has finished.
* | Remove :nodoc: from the methods which is added the doc [ci skip]Ryuta Kamizono2018-05-151-4/+4
| | | | | | | | Follow up of #19171 and #26825.
* | Add available transformations to docs [ci skip]wata_mac2018-05-131-0/+3
| | | | | | | | `foreign_key`, `json` and `virtual` are also available.
* | Restore original merging order to enforce `if_exists: true`Ryuta Kamizono2018-04-291-2/+1
| | | | | | | | | | The merging order was accidentally changed at #32447. The original intention is force `drop_table ... if_exists: true`. #28070.
* | Allow `primary_key` argument to `empty_insert_statement_value`Yasuo Honda2018-04-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | to support Oracle database support identity data type Oracle database does not support `INSERT .. DEFAULT VALUES` then every insert statement needs at least one column name specified. When `prefetch_primary_key?` returns `true` insert statement always have the primary key name since the primary key value is selected from the associated sequence. However, supporting identity data type will make `prefetch_primary_key?` returns `false` then no primary key column name added. As a result, `empty_insert_statement_value` raises `NotImplementedError` To address this error `empty_insert_statement_value` can take one argument `primary_key` to generate insert statement like this. `INSERT INTO "POSTS" ("ID") VALUES(DEFAULT)` It needs arity change for the public method but no actual behavior changes for the bundled adapters. Oracle enhanced adapter `empty_insert_statement_value` implementation will be like this: ``` def empty_insert_statement_value(primary_key) raise NotImplementedError unless primary_key "(#{quote_column_name(primary_key)}) VALUES(DEFAULT)" end ``` [Raise NotImplementedError when using empty_insert_statement_value with Oracle](https://github.com/rails/rails/pull/28029) [Add support for INSERT .. DEFAULT VALUES](https://community.oracle.com/ideas/13845)
* | Remove unused attr_writer :joinable on TransactionEugene Kenny2018-04-171-1/+0
| | | | | | | | | | This was added in 280587588aba6ce13717cd6679e3f2b43d287443, but has been unused since 392eeecc11a291e406db927a18b75f41b2658253.
* | passing splat keyword arguments as a single Hashutilum2018-04-041-2/+3
| | | | | | | | Ruby 2.6.0 warns about this.
* | Remove `ForeignKeys` module which was introduced at #32299Ryuta Kamizono2018-04-021-1/+1
| | | | | | | | | | | | | | To solve the problem #32299, just enough to introduce `fk_ignore_pattern` option. I don't think there is a need to expose these constants.
* | Move fk_ignore_pattern from config.active_record to SchemaDumperDavid Stosik2018-03-221-1/+1
| | | | | | | | | | This makes more sense, as the foreign key ignore pattern is only used by the schema dumper.
* | Expose foreign key name ignore pattern in configurationDavid Stosik2018-03-192-1/+5
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | When dumping the database schema, Rails will dump foreign key names only if those names were not generate by Rails. Currently this is determined by checking if the foreign key name is `fk_rails_` followed by a 10-character hash. At [Cookpad](https://github.com/cookpad), we use [Departure](https://github.com/departurerb/departure) (Percona's pt-online-schema-change runner for ActiveRecord migrations) to run migrations. Often, `pt-osc` will make a copy of a table in order to run a long migration without blocking it. In this copy process, foreign keys are copied too, but [their name is prefixed with an underscore to prevent name collision ](https://www.percona.com/doc/percona-toolkit/LATEST/pt-online-schema-change.html#cmdoption-pt-online-schema-change-alter-foreign-keys-method). In the process described above, we often end up with a development database that contains foreign keys which name starts with `_fk_rails_`. That name does not match the ignore pattern, so next time Rails dumps the database schema (eg. when running `rake db:migrate`), our `db/schema.rb` file ends up containing those unwanted foreign key names. This also produces an unwanted git diff that we'd prefer not to commit. In this PR, I'd like to suggest a way to expose the foreign key name ignore pattern to the Rails configuration, so that individual projects can decide on a different pattern of foreign keys that will not get their names dumped in `schema.rb`.
* Ensure that leading date is stripped by quoted_timeAndrew White2018-03-111-1/+1
| | | | | | | | In #24542, quoted_time was introduced to strip the leading date component for time columns because it was having a significant effect in mariadb. However, it assumed that the date component was always 2000-01-01 which isn't the case, especially if the source wasn't another time column.
* Deprecate `active_support/core_ext/hash/compact`yuuji.yaginuma2018-03-021-2/+0
| | | | | Ruby 2.4+ provides `Hash#compact` and `Hash#compact!` natively, so `active_support/core_ext/hash/compact` is no longer necessary.
* PostgreSQL adapter also supports bulk alter since #31331 [ci skip]yuuji.yaginuma2018-03-021-1/+1
|
* Use `delegate private: true` for `SchemaCreation`Ryuta Kamizono2018-03-021-3/+2
| | | | Duplicated method name list is no longer needed.
* Rails 6 requires Ruby 2.3+Jeremy Daer2018-02-171-6/+1
|
* Fix frozen string concatenation by indicating that it's mutableJeremy Daer2018-02-161-1/+1
| | | | References 89bcca59e91fa9da941de890012872e8288e77b0
* Remove usage of strip_heredoc in the framework in favor of <<~Rafael Mendonça França2018-02-161-4/+2
| | | | | Some places we can't remove because Ruby still don't have a method equivalent to strip_heredoc to be called in an already existent string.
* Bring back ability to insert zero value on primary key for fixtures (#31795)Ryuta Kamizono2018-01-261-1/+4
| | | | | | Since #29504, mysql2 adapter lost ability to insert zero value on primary key due to enforce `NO_AUTO_VALUE_ON_ZERO` disabled. That is for using `DEFAULT` on auto increment column, but we can use `NULL` instead in that case.