aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
Commit message (Collapse)AuthorAgeFilesLines
...
* | | | PostgreSQL 10 new relkind for partitioned tables (#31336)Yannick Schutz2018-07-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * PostgreSQL 10 new relkind for partitioned tables Starting with PostgreSQL 10, we can now have partitioned tables natively * Add comment * Remove extra space * Add test for partition table in postgreSQL10 * Select 'p' for "BASE TABLE" and add a test case to support PostgreSQL 10 partition tables * Address RuboCop offense * Addressed incorrect `postgresql_version` Fixes #33008. [Yannick Schutz & Yasuo Honda & Ryuta Kamizono]
* | | | Merge pull request #32381 from q-centrix/update-codeclimate-configsRichard Schneeman2018-07-253-5/+3
|\ \ \ \ | | | | | | | | | | Turn on performance based cops
| * | | | Turn on performance based copsDillon Welch2018-07-233-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use attr_reader/attr_writer instead of methods method is 12% slower Use flat_map over map.flatten(1) flatten is 66% slower Use hash[]= instead of hash.merge! with single arguments merge! is 166% slower See https://github.com/rails/rails/pull/32337 for more conversation
* | | | | Normalize time value not to be affected by summer timeRyuta Kamizono2018-07-251-0/+1
|/ / / / | | | | | | | | | | | | Follow up of #33358 for SQLite3.
* | | | [ci skip] Tidy up formatting of examplesOrhan Toy2018-07-221-12/+3
| | | | | | | | | | | | | | | | The consecutive verbatim blocks were being merged making the output look weird.
* | | | Fix `insert_fixtures_set` to be restored original connection flagsRyuta Kamizono2018-07-192-29/+36
| | | | | | | | | | | | | | | | | | | | | | | | #33363 has two regressions. First one is that `insert_fixtures_set` is failed if flags is an array. Second one is that connection flags are not restored if `set_server_option` is not supported.
* | | | Merge pull request #33363 from ahorek/transaction_bugRafael França2018-07-181-5/+23
|\ \ \ \ | | | | | | | | | | use set_server_option if possible
| * | | | use set_server_option if possiblepavel2018-07-151-5/+23
| | | | |
* | | | | Implement change() to convert to "2001-01-01" firstSean Prashad2018-07-171-0/+1
|/ / / / | | | | | | | | | | | | (cherry picked from commit da34d4766c33a042aeb92778a492fa810ec23001)
* | | | SQLite: Don't leak internal schema objectsRyuta Kamizono2018-07-092-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Related #31201. If creating custom primary key (like a string) in SQLite, it would also create an internal index implicitly which named begin with "sqlite_". It need to be hidden since the internal object names are reserved and prohibited for public use. See https://www.sqlite.org/fileformat2.html#intschema Fixes #33320.
* | | | Fix default value for mysql time types with specified precisionNikolay Kondratyev2018-07-041-2/+2
| |/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The TIME, DATETIME, and TIMESTAMP types [have supported](https://mariadb.com/kb/en/library/microseconds-in-mariadb/) a fractional seconds precision from 0 to 6. Default values from time columns with specified precision is read as `current_timestamp(n)` from information schema. rake `db:schema:dump` produces `schema.rb` **without** default values for time columns with the specified precision: t.datetime "last_message_at", precision: 6, null: false rake `db:schema:dump` produces `schema.rb` **with** default values for time columns with the specified precision: t.datetime "last_message_at", precision: 6, default: -> { "current_timestamp(6)" }, null: false
* | | Merge pull request #33242 from brasic/sqlite-readonlyRyuta Kamizono2018-07-031-1/+3
|\ \ \ | | | | | | | | | | | | Support readonly option in SQLite3Adapter
| * | | Support readonly option in SQLite3AdapterCarl Brasic2018-07-021-1/+3
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Readonly sqlite database files are very useful as a data format for storing configuration/lookup data that is too complicated for YAML files. But since such files would typically be committed to a source control repository, it's important to ensure that they are truly safe from being inadvertently modified. Unfortunately using unix permissions isn't enough, as sqlite will "helpfully" add the write bit to a database file whenever it's written to. sqlite3-ruby has supported a `:readonly` option since version 1.3.2 (see https://github.com/sparklemotion/sqlite3-ruby/commit/c20c9f5dd2990042) This simply passes that option through to the adapter if present in the config hash. I think this is best considered an adapter-specific option since no other supported database has an identical concept.
* | | Fix formatting of `primary_key` [ci skip]yuuji.yaginuma2018-06-241-2/+2
| | |
* | | 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).
* | Make force equality checking more strictly not to allow serialized attributeRyuta Kamizono2018-05-252-0/+8
| | | | | | | | | | | | | | | | | | | | | | Since #26074, introduced force equality checking to build a predicate consistently for both `find` and `create` (fixes #27313). But the assumption that only array/range attribute have subtype was wrong. We need to make force equality checking more strictly not to allow serialized attribute. Fixes #32761.
* | Disable foreign keys during `alter_table` for sqlite3 adapterYasuo Honda2018-05-221-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Unlike other databases, changing SQLite3 table definitions need to create a temporary table. While changing table operations, the original table needs dropped which caused `SQLite3::ConstraintException: FOREIGN KEY constraint failed` if the table is referenced by foreign keys. This pull request disables foreign keys by `disable_referential_integrity`. Also `disable_referential_integrity` method needs to execute `defer_foreign_keys = ON` to defer re-enabling foreign keys until the transaction is committed. https://www.sqlite.org/pragma.html#pragma_defer_foreign_keys Fixes #31988 - This `defer_foreign_keys = ON` has been supported since SQLite 3.8.0 https://www.sqlite.org/releaselog/3_8_0.html and Rails 6 requires SQLite 3.8 #32923 now - <Models>.reset_column_information added to address `ActiveModel::UnknownAttributeError` ``` Error: ActiveRecord::Migration::ForeignKeyChangeColumnTest#test_change_column_of_parent_table: ActiveModel::UnknownAttributeError: unknown attribute 'name' for ActiveRecord::Migration::ForeignKeyChangeColumnTest::Post. ```
* | Bump minimum SQLite version to 3.8Yasuo Honda2018-05-213-13/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | `SqlTypeMetadata` is :nodoc: class [ci skip]Ryuta Kamizono2018-05-211-0/+1
| | | | | | | | So do not expose `PostgreSQLTypeMetadata` in the doc too.
* | 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.
* | `columns` is cached in the statementRyuta Kamizono2018-04-241-6/+3
| | | | | | | | https://github.com/sparklemotion/sqlite3-ruby/blob/v1.3.13/lib/sqlite3/statement.rb#L101-L104
* | Save a hash allocation in MySQL statement poolEugene Kenny2018-04-232-5/+2
| | | | | | | | There's no need to wrap the statement in a hash with a single key.
* | Allow `primary_key` argument to `empty_insert_statement_value`Yasuo Honda2018-04-202-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Merge pull request #32299 from davidstosik/expose-fk-ignore-patternGuillermo Iguaran2018-03-272-1/+5
|\ \ | |/ |/| Expose foreign key name ignore pattern in configuration
| * 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`.
* | Support mysql2 0.4.x and 0.5.xAaron Stone2018-03-201-1/+1
|/
* Merge pull request #32271 from eileencodes/fix-three-tier-default-connectionEileen M. Uchitelle2018-03-161-1/+0
|\ | | | | Fix default connection handling with three-tier config
| * Fix connection handling with three-tier configeileencodes2018-03-161-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If you had a three-tier config, the `establish_connection` that's called in the Railtie on load can't figure out how to access the default configuration. This is because Rails assumes that the config is the first value in the hash and always associated with the key from the environment. With a three tier config however we need to go one level deeper. This commit includes 2 changes. 1) removes a line from `resolve_all` which was parsing out the the environment from the config so instead of getting ``` { :development => { :primary => { :database => "whatever" } }, :animals => { :database => "whatever-animals" } }, etc with test / prod } ``` We'd instead end up with a config that had no attachment to it's envioronment. ``` { :primary => { :database => "whatever" } :animals => { :database => "whatever-animals" } etc - without test and prod } ``` Not only did this mean that Active Record didn't know how to establish a connection, it didn't have the other necessary configs along with it in the configs list. So fix this I removed the line that deletes these configs. The second thing this commit changes is adding this line to `establish_connection` ``` spec = spec[spec_name.to_sym] if spec[spec_name.to_sym] ``` When you have a three-tier config and don't pass any hash/symbol/env etc to `establish_connection` the resolver will automatically return both the primary and secondary (in this case animals db) configurations. We'll get an `database configuration does not specify adapter` error because AR will try to establish a connection on the `primary` key rather than the `primary` key's config. It assumes that the `development` or default env automatically will return a config hash, but with a three-tier config we actually get a key and config `primary => config`. This fix is a bit of a bandaid because it's not the "correct" way to handle this situation, but it does solve our immediate problem. The new code here is saying "if the config returned from the resolver (I know it's called spec in here but we interchange our meanings a LOT and what is returned is a three-tier config) has a key matching the "primary" spec name, grab the config from the spec and pass that to the estalbish_connection method". This works because if we pass `:animals` or a hash, or `:primary` we'll already have the correct configuration to connect with. This fixes the case where we want Rail to connect with the default connection. Coming soon is a refactoring that should eliminate the need to do this but I need this fix in order to write the multi-db rake tasks that I promised in my RailsConf submission. `@tenderlove` and I are working on the refactoring of the internals for connection management but it won't be ready for a few weeks and this issue has been blocking progress.
* | Fix multiline expression indexes for postgresql (#31621)fatkodima2018-03-161-1/+1
| |
* | 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.
* | Normalize date component when writing to time columnsAndrew White2018-03-111-1/+1
|/ | | | | | | | | | | | | | | For legacy reasons Rails stores time columns on sqlite as full timestamp strings. However because the date component wasn't being normalized this meant that when they were read back they were being prefixed with 2001-01-01 by ActiveModel::Type::Time. This had a twofold result - first it meant that the fast code path wasn't being used because the string was invalid and second it was corrupting the second fractional component being read by the Date._parse code path. Fix this by a combination of normalizing the timestamps on writing and also changing Active Model to be more lenient when detecting whether a string starts with a date component before creating the dummy time value for parsing.
* 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-022-5/+3
| | | | Duplicated method name list is no longer needed.
* Fix `#columsn_for_distinct` of MySQL and PostgreSQLkg8m2018-02-272-2/+2
| | | | | | | Prevent `ActiveRecord::FinderMethods#limited_ids_for` from using correct primary key values even if `ORDER BY` columns include other table's primary key. Fixes #28364.
* PostgreSQL: Allow BC dates like datetime consistentlyRyuta Kamizono2018-02-231-0/+3
| | | | | | | | | BC dates are supported by both date and datetime types. https://www.postgresql.org/docs/current/static/datatype-datetime.html Since #1097, new datetime allows year zero as 1 BC, but new date does not. It should be allowed even in new date consistently.
* PostgreSQL: Treat infinite values in date like datetime consistentlyRyuta Kamizono2018-02-233-1/+23
| | | | | | | | | | | | | | The values infinity and -infinity are supported by both date and timestamp types. https://www.postgresql.org/docs/current/static/datatype-datetime.html#DATATYPE-DATETIME-SPECIAL-TABLE And also, it can not be known whether a value is infinity correctly unless cast a value. I've added `QueryAttribute#infinity?` to handle that case. Closes #27585.
* Use private attr_readerRyuta Kamizono2018-02-231-2/+1
| | | | | Since #32028, Rails 6 requires Ruby 2.3+. No longer needed workaround for Ruby 2.2 "private attribute?" warning.
* Rails 6 requires Ruby 2.3+Jeremy Daer2018-02-172-10/+2
|
* 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-163-13/+9
| | | | | 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.
* Prefer `@connection.abandon_results!` than `@connection.next_result while ↵Ryuta Kamizono2018-02-041-1/+1
| | | | @connection.more_results?`