aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* | | Don't cache queries for schema statementsRyuta Kamizono2017-06-301-21/+19
| |/ |/| | | | | | | | | `test_middleware_caches` is sometimes failed since #29454. The failure is due to schema statements are affected by query caching. Bypassing query caching for schema statements to avoid the issue.
* | Use `quote` method rather than single quotes to identifiers in SQLRyuta Kamizono2017-06-291-6/+6
|/ | | | | | Because identifiers in SQL could include a single quote. Related #24950, #26784.
* Support PostgreSQL 10 `pg_sequence`Yasuo Honda2017-05-301-1/+9
| | | | | | | | | | | | | | Another fix for #28780 based on discussions at #28789 - In PostgreSQL 10 each sequence does not know its `min_value`. A new system catalog `pg_sequence` shows it as `seqmin`. Refer https://github.com/postgres/postgres/commit/1753b1b027035029c2a2a1649065762fafbf63f3 - `setval` 3rd argument needs to set to `false` only when the table has no rows to avoid `nextval(<sequence_name>)` returns `2` where `1` is expected. - `min_value` is only necessary when the table has no rows. It used to be necessary since the 3rd argument of `setval` is always `false`.
* `rename_table` renames primary key index nameYaw Boakye2017-05-291-4/+5
| | | | | | | | | | Formerly, `rename_table` only renamed primary key index name if the column's data type was sequential (serial, etc in PostgreSQL). The problem with that is tables whose primary keys had other data types (e.g. UUID) maintained the old primary key name. So for example, if the `cats` table has a UUID primary key, and the table is renamed to `felines`, the primary key index will still be called `cats_pkey` instead of `felines_pkey`. This PR corrects it.
* Prevent extra `current_database` query for `encoding`/`collation`/`ctype`Ryuta Kamizono2017-05-281-3/+3
|
* Refactor `indexes` things in connection adaptersRyuta Kamizono2017-04-161-2/+11
| | | | | | | * Use keyword arguments in `IndexDefinition` to ease to ignore unused options and to avoid to initialize incorrect empty value. * Place it in `SchemaStatements` for consistency. * And tiny tweaks.
* Use a query that's compatible with PostgreSQL 9.2Matthew Draper2017-04-121-7/+11
| | | | | | Also, explicitly apply the order: generate_subscripts is unlikely to start returning values out of order, but we should still be clear about what we want.
* Merge pull request #28478 from kamipo/fix_primary_keys_across_multiple_schemasAndrew White2017-03-291-9/+7
|\ | | | | Fix `primary_keys` across multiple schemas
| * Fix `primary_keys` across multiple schemasRyuta Kamizono2017-03-201-9/+7
| | | | | | | | Fixes #28470.
* | Make internal methods to privateRyuta Kamizono2017-03-271-39/+46
|/
* Merge pull request #28068 from kamipo/refactor_data_sourcesRafael França2017-03-131-91/+55
|\ | | | | Extract `data_source_sql` to refactor data source statements
| * Prefer `USING (column_list)` for joining information_schemaRyuta Kamizono2017-02-251-3/+1
| |
| * Extract `data_source_sql` to refactor data source statementsRyuta Kamizono2017-02-201-88/+54
| |
* | Use `max_identifier_length` for `index_name_length` in PostgreSQL adapterRyuta Kamizono2017-02-271-4/+0
| | | | | | | | | | Actually `index_name_length` depend on `max_identifier_length`, not always 63.
* | Fix `change_column` to drop default with `null: false`Ryuta Kamizono2017-02-261-1/+1
|/ | | | | | | | | | | | | | | | Currently `change_column` cannot drop default if `null: false` is specified at the same time. This change fixes the issue. ```ruby # cannot drop default change_column "tests", "contributor", :boolean, default: nil, null: false # we need the following workaround currently change_column "tests", "contributor", :boolean, null: false change_column "tests", "contributor", :boolean, default: nil ``` Closes #26582
* Should keep the primary key column orderRyuta Kamizono2017-02-141-0/+1
| | | | | | Fixes CI failure caused by #27961. https://travis-ci.org/rails/rails/jobs/201472146#L2390-L2409
* Simplify and optimize Postgres query for primary_keys()Jordan Lewis2017-02-131-10/+10
| | | | | | | | | | | | 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.
* Deprecate passing `default` to `index_name_exists?`Ryuta Kamizono2017-02-131-0/+5
|
* The `default` arg of `index_name_exists?` makes to optionalRyuta Kamizono2017-02-131-1/+1
| | | | | | 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.
* Revert "Simplify and speed up Postgres query for primary_keys"Ryuta Kamizono2017-02-101-8/+10
| | | | This reverts commit d6529af2954a67bd57fda45286fa9cfd0ff6b5ac.
* Simplify and speed up Postgres query for primary_keysJordan Lewis2017-02-091-10/+8
| | | | | | | | | | | | | | | | | | 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 joining pg_index against pg_attribute instead of going through pg_constraint. This avoids an expensive unnest, window function query, and common table expression. EXPLAINing these queries in Postgres against a database with a single table with a composite primary key shows a 66% reduction in the plan and execute latencies. This is significant during application startup time, especially against very large schemas, where these queries would be even slower and more numerous. Closes #27949
* Refactor `ColumnDefinition` to contain `options` hashRyuta Kamizono2017-02-091-20/+4
| | | | | | 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.
* Deprecate passing `name` to `indexes` like `tables`Ryuta Kamizono2017-01-041-1/+7
| | | | | Passing `name` to `tables` is already deprecated at #21601. Passing `name` to `indexes` is also unused.
* `#tables` and `#table_exists?` and returns only tables and not viewsRafael Mendonça França2016-12-291-20/+22
|
* Remove deprecated `name` argument from `#tables`Rafael Mendonça França2016-12-291-7/+1
|
* Refactor column initialization into `new_column_from_field`Kir Shatrov2016-11-111-15/+17
| | | | that accepts results of SHOW FIELDS
* Quote table name properlyRyuta Kamizono2016-10-141-8/+8
| | | | If does not quote table name properly, invalid SQL is generated.
* Fix table comment dumpingRyuta Kamizono2016-10-111-1/+3
| | | | | | | | | | | | | Follow up to #26735. If `table_options` returns `{ comment: nil }`, `create_table` line is broken. Example: ```ruby create_table "accounts", force: :cascade, do |t| ```
* Fix Remaining Case-In-Assignment Statement FormattingAlex Kitchens2016-09-061-25/+26
| | | | | | | | | Recently, the Rails team made an effort to keep the source code consistent, using Ruboco (bb1ecdcc677bf6e68e0252505509c089619b5b90 and below). Some of the case statements were missed. This changes the case statements' formatting and is consistent with changes in 810dff7c9fa9b2a38eb1560ce0378d760529ee6b and db63406cb007ab3756d2a96d2e0b5d4e777f8231.
* fixes remaining RuboCop issues [Vipul A M, Xavier Noria]Xavier Noria2016-09-011-2/+2
|
* 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-34/+34
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-9/+9
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-48/+48
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Merge pull request #25340 from kamipo/prevent_table_comment_queryRafael França2016-07-281-0/+4
|\ | | | | Prevent `table_comment` query if a table doesn't have a comment
| * Prevent `table_comment` query if a table doesn't have a commentRyuta Kamizono2016-06-101-0/+4
| |
* | Refactored method ↵bogdanvlviv2016-07-171-3/+3
| | | | | | | | `ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements#default_sequence_name`
* | Merge pull request #25307 from ↵Eileen M. Uchitelle2016-07-011-1/+1
|\ \ | | | | | | | | | | | | kamipo/extract_foreign_key_action_from_information_schema Extract foreign key action from `information_schema`
| * | Make `foreign_keys` queries to `SCHEMA`Ryuta Kamizono2016-06-071-1/+1
| |/
* / Fix error message to talk about the scale not precision of the typeRafael Mendonça França2016-06-131-1/+1
|/ | | | Fixes #25391
* Treat blank comments as no comment for indexesRyuta Kamizono2016-04-291-1/+1
| | | | | | Follow up of 1683410. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Add Expression Indexes and Operator Classes support for PostgreSQLRyuta Kamizono2016-04-241-15/+20
| | | | | | | | | | | | | | | | 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 `test_blank_columns_created_in_block`Ryuta Kamizono2016-04-201-1/+1
| | | | Follow up to 1683410.
* Database comments: switch to keyword args for new table optionsJeremy Daer2016-04-181-16/+16
| | | | | | * Switch to keyword args where we can without breaking compat. * Use add_table_options! for :options, too. * Some code polish.
* Add support for specifying comments for tables, columns, and indexes.Andrey Novikov2016-04-161-8/+43
| | | | | | | | | | | | | Comments are specified in migrations, stored in database itself (in its schema), and dumped into db/schema.rb file. This allows to generate good documentation and explain columns and tables' purpose to everyone from new developers to database administrators. For PostgreSQL and MySQL only. SQLite does not support comments at the moment. See docs for PostgreSQL: http://www.postgresql.org/docs/current/static/sql-comment.html See docs for MySQL: http://dev.mysql.com/doc/refman/5.7/en/create-table.html
* Pass over all Rails 5 warnings, to make sure:Vipul A M2016-04-121-2/+2
| | | | | | | | | | - we are ending sentences properly - fixing of space issues - fixed continuity issues in some sentences. Reverts https://github.com/rails/rails/commit/8fc97d198ef31c1d7a4b9b849b96fc08a667fb02 . This change reverts making sure we add '.' at end of deprecation sentences. This is to keep sentences within Rails itself consistent and with a '.' at the end.
* Passing `table_name` to `Column#initialize` to avoid `instance_variable_set`Ryuta Kamizono2016-03-081-5/+3
|
* Initialize `column.table_name` immediately for `column.serial?` correctly ↵Ryuta Kamizono2016-03-081-2/+5
| | | | | | | | working Currently the results of `column.serial?` is not correct. For `column.serial?` correctly working, initialize `column.table_name` immediately.
* Remove outdated comment [ci skip]Ryuta Kamizono2016-03-041-1/+0
| | | | Currently column options handled by the type map in Rails 4.2.
* Handle specified schemas when removing a Postgres indexGrey Baker2015-12-181-3/+16
|