aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/schema_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Fix `test_schema_names` to include "hint_plan" schemaRyuta Kamizono2019-06-151-1/+5
|
* Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-211-12/+8
| | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* Use squiggly heredoc to strip odd indentation in the executed SQLRyuta Kamizono2018-11-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: ``` LOG: execute <unnamed>: SELECT t.oid, t.typname FROM pg_type as t WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool') LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype FROM pg_type as t LEFT JOIN pg_range as r ON oid = rngtypid WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric') OR t.typtype IN ('r', 'e', 'd') OR t.typinput::varchar = 'array_in' OR t.typelem != 0 LOG: statement: SHOW TIME ZONE LOG: statement: SELECT 1 LOG: execute <unnamed>: SELECT COUNT(*) FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view AND c.relname = 'accounts' AND n.nspname = ANY (current_schemas(false)) ``` After: ``` LOG: execute <unnamed>: SELECT t.oid, t.typname FROM pg_type as t WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'bool') LOG: execute <unnamed>: SELECT t.oid, t.typname, t.typelem, t.typdelim, t.typinput, r.rngsubtype, t.typtype, t.typbasetype FROM pg_type as t LEFT JOIN pg_range as r ON oid = rngtypid WHERE t.typname IN ('int2', 'int4', 'int8', 'oid', 'float4', 'float8', 'text', 'varchar', 'char', 'name', 'bpchar', 'bool', 'bit', 'varbit', 'timestamptz', 'date', 'money', 'bytea', 'point', 'hstore', 'json', 'jsonb', 'cidr', 'inet', 'uuid', 'xml', 'tsvector', 'macaddr', 'citext', 'ltree', 'interval', 'path', 'line', 'polygon', 'circle', 'lseg', 'box', 'time', 'timestamp', 'numeric') OR t.typtype IN ('r', 'e', 'd') OR t.typinput::varchar = 'array_in' OR t.typelem != 0 LOG: statement: SHOW TIME ZONE LOG: statement: SELECT 1 LOG: execute <unnamed>: SELECT COUNT(*) FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','v','m') -- (r)elation/table, (v)iew, (m)aterialized view AND c.relname = 'accounts' AND n.nspname = ANY (current_schemas(false)) ```
* Fixing an issue when parsing an opclass by allowing indexed columnThomas Bianchini2018-11-211-0/+12
| | | | | | | | in indexdef to be wrapped up by double quotes Fixes #34493. *Thomas Bianchini*
* Fix `CustomCops/AssertNot` to allow it to have failure messageRyuta Kamizono2018-05-131-2/+2
| | | | Follow up of #32605.
* Dump correctly index nulls order for postgresqlfatkodima2018-01-281-0/+28
|
* Suppress `warning: BigDecimal.new is deprecated` in activerecordYasuo Honda2017-12-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `BigDecimal.new` has been deprecated in BigDecimal 1.3.3 which will be a default for Ruby 2.5. Refer https://github.com/ruby/bigdecimal/commit/533737338db915b00dc7168c3602e4b462b23503 ``` $ cd rails/activerecord/ $ git grep -l BigDecimal.new | grep \.rb | xargs sed -i -e "s/BigDecimal.new/BigDecimal/g" ``` - Changes made only to Active Record. Will apply the same change to other module once this commit is merged. - The following deprecation has not been addressed because it has been reported at `ActiveRecord::Result.new`. `ActiveRecord::Result.ancestors` did not show `BigDecimal`. * Not addressed ```ruby /path/to/rails/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb:34: warning: BigDecimal.new is deprecated ``` * database_statements.rb:34 ```ruby ActiveRecord::Result.new(result.fields, result.to_a) if result ``` * ActiveRecord::Result.ancestors ```ruby [ActiveRecord::Result, Enumerable, ActiveSupport::ToJsonWithActiveSupportEncoder, Object, Metaclass::ObjectMethods, Mocha::ObjectMethods, PP::ObjectMixin, ActiveSupport::Dependencies::Loadable, ActiveSupport::Tryable, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject] ``` This commit has been tested with these Ruby and BigDecimal versions - ruby 2.5 and bigdecimal 1.3.3 ``` $ ruby -v ruby 2.5.0dev (2017-12-14 trunk 61217) [x86_64-linux] $ gem list |grep bigdecimal bigdecimal (default: 1.3.3, default: 1.3.2) ``` - ruby 2.4 and bigdecimal 1.3.0 ``` $ ruby -v ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux-gnu] $ gem list |grep bigdecimal bigdecimal (default: 1.3.0) ``` - ruby 2.3 and bigdecimal 1.2.8 ``` $ ruby -v ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-linux] $ gem list |grep -i bigdecimal bigdecimal (1.2.8) ``` - ruby 2.2 and bigdecimal 1.2.6 ``` $ ruby -v ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-linux] $ gem list |grep bigdecimal bigdecimal (1.2.6) ```
* Refactor `length`, `order`, and `opclass` index options dumpingRyuta Kamizono2017-12-031-3/+3
|
* Add support for PostgreSQL operator classes to add_indexGreg Navis2017-11-301-0/+32
| | | | | | | | | | | | 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 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-3/+7
|/ | | | | | | | 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.
* 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
|
* Extract `bind_param` and `bind_attribute` into `ActiveRecord::TestCase`Ryuta Kamizono2017-05-041-7/+3
| | | | These are used in tests from anywhere.
* Fix `primary_keys` across multiple schemasRyuta Kamizono2017-03-201-1/+2
| | | | Fixes #28470.
* Simplify and optimize Postgres query for primary_keys()Jordan Lewis2017-02-131-8/+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.
* The `default` arg of `index_name_exists?` makes to optionalRyuta Kamizono2017-02-131-7/+7
| | | | | | The `default` arg of `index_name_exists?` is only used the adapter does not implemented `indexes`. But currently all adapters implemented `indexes` (See #26688). Therefore the `default` arg is never used.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-3/+3
|
* improve error message when include assertions failMichael Grosser2016-09-161-1/+1
| | | | | | assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
* Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+1
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-5/+5
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-44/+44
| | | | | 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-13/+17
| | | | | | | | | | | | | | | | 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>
* Fix tests failure with `prepared_statements: false`Ryuta Kamizono2016-02-291-10/+12
| | | | | | 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`.
* Typos in AR testsAkira Matsuda2016-02-031-1/+1
|
* Handle specified schemas when removing a Postgres indexGrey Baker2015-12-181-0/+14
|
* Merge pull request #22623 from greysteil/support-passing-schema-name-to-indexesMatthew Draper2015-12-181-0/+5
|\ | | | | | | Support passing the schema name prefix to `conenction.indexes`
| * Support passing the schema name prefix to `conenction.indexes`Grey Baker2015-12-171-0/+5
| | | | | | | | | | | | | | Support passing the schema name as a prefix to table name in `ConnectionAdapters::SchemaStatements#indexes`. Previously the prefix would be considered a full part of the index name, and only the schema in the current search path would be considered.
* | Support removing custom-names indexes when only specifying column namesGrey Baker2015-12-151-2/+0
|/
* Deprecate `#table_exists?`, `#tables` and passing arguments to `#talbes`yui-knk2015-11-091-13/+13
| | | | | | | | | | Reported on #21509, how views is treated by `#tables` are differ by each adapters. To fix this different behavior, after Rails 5.0 is released, deprecate `#tables`. And `#table_exists?` would check both tables and views. To make their behavior consistent with `#tables`, after Rails 5.0 is released, deprecate `#table_exists?`.
* Do not cache prepared statements that are unlikely to have cache hitsSean Griffin2015-10-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit, Rails makes no differentiation between whether a query uses bind parameters, and whether or not we cache that query as a prepared statement. This leads to the cache populating extremely fast in some cases, with the statements never being reused. In particular, the two problematic cases are `where(foo: [1, 2, 3])` and `where("foo = ?", 1)`. In both cases we'll end up quoting the values rather than using a bind param, causing a cache entry for every value ever used in that query. It was noted that we can probably eventually change `where("foo = ?", 1)` to use a bind param, which would resolve that case. Additionally, on PG we can change our generated query to be `WHERE foo = ANY($1)`, and pass an array for the bind param. I hope to accomplish both in the future. For SQLite and MySQL, we still end up preparing the statements anyway, we just don't cache it. The statement will be cleaned up after it is executed. On postgres, we skip the prepare step entirely, as an API is provided to execute with bind params without preparing the statement. I'm not 100% happy on the way this ended up being structured. I was hoping to use a decorator on the visitor, rather than mixing a module into the object, but the way Arel has it's visitor pattern set up makes it very difficult to extend without inheritance. I'd like to remove the duplication from the various places that are extending it, but that'll require a larger restructuring of that initialization logic. I'm going to take another look at the structure of it soon. This changes the signature of one of the adapter's internals, and will require downstream changes from third party adapters. I'm not too worried about this, as worst case they can simply add the parameter and always ignore it, and just keep their previous behavior. Fixes #21992.
* introduce `conn.data_source_exists?` and `conn.data_sources`.Yves Senn2015-09-221-0/+2
| | | | | | | | | | | | | | | | | These new methods are used from the Active Record model layer to determine which relations are viable to back a model. These new methods allow us to change `conn.tables` in the future to only return tables and no views. Same for `conn.table_exists?`. The goal is to provide the following introspection methods on the connection: * `tables` * `table_exists?` * `views` * `view_exists?` * `data_sources` (views + tables) * `data_source_exists?` (views + tables)
* Support dropping indexes concurrently in PostgresGrey Baker2015-09-051-2/+2
| | | | | See http://www.postgresql.org/docs/9.4/static/sql-dropindex.html for more details.
* pg, `create_schema`, `drop_schema` and `rename_table` quote schema name.Yves Senn2015-08-281-7/+47
| | | | | | | | Closes #21418. Previously schema names were not quoted. This leads to issues when a schema names contains a ".". Methods in `schema_statements.rb` should quote user input.
* PostgreSQL, add `:if_exists` to `#drop_schema`.Yves Senn2015-08-281-10/+21
|
* Display decimal defaults as strings to keep precisionJohn Gesimondo2015-06-231-0/+5
|
* make it possible to run AR tests with bin/testYves Senn2015-06-111-3/+3
|
* PostgreSQL, Fix OID based type casts in C for primitive types.Lars Kanis2015-03-251-3/+3
| | | | | | | | | | 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.
* Closes rails/rails#18864: Renaming transactional fixtures to transactional testsBrandon Weiss2015-03-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | I’m renaming all instances of `use_transcational_fixtures` to `use_transactional_tests` and “transactional fixtures” to “transactional tests”. I’m deprecating `use_transactional_fixtures=`. So anyone who is explicitly setting this will get a warning telling them to use `use_transactional_tests=` instead. I’m maintaining backwards compatibility—both forms will work. `use_transactional_tests` will check to see if `use_transactional_fixtures` is set and use that, otherwise it will use itself. But because `use_transactional_tests` is a class attribute (created with `class_attribute`) this requires a little bit of hoop jumping. The writer method that `class_attribute` generates defines a new reader method that return the value being set. Which means we can’t set the default of `true` using `use_transactional_tests=` as was done previously because that won’t take into account anyone using `use_transactional_fixtures`. Instead I defined the reader method manually and it checks `use_transactional_fixtures`. If it was set then it should be used, otherwise it should return the default, which is `true`. If someone uses `use_transactional_tests=` then it will overwrite the backwards-compatible method with whatever they set.
* 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.
* Remove Relation#bind_paramsSean Griffin2015-01-271-2/+6
| | | | | | | | `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.
* Should escape regexp wildcard character `.`Ryuta Kamizono2015-01-191-1/+1
| | | | | `.` is regexp meta character. It should be escape for `assert_match` correctly.
* pg tests, get rid of global schema `schema_1`.Yves Senn2014-12-021-1/+51
|
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* fix set_pk_sequence and add a test for it.Aaron Patterson2014-10-311-0/+8
|
* pg, correctly dump foreign keys targeting tables in a different schema.Yves Senn2014-09-171-0/+26
| | | | | | Closes #16907. [Matthew Draper & Yves Senn]
* pg, `reset_pk_sequence!` respects schemas. Closes #14719.Yves Senn2014-05-301-2/+11
|
* remove unused variable warningKuldeep Aggarwal2014-05-261-1/+1
| | | | `warning: assigned but unused variable - album`