aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
Commit message (Collapse)AuthorAgeFilesLines
* SQLite: Fix `copy_table` with composite primary keysRyuta Kamizono2017-12-081-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | `connection.primary_key` also return composite primary keys, so `from_primary_key_column` may not be found even if `from_primary_key` is presented. ``` % ARCONN=sqlite3 be ruby -w -Itest test/cases/adapters/sqlite3/sqlite3_adapter_test.rb -n test_copy_table_with_composite_primary_keys Using sqlite3 Run options: -n test_copy_table_with_composite_primary_keys --seed 19041 # Running: E Error: ActiveRecord::ConnectionAdapters::SQLite3AdapterTest#test_copy_table_with_composite_primary_keys: NoMethodError: undefined method `type' for nil:NilClass /path/to/rails/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb:411:in `block in copy_table' ``` This change fixes `copy_table` to do not lose composite primary keys.
* Merge pull request #31327 from aellispierce/custom-id-change-table-sqliteEileen M. Uchitelle2017-12-071-1/+5
|\ | | | | Fix sqlite migrations with custom primary keys
| * Fix sqlite migrations with custom primary keysAshley Ellis Pierce2017-12-061-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, if a record was created with a custom primary key, that table could not be migrated using sqlite. While attempting to copy the table, the type of the primary key was ignored. Once that was corrected, copying the indexes would fail because custom primary keys are autoindexed by sqlite by default. To correct that, this skips copying the index if the index name begins with "sqlite_". This is a reserved word that indicates that the index is an internal schema object. SQLite prohibits applications from creating objects whose names begin with "sqlite_", so this string should be safe to use as a check. ref https://www.sqlite.org/fileformat2.html#intschema
* | SQLite3 valid integer value should be 8 bytes (64-bit signed integer) (#28379)Ryuta Kamizono2017-12-031-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a regression since Rails 4.2. SQLite3 integer is stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value. Assuming default valid value as 4 bytes caused that actual valid value in INTEGER storage class cannot be stored and existing value cannot be found. https://www.sqlite.org/datatype3.html We should allow valid value in INTEGER storage class in SQLite3 to fix the regression. Fixes #22594.
* | Emulate JSON types for SQLite3 adapter (#29664)Ryuta Kamizono2017-12-034-9/+7
| | | | | | | | | | Actually SQLite3 doesn't have JSON storage class (so it is stored as a TEXT like Date and Time). But emulating JSON types is convinient for making database agnostic migrations.
* | `change_column_default` should be executed after type changingRyuta Kamizono2017-12-031-7/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If do not execute a type changing first, filling in default value may be failed. ``` % ARCONN=postgresql be ruby -w -Itest test/cases/migration/compatibility_test.rb -n test_legacy_change_column_with_null_executes_update Using postgresql Run options: -n test_legacy_change_column_with_null_executes_update --seed 20459 E Error: ActiveRecord::Migration::CompatibilityTest#test_legacy_change_column_with_null_executes_update: StandardError: An error has occurred, this and all later migrations canceled: PG::StringDataRightTruncation: ERROR: value too long for type character varying(5) : UPDATE "testings" SET "foo"='foobar' WHERE "foo" IS NULL ```
* | Extract duplicated index column options normalization as ↵Ryuta Kamizono2017-12-035-46/+34
| | | | | | | | | | | | | | `options_for_index_columns` And placed `add_options_for_index_columns` in `schema_statements.rb` consistently to ease to find related code.
* | Refactor `length`, `order`, and `opclass` index options dumpingRyuta Kamizono2017-12-035-24/+30
| |
* | Merge pull request #31230 from dinahshi/postgresql_extract_sqlMatthew Draper2017-12-033-59/+79
|\ \ | | | | | | Extract sql fragment generators from PostgreSQL adapter
| * | Extract sql fragment generators for alter table from PostgreSQL adapterDinah Shi2017-12-023-59/+79
| | |
* | | Fix method name in `validate_constraint` doc [ci skip]yuuji.yaginuma2017-12-021-1/+1
| | |
* | | Add support for invalid foreign keys in PostgresTravis Hunter2017-12-017-1/+84
| |/ |/| | | | | Add validate_constraint and update naming
* | Remove unpaired `}` [ci skip]Ryuta Kamizono2017-12-011-2/+1
| |
* | Merge pull request #19090 from ↵Matthew Draper2017-12-014-15/+66
|\ \ | | | | | | | | | | | | gregnavis/support-postgresql-operator-classes-in-indexes Add support for PostgreSQL operator classes to add_index
| * | Add support for PostgreSQL operator classes to add_indexGreg Navis2017-11-304-15/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for specifying non-default operator classes in PostgreSQL indexes. An example CREATE INDEX query that becomes possible is: CREATE INDEX users_name ON users USING gist (name gist_trgm_ops); Previously it was possible to specify the `gist` index but not the custom operator class. The `add_index` call for the above query is: add_index :users, :name, using: :gist, opclasses: {name: :gist_trgm_ops}
* | | Add :nodoc: to `StatementPool` which is internal used [ci skip]Ryuta Kamizono2017-11-302-4/+2
|/ / | | | | | | | | | | In #30510, `StatementPool` in `AbstractMysqlAdapter` was hidden in the doc. But that class is also had in sqlite3 and postgresql adapters and the base class is :nodoc: class.
* | Drop mysql2 version less than 0.4.3 to guarantee fork safety (#31244)Ryuta Kamizono2017-11-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since #31173, mysql2 adapter depends on `automatic_close` which is introduced since mysql2 0.4.3. So the adapter with the mysql2 version before doesn't work with fork now. ``` % ARCONN=mysql2 be ruby -w -Itest test/cases/connection_adapters/connection_handler_test.rb -n test_forked_child_doesnt_mangle_parent_connection Using mysql2 Run options: -n test_forked_child_doesnt_mangle_parent_connection --seed 19988 /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/connection_adapters/mysql2_adapter.rb:108:in `discard!': undefined method `automatic_close=' for #<Mysql2::Client:0x00007fedaa91dfd0> (NoMethodError) ``` This drops mysql2 version less than 0.4.3 to guarantee fork safety.
* | Add new error class `QueryCanceled` which will be raised when canceling ↵Ryuta Kamizono2017-11-272-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | statement due to user request (#31235) This changes `StatementTimeout` to `QueryCanceled` for PostgreSQL. In MySQL, errno 1317 (`ER_QUERY_INTERRUPTED`) is only used when the query is manually cancelled. But in PostgreSQL, `QUERY_CANCELED` error code (57014) which is used `StatementTimeout` is also used when the both case. And, we can not tell which reason happened. So I decided to introduce new error class `QueryCanceled` closer to the error code name.
* | Rename `TransactionTimeout` to more descriptive `LockWaitTimeout` (#31223)Ryuta Kamizono2017-11-272-2/+2
| | | | | | | | | | | | Since #31129, new error class `StatementTimeout` has been added. `TransactionTimeout` is caused by the timeout shorter than `StatementTimeout`, but its name is too generic. I think that it should be a name that understands the difference with `StatementTimeout`.
* | Merge pull request #31221 from matthewd/flush-idle-connectionsMatthew Draper2017-11-262-16/+66
|\ \ | | | | | | Flush idle database connections
| * | Flush idle database connectionsMatthew Draper2017-11-262-16/+66
| | |
* | | Let rubygems handle our objection to mysql2 0.4.3Matthew Draper2017-11-261-2/+1
| |/ |/|
* | Merge pull request #30510 from yhirano55/add_nodoc_to_activerecordEileen M. Uchitelle2017-11-251-1/+1
|\ \ | | | | | | Add :nodoc: to activerecord [ci skip]
| * | Add :nodoc: to activerecord [ci skip]Yoshiyuki Hirano2017-09-031-1/+1
| | |
* | | Merge pull request #31173 from matthewd/connection-fork-safetyMatthew Draper2017-11-254-0/+58
|\ \ \ | |_|/ |/| | Improve AR connection fork safety
| * | Improve AR connection fork safetyMatthew Draper2017-11-184-0/+58
| | | | | | | | | | | | | | | | | | Use whatever adapter-provided means we have available to ensure forked children don't send quit/shutdown/goodbye messages to the server on connections that belonged to their parent.
* | | Merge pull request #31035 from BrentWheeldon/bmw-db-load-deadlockMatthew Draper2017-11-181-1/+2
|\ \ \ | | | | | | | | Prevent deadlocks with load interlock and DB lock.
| * | | Prevent deadlocks with load interlock and DB lock.Brent Wheeldon2017-11-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes an issue where competing threads deadlock each other. - Thread A holds the load interlock but is blocked on getting the DB lock - Thread B holds the DB lock but is blocked on getting the load interlock (for example when there is a `Model.transaction` block that needs to autoload) This solution allows for dependency loading in other threads while a thread is waiting to acquire the DB lock. Fixes #31019
* | | | Merge pull request #28742 from quixoten/stack_conn_poolMatthew Draper2017-11-171-6/+3
|\ \ \ \ | |_|/ / |/| | | Switch to LIFO for the connection pool
| * | | Fix typosDevin Christensen2017-04-131-1/+1
| | | |
| * | | Improve documentation and add testDevin Christensen2017-04-131-7/+4
| | | |
| * | | Switch to LIFO for the connection poolDevin Christensen2017-04-121-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using a FIFO for the connection pool can lead to issues when there are upstream components (pgbouncer, haproxy, etc.) that terminate connections that are idle after a period of time. Switching to a LIFO reduces the probability that a thread will checkout a connection that is about to be closed by an idle timeout in an upstream component.
* | | | Add new error class `StatementTimeout` which will be raised when statement ↵Ryuta Kamizono2017-11-132-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | timeout exceeded (#31129) We are sometimes using The MAX_EXECUTION_TIME hint for MySQL depending on the situation. It will prevent catastrophic performance down by wrong performing queries. The new error class `StatementTimeout` will make to be easier to handle that case. https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html#optimizer-hints-execution-time
* | | | Raise `TransactionTimeout` when lock wait timeout exceeded for PG adapterRyuta Kamizono2017-11-111-0/+3
| | | | | | | | | | | | | | | | Follow up of #30360.
* | | | Add missing autoload `Type` (#31123)Ryuta Kamizono2017-11-111-1/+0
| |/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Attribute modules (`Attribute`, `Attributes`, `AttributeSet`) uses `Type`, but referencing `Type` before the modules still fail. ``` % ./bin/test -w test/cases/attribute_test.rb -n test_with_value_from_user_validates_the_value Run options: -n test_with_value_from_user_validates_the_value --seed 31876 E Error: ActiveModel::AttributeTest#test_with_value_from_user_validates_the_value: NameError: uninitialized constant ActiveModel::AttributeTest::Type /Users/kamipo/src/github.com/rails/rails/activemodel/test/cases/attribute_test.rb:233:in `block in <class:AttributeTest>' bin/test test/cases/attribute_test.rb:232 Finished in 0.002985s, 335.0479 runs/s, 335.0479 assertions/s. 1 runs, 1 assertions, 0 failures, 1 errors, 0 skips ``` Probably we need more autoloading at least `Type`.
* | | Properly check transaction in persistenceKeenan Brock2017-11-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` [NoMethodError]: undefined method `state' for nil:NilClass Method:[rescue in block in refresh] ``` In `within_new_transaction`, there is the possibility that `begin_transaction` returns a `nil`. (i.e.: so `transaction = nil`) So this method is checking `transaction` for nil in 2 spots. Unfortunately, there is one line that is not checking `transaction` for `nil` That line, `commit_transaction`, throws an exception for us in AR 5.0.0.1 The problem with the method is finally realized in the error checking itself. it calls `transaction.state` (i.e.: nil.state) and that is the final exception raised. The actual underlying (user) issue is hidden by this line. Solution is test transaction for nil.
* | | [ci skip]Update the documentation about the primary key typesuginoy2017-10-292-16/+16
| | | | | | | | | | | | | | | | | | Replace the primary key type `integer` in docs with `bigint`. ref #26266
* | | Merge pull request #30984 from yahonda/schema_dumper_pgRyuta Kamizono2017-10-261-0/+12
|\ \ \ | | | | | | | | Move `extensions` to `PostgreSQL::SchemaDumper`
| * | | Implement `PostgreSQL::SchemaDumper#extensions`Yasuo Honda2017-10-251-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | and abstract `SchemaDumper#extensions` is now an empty method. Since #30337, every database adapter has its own `SchemaDumper`. `extensions` are only supported by PostgreSQL database and postgresql database adapter.
* | | | Merge pull request #30970 from rohitpaulk/fix-sqlite-3-index-order-dumpRafael França2017-10-251-1/+11
|\ \ \ \ | |/ / / |/| | | Save index order :desc to schema.rb (sqlite). Fixes #30902
| * | | Avoid using index_xinfo, only available in sqlite >= 3.8.9Paul Kuruvilla2017-10-251-9/+12
| | | |
| * | | Save index order :desc to schema.rb (sqlite). Fixes #30902Paul Kuruvilla2017-10-241-2/+9
| | | | | | | | | | | | | | | | | | | | Although the sqlite adapter supports index sort orders, they weren't being written to db/schema.rb.
* | | | `supports_extensions?` return always true since PostgreSQL 9.1Yasuo Honda2017-10-241-9/+3
|/ / / | | | | | | | | | | | | | | | | | | | | | since the minimum version of PostgreSQL currently Rails supports is 9.1, there is no need to handle if `supports_extensions?` Refer https://www.postgresql.org/docs/9.1/static/sql-createextension.html "CREATE EXTENSION"
* | | Remove `supports_disable_referential_integrity?`Yasuo Honda2017-10-231-25/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `supports_disable_referential_integrity?` used to handle if PostgreSQL database supports `ALTER TABLE <table name> DISABLE/ENABLE TRIGGER` statements. Refer https://github.com/rails/rails/commit/9a947af0e79cfb8692eb7e5ae94c1b8c40756f49 These statements have been documented since 8.1. https://www.postgresql.org/docs/8.1/static/sql-altertable.html > DISABLE/ENABLE TRIGGER Now Rails supports PostgreSQL 9.1 or higher only. No need to handle `supports_disable_referential_integrity?` anymore. Also, this method does not exist in any other adapters including AbstractAdapter.
* | | Remove deprecated arguments from `#verify!`Rafael Mendonça França2017-10-231-4/+1
| | |
* | | Remove deprecated argument `name` from `#indexes`Rafael Mendonça França2017-10-234-24/+4
| | |
* | | Remove deprecated method `supports_primary_key?`Rafael Mendonça França2017-10-231-5/+0
| | |
* | | Remove deprecated method `supports_migrations?`Rafael Mendonça França2017-10-231-5/+0
| | |
* | | Remove deprecated methods `initialize_schema_migrations_table` and ↵Rafael Mendonça França2017-10-231-10/+0
| | | | | | | | | | | | `initialize_internal_metadata_table`
* | | Remove deprecated argument `default` from `index_name_exists?`Rafael Mendonça França2017-10-232-12/+2
| | |