aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix index_exists? for PostgreSQL expression indexesStan Hu2019-07-241-2/+4
| | | | | | | | Previously Rails expected indexes to be an array of columns, but for PostgreSQL a expression index can just be a string of text. Handle this by forcing `Index#columns` to be an Array inside `index_exists?`. Closes #36739
* Add database_exists? method to connection adaptersGuilherme Mansur2019-06-171-0/+12
| | | | | | | | When SQLite connects it will silently create a database if the database does not exist. This behaviour causes different issues because of inconsistent behaviour between adapters: #36383, #32914. This commit adds a `database_exists?` method as a way to check the database without creating it. This is a stepping stone to fully resolving the above issues.
* Move while_preventing_writes from conn to handlereileencodes2019-06-141-7/+8
| | | | | | | | | | | | | | | | | If we put the `while_preventing_writes` on the connection then the middleware that sends reads to the primary and ensures they can't write will not work. The `while_preventing_writes` will only be applied to the connection which it's called on - which in the case of the middleware is Ar::Base. This worked fine if you called it directly like `OtherDbConn.connection.while_preventing_writes` but Rails didn't have a way of knowing you wanted to call it on all the connections. The change here moves the `while_preventing_writes` method from the connection to the handler so that it can block writes to all queries for that handler. This will apply to all the connections associated with that handler.
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Update READ_QUERY regexAli Ibrahim2019-02-251-0/+10
| | | | | | | * The READ_QUERY regex would consider reads to be writes if they started with spaces or parens. For example, a UNION query might have parens around each SELECT - (SELECT ...) UNION (SELECT ...). * It will now correctly treat these queries as reads.
* Rename error that occurs when writing on a readEileen Uchitelle2018-12-071-3/+3
| | | | | | | I originally named this `StatementInvalid` because that's what we do in GitHub, but `@tenderlove` pointed out that this means apps can't test for or explitly rescue this error. `StatementInvalid` is pretty broad so I've renamed this to `ReadOnlyError`.
* Add ability to prevent writes to a databaseEileen Uchitelle2018-11-301-0/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR adds the ability to prevent writes to a database even if the database user is able to write (ie the database is a primary and not a replica). This is useful for a few reasons: 1) when converting your database from a single db to a primary/replica setup - you can fix all the writes on reads early on, 2) when we implement automatic database switching or when an app is manually switching connections this feature can be used to ensure reads are reading and writes are writing. We want to make sure we raise if we ever try to write in read mode, regardless of database type and 3) for local development if you don't want to set up multiple databases but do want to support rw/ro queries. This should be used in conjunction with `connected_to` in write mode. For example: ``` ActiveRecord::Base.connected_to(role: :writing) do Dog.connection.while_preventing_writes do Dog.create! # will raise because we're preventing writes end end ActiveRecord::Base.connected_to(role: :reading) do Dog.connection.while_preventing_writes do Dog.first # will not raise because we're not writing end end ```
* Fix `#columsn_for_distinct` of MySQL and PostgreSQLkg8m2018-02-271-10/+10
| | | | | | | 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.
* Add support for PostgreSQL operator classes to add_indexGreg Navis2017-11-301-5/+5
| | | | | | | | | | | | 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}
* Merge remote-tracking branch 'origin/master' into unlock-minitestRafael Mendonça França2017-08-011-4/+6
|\
| * Merge pull request #29732 from kirs/frozen-activerecordRafael França2017-07-211-0/+2
| |\ | | | | | | Use frozen-string-literal in ActiveRecord
| | * Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
| | |
| * | Revert "Extract `bind_param` and `bind_attribute` into `ActiveRecord::TestCase`"Sean Griffin2017-07-211-4/+4
| |/ | | | | | | | | | | | | | | This reverts commit b6ad4052d18e4b29b8a092526c2beef013e2bf4f. This is not something that the majority of Active Record should be testing or care about. We should look at having fewer places rely on these details, not make it easier to rely on them.
* | Merge branch 'master' into unlock-minitestKasper Timm Hansen2017-07-151-8/+8
|\|
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| |
| * PostgreSQL 10 converts unknown OID 705 to text 25Yasuo Honda2017-06-061-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Rename test cases from `unknown` to `unrecognized` since unknown OID is one of possible unrecognized types by Rails - Use "select 'pg_catalog.pg_class'::regclass" whose OID is 2205, which will not be converted to recognized type in PostgreSQL 10. activerecord_unittest=# select oid, typname from pg_type where oid in (2205, 2277); oid | typname ------+---------- 2205 | regclass 2277 | anyarray (2 rows) Addresses #28868
* | Explicitly clear type map before run ↵yuuji.yaginuma2017-06-031-6/+12
|/ | | | | | | | | | | | | | | | `test_only_reload_type_map_once_for_every_unknown_type` Currently, the following test fails. ``` bin/test -a sqlite3_mem --seed 37473 test/cases/relation_test.rb ``` This is due to reset connection in `test_respond_to_for_non_selected_element` postprocessing. This reset is added with #29332 for `test_only_reload_type_map_once_for_every_unknown_type`. Since the above test expects the type map to be empty at the time of test run, I think that it is better to empty the type map before test run.
* Should escape meta characters in regexpRyuta Kamizono2017-05-071-1/+1
|
* Extract `bind_param` and `bind_attribute` into `ActiveRecord::TestCase`Ryuta Kamizono2017-05-041-4/+4
| | | | These are used in tests from anywhere.
* `valid_type?` should accept only supported typesRyuta Kamizono2017-02-281-11/+0
| | | | | | | | | | | | | | | | | | | | `valid_type?` is used in schema dumper to determine if a type is supported. So if `valid_type?(:foobar)` is true, it means that schema dumper is allowed to create `t.foobar`. But it doesn't work. I think that `valid_type?` should accept only supported types. https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/schema_dumper.rb#L135-L142 ```ruby columns.each do |column| raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type) next if column.name == pk type, colspec = @connection.column_spec(column) tbl.print " t.#{type} #{column.name.inspect}" tbl.print ", #{format_colspec(colspec)}" if colspec.present? tbl.puts end ```
* Simplify and optimize Postgres query for primary_keys()Jordan Lewis2017-02-131-6/+0
| | | | | | | | | | | | primary_keys(table) needs to query various metadata tables in Postgres to determine the primary key for the table. Previously, it did so using a complex common table expression against pg_constraint and pg_attribute. This patch simplifies the query by using information_schema tables. This simplifies the logic, making the query far easier to understand, and additionally avoids an expensive unnest, window function query, and common table expression.
* Fix `remove_index` to be able to remove expression indexesRyuta Kamizono2016-12-251-2/+5
| | | | Fixes #26635, #26641.
* Remove unnecessary `test_sql_for_insert_with_returning_disabled`Ryuta Kamizono2016-08-181-6/+0
| | | | | Because `sql_for_insert` is only called in `use_insert_returning?` is true since #26002.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-6/+6
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-2/+2
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-78/+78
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Add Expression Indexes and Operator Classes support for PostgreSQLRyuta Kamizono2016-04-241-0/+16
| | | | | | | | | | | | | | | | 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>
* Deprecate `{insert|update|delete}_sql` in `DatabaseStatements`Ryuta Kamizono2016-03-021-44/+0
| | | | | Originally, `{insert|update|delete}_sql` is protected methods. We can use the `{insert|update|delete}` public methods instead.
* Fix tests failure with `prepared_statements: false`Ryuta Kamizono2016-02-291-61/+23
| | | | | | Some tests does not work for unprepared statements. Add `if ActiveRecord::Base.connection.prepared_statements` and fix a regex for fix tests failure with `prepared_statements: false`.
* Remove duplicated composite primary key testsRyuta Kamizono2016-02-011-8/+0
|
* :speak_no_evil: :warning:Akira Matsuda2016-02-011-1/+3
|
* `sql_for_insert` returns values for passing to `exec_insert`Ryuta Kamizono2016-01-151-2/+2
|
* `substitute_at` is no longer usedRyuta Kamizono2016-01-141-5/+0
| | | | Arel handles substitution for bind parameters by now.
* Merge pull request #21697 from gdeglin/fix_returning_disabled_default_values_bugSean Griffin2015-09-241-0/+14
|\ | | | | | | Fix a bug with returning_disabled when using the postgresql adapter
| * Fix a bug with returning_disabled when using the postgresql adapterGeorge Deglin2015-09-201-0/+15
|/ | | | The returning_disabled configuration option is required to make postgresql partitioning triggers work. This commit fixes a bug where an invalid query would be made in cases where returning_disabled was true and objects were created with no attributes defined.
* make it possible to run AR tests with bin/testYves Senn2015-06-111-1/+1
|
* PostgreSQL, Fix OID based type casts in C for primitive types.Lars Kanis2015-03-251-8/+8
| | | | | | | | | | The type map was introduced in aafee23, but wasn't properly filled. This mainly adjusts many locations, that expected strings instead of integers or boolean. add_pg_decoders is moved after setup of the StatementPool, because execute_and_clear could potentially make use of it.
* Prefer `drop_table if_exists: true` over raw SQLRyuta Kamizono2015-02-181-2/+2
| | | | | Lowercase raw SQL has been replaced by 07b659c already. This commit replaces everything else of raw SQL.
* Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 ↵Vipul A M2015-02-031-1/+0
| | | | onwards.
* Remove Relation#bind_paramsSean Griffin2015-01-271-6/+10
| | | | | | | | `bound_attributes` is now used universally across the board, removing the need for the conversion layer. These changes are mostly mechanical, with the exception of the log subscriber. Additional, we had to implement `hash` on the attribute objects, so they could be used as a key for query caching.
* Ensures that primary_key method will return nil when multi-pkArthur Neves2014-12-301-0/+6
| | | | | | | When table has a composite primary key, the `primary_key` method for sqlite3 and postgresql was only returning the first field of the key. Ensures that it will return nil instead, as AR dont support composite pks.
* Remove the unused second argument to `substitute_at`Sean Griffin2014-11-171-1/+1
| | | | Oh hey, we got to remove some code because of that!
* rm `reorder_bind_params`Sean Griffin2014-11-171-4/+1
| | | | | | Arel handles this for us automatically. Updated tests, as BindParam is no longer a subclass of SqlLiteral. We should remove the second argument to substitute_at entirely, as it's no longer used
* pg, `default_sequence_name` needs to return a string.Yves Senn2014-08-251-6/+6
| | | | | | | | | This is a reacon to https://github.com/rails/rails/commit/d6c1205584b1ba597db4071b168681678b1e9875#commitcomment-7502487 This backwards incompatibility was introduced with d6c12055 to fix #7516. However both `connection.default_sequence_name` and `model.sequence_name` are public API. The PostgreSQL adapter should honor the interface and return strings. /cc @matthewd @chancancode
* Don't trim excess whitespace in pg #columns_for_distinctAgis-2014-08-241-0/+8
| | | | Fixes #16623 introduced by https://github.com/rails/rails/commit/3d5a2019bcccc6fb01bee4811ca669f4383edb51
* pg, `default_sequence_name` respects schema. Closes #7516.Yves Senn2014-05-301-8/+6
|
* Merge pull request #11896 from nkondratyev/fix_pg_columns_for_distinctYves Senn2014-05-301-0/+11
|\ | | | | | | | | | | | | Fixed #columns_for_distinct of postgresql adapter Conflicts: activerecord/CHANGELOG.md
| * Fixed `columns_for_distinct` of postgresql adapterNikolay Kondratyev2013-08-151-0/+11
| |
* | pg, `reset_pk_sequence!` respects schemas. Closes #14719.Yves Senn2014-05-301-3/+5
| |