aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* | [Active Record] require => require_relativeAkira Matsuda2017-07-011-14/+14
|/
* Use `quote` method rather than single quotes to identifiers in SQLRyuta Kamizono2017-06-291-5/+0
| | | | | | Because identifiers in SQL could include a single quote. Related #24950, #26784.
* Consolidate database specific JSON types to `Type::Json`Ryuta Kamizono2017-05-301-2/+1
|
* Deprecate `supports_statement_cache?`Ryuta Kamizono2017-05-011-6/+0
| | | | | | | | | | | | | | `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
* Merge pull request #28883 from yahonda/fix28797Rafael França2017-04-261-1/+1
|\ | | | | PostgreSQL 10 does not convert `CURRENT_DATE` into `('now'::text)::date`
| * PostgreSQL 10 allows `CURRENT_DATE` and `CURRENT_TIMESTAMP` as default functionsYasuo Honda2017-04-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | Address #28797 In the previous versions of PostgreSQL, `CURRENT_DATE` converted to `('now'::text)::date` and `CURRENT_TIMESTAMP` converted to `now()`. Refer these discussions and commit at PostgreSQL : https://www.postgresql.org/message-id/flat/5878.1463098164%40sss.pgh.pa.us#5878.1463098164@sss.pgh.pa.us https://github.com/postgres/postgres/commit/0bb51aa96783e8a6c473c2b5e3725e23e95db834
* | Revert "Merge pull request #27636 from ↵Rafael Mendonça França2017-04-261-6/+0
|/ | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privilege-take-2" This reverts commit c1faca6333abe4b938b98fedc8d1f47b88209ecf, reversing changes made to 8c658a0ecc7f2b5fc015d424baf9edf6f3eb2b0b. See https://github.com/rails/rails/pull/27636#issuecomment-297534129
* Add comprehensive locking around DB transactionsMatthew Draper2017-04-111-12/+20
| | | | | | | | | | | | | | | | | | 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.
* Merge pull request #28052 from kamipo/make_internal_methods_to_privateRafael França2017-03-281-15/+2
|\ | | | | Make internal methods to private
| * Make internal methods to privateRyuta Kamizono2017-03-271-15/+2
| |
* | Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2017-03-261-0/+6
|/ | | | | | | | | | | | | | | privileges (take 2) Re-create https://github.com/rails/rails/pull/21233 eeac6151a5 was reverted (127509c071b4) because it breaks tests. ---------------- ref: 72c1557254 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
* Move comment to inside the method [ci skip]Fumiaki MATSUSHIMA2017-03-231-1/+1
| | | | | | Because this comment is not document for `supports_ranges?` ref: https://github.com/rails/rails/pull/27636#discussion_r107560081
* [PostgreSQL]: Replace deprecated PG constants.Lars Kanis2017-03-221-9/+9
| | | | | The old top level classes PGconn, PGresult and PGError were deprecated since pg-0.13.0: https://github.com/ged/ruby-pg/blob/master/History.rdoc#v0130-2012-02-09-michael-granger-gedfaeriemudorg
* Revert "Merge pull request #28369 from ↵Matthew Draper2017-03-141-2/+2
| | | | | | | | | mylake/reduce-postgresql-adapter-memory-bloat" This reverts commit 192db64452d148c7b51713979459e38407380dc6, reversing changes made to 9893955363cf6358556ed3b36f4538d5b54e9d17. We can't sacrifice correctness for performance.
* Merge pull request #28369 from mylake/reduce-postgresql-adapter-memory-bloatRafael França2017-03-131-2/+2
|\ | | | | 500x memory reduction of 10k schemas for postgresql adapter
| * Use “distinct” to filter redundant types from pg_typeto reduce memory ↵mylake2017-03-101-2/+2
| | | | | | | | bloat especially in multi-schema structure database
* | Merge pull request #28068 from kamipo/refactor_data_sourcesRafael França2017-03-131-1/+1
|\ \ | |/ |/| Extract `data_source_sql` to refactor data source statements
| * Extract `data_source_sql` to refactor data source statementsRyuta Kamizono2017-02-201-1/+1
| |
* | Use `max_identifier_length` for `index_name_length` in PostgreSQL adapterRyuta Kamizono2017-02-271-2/+3
| | | | | | | | | | Actually `index_name_length` depend on `max_identifier_length`, not always 63.
* | Deprecate `supports_migrations?` on connection adaptersRyuta Kamizono2017-02-271-5/+0
| | | | | | | | | | | | | | `supports_migrations?` was added at 4160b518 to determine if schema statements (`create_table`, `drop_table`, etc) are implemented in the adapter. But all tested databases has been supported migrations since a4fc93c3 at least.
* | Push `valid_type?` up to abstract adapterRyuta Kamizono2017-02-261-4/+0
| | | | | | | | | | | | | | `valid_type?` should return true if a type exists in `native_database_types` at least. https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/schema_dumper.rb#L136
* | Ensure test threads share a DB connectioneileencodes2017-02-201-14/+20
|/ | | | | | | | | | | | | | | | | | | | | | | This ensures multiple threads inside a transactional test to see consistent database state. When a system test starts Puma spins up one thread and Capybara spins up another thread. Because of this when tests are run the database cannot see what was inserted into the database on teardown. This is because there are two threads using two different connections. This change uses the statement cache to lock the threads to using a single connection ID instead of each not being able to see each other. This code only runs in the fixture setup and teardown so it does not affect real production databases. When a transaction is opened we set `lock_thread` to `Thread.current` so we can keep track of which connection the thread is using. When we rollback the transaction we unlock the thread and then there will be no left-over data in the database because the transaction will roll back the correct connections. [ Eileen M. Uchitelle, Matthew Draper ]
* Add `default_index_type?` to the generic schema dumper doesn't have the ↵Ryuta Kamizono2017-02-141-0/+4
| | | | knowledge about an index type
* Schema dumping support for PostgreSQL oid typeRyuta Kamizono2017-02-121-1/+2
| | | | Closes #27980
* Schema dumping support for PostgreSQL interval typeRyuta Kamizono2017-02-121-2/+5
| | | | Closes #27979
* Deprecate `supports_primary_key?`Ryuta Kamizono2017-02-121-5/+0
| | | | | | | | | | | | `supports_primary_key?` was added to determine if `primary_key` is implemented in the adapter in f060221. But we already use `primary_key` without `supports_primary_key?` (207f266, 5f3cf42) and using `supports_primary_key?` has been removed in #1318. This means that `supports_primary_key?` is no longer used in the internal and Active Record doesn't work without `primary_key` is implemented (all adapters must implement `primary_key`). Closes #27977
* Refactor `ColumnDefinition` to contain `options` hashRyuta Kamizono2017-02-091-0/+1
| | | | | | Column options are passed as an hash args then used as `options` hash in `add_column_options!`. Converting args to attributes is inconvinient for using options as an hash.
* Merge pull request #27767 from benoittgt/freeze_sql_type_with_get_oid_typeArthur Nogueira Neves2017-01-311-1/+1
|\ | | | | Freeze default empty string for sql_type in get_oid_type
| * Freeze default empty string for sql_type in get_oid_typeBenoit Tigeot2017-01-221-1/+1
| | | | | | | | One empty string allocation per column per row.
* | Simplify Postgres query for column_definitions()Jordan Lewis2017-01-301-5/+5
|/ | | | | | | | | | | | | | column_definitions() needs to fetch the collation for every column, if present. Previously, it did so using a correlated subquery - a subquery that references results from the outer scope. This patch updates the query to remove the subquery in favor of a simpler and more efficient JOIN clause. Running the two queries through EXPLAIN against Postgres additionally shows that the original form with a correlated subquery requires a Nested Loop Left Join, while the new form with a simple JOIN can use a more efficient Merge Left Join.
* Revert "Merge pull request #21233 from ↵Rafael Mendonça França2017-01-031-6/+0
| | | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges" This reverts commit eeac6151a55cb7d5f799e1ae33aa64a839cbc3aa, reversing changes made to 5c40239d3104543e70508360d27584a3e4dc5baf. Reason: Broke the isolated tests. https://travis-ci.org/rails/rails/builds/188721346
* Merge pull request #21233 from ↵Rafael França2017-01-031-0/+6
|\ | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privileges Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser privileges
| * Use `SET CONSTRAINTS` for `disable_referential_integrity` without superuser ↵Fumiaki MATSUSHIMA2016-12-031-0/+6
| | | | | | | | | | | | | | | | | | privileges ref: 72c1557254 - We must use `authors` fixture with `author_addresses` because of its foreign key constraint. - Tests require PostgreSQL >= 9.4.2 because it had a bug about `ALTER CONSTRAINTS` and fixed in 9.4.2.
* | Fix Rubocop violations and fix documentation visibilityRafael Mendonça França2016-12-281-1/+1
| | | | | | | | | | | | Some methods were added to public API in 5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of the public API.
* | Privatize unneededly protected methods in Active RecordAkira Matsuda2016-12-241-4/+2
| |
* | No need to nodoc private methodsAkira Matsuda2016-12-241-11/+11
| |
* | Translate numeric value out of range to the specific exceptionRyuta Kamizono2016-12-061-0/+3
| | | | | | | | Raise `ActiveRecord::RangeError` when values that executed are out of range.
* | Translate NOT NULL violation to the specific exceptionRyuta Kamizono2016-12-061-0/+3
| | | | | | | | | | Raise `ActiveRecord::NotNullViolation` when a record cannot be inserted or updated because it would violate a not null constraint.
* | Change MySQL and Postgresql to use Bigint primary keysJon McCartie2016-12-051-1/+1
|/
* Stop using the `pg` Float encoderSean Griffin2016-12-011-1/+0
| | | | | | | | | | PG's type map assumes that all Ruby floats are going to a field with an OID of type float4 or float8, and generates text which is invalid syntax for other types. Since the gem can handle floats properly without this encoder (albeit slightly slower), we can continue to use that as we have in prior versions of Rails. Fixes #27246
* For `PostgreSQL >= 9.4` use `gen_random_uuid()`Yaw Boakye2016-11-221-0/+4
| | | | | | | | | | Since 9.4, PostgreSQL recommends using `pgcrypto`'s `gen_random_uuid()` to generate version 4 UUIDs instead of the functions in the `uuid-ossp` extension. These changes uses the appropriate UUID function depending on the underlying PostgreSQL server's version, while maintaining `uuid_generate_v4()` in older migrations.
* Permit loads while queries are runningMatthew Draper2016-10-271-2/+8
| | | | | A query may wait on a database-level lock, which could lead to a deadlock between threads.
* Quote table name properlyRyuta Kamizono2016-10-141-1/+1
| | | | If does not quote table name properly, invalid SQL is generated.
* Merge pull request #26208 from nanaya/pg-insensitive-textMatthew Draper2016-10-111-2/+6
|\ | | | | | | Fix case insensitive check for text column in pg
| * Fix case insensitive check for text column in pgnanaya2016-09-011-0/+4
| | | | | | | | There's no 'text to text' casting in the cast table so the feature detection fails.
| * Use proper castingnanaya2016-09-011-2/+2
| |
* | Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-4/+4
|/ | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* Remove deprecated handling of PG PointsSean Griffin2016-08-311-2/+2
| | | | | | | | | | There are some minor changes to the point type as I had forgotten that this will affect the behavior of `t.point` in migrations and the schema dumper so we need to handle those as well. I'll say this again so I can convince myself to come up with a better structure... TYPES SHOULD NOT CARE ABOUT SCHEMA DUMPING AND WE NEED TO BETTER SEPARATE THESE.
* Add `Type.default_value` and use it everywhere for internalRyuta Kamizono2016-08-261-1/+1
| | | | For reduce instantiating `Type::Value`.
* applies remaining conventions across the projectXavier Noria2016-08-061-13/+13
|