aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* 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
|
* Support passing the schema name prefix to `conenction.indexes`Grey Baker2015-12-171-9/+12
| | | | | | | 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.
* Deprecate `#table_exists?`, `#tables` and passing arguments to `#talbes`yui-knk2015-11-091-1/+16
| | | | | | | | | | 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?`.
* introduce `conn.data_source_exists?` and `conn.data_sources`.Yves Senn2015-09-221-0/+11
| | | | | | | | | | | | | | | | | 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)
* Merge pull request #21609 from kamipo/do_not_dump_view_as_tableJeremy Daer2015-09-191-0/+24
|\ | | | | | | Do not dump a view as a table in sqlite3, mysql and mysql2 adapters
| * Add `#views` and `#view_exists?` methods on connection adaptersRyuta Kamizono2015-09-131-0/+24
| |
* | Correctly dump composite primary keyRyuta Kamizono2015-09-201-11/+13
|/ | | | | | | | | Example: create_table :barcodes, primary_key: ["region", "code"] do |t| t.string :region t.integer :code end
* Fix test failures from premature merge of #21317Matthew Draper2015-09-071-4/+8
| | | | | | | | Apparently I managed to forget how similar the "tests passing" and "no status reported" merge indicators look. Note that the previous `stubs` in test_add_index wasn't working: the method was still called, and just happened to return false.
* Support dropping indexes concurrently in PostgresGrey Baker2015-09-051-2/+9
| | | | | 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-3/+3
| | | | | | | | 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.
* pg docs, `connection.tables` does not use the `name` argument.Yves Senn2015-08-281-1/+1
| | | | | | | | | | | | [ci skip] Currently the `#tables` method does not make use of the `name` argument and always returns all the tables in the schema search path. However the docs suggest different behavior. While we should porbably adjust the implementation to provide this behavior, let's make the docs right for now (also for `4-2-stable`) and then implement the behavior on `master`.
* PostgreSQL, add `:if_exists` to `#drop_schema`.Yves Senn2015-08-281-2/+2
|
* Add reversible syntax for change_column_defaultPrem Sichanugrist2015-06-261-1/+2
| | | | | | | | | | | | | Passing `:from` and `:to` to `change_column_default` makes this command reversible as user has defined its previous state. So, instead of having the migration command as: change_column_default(:posts, :state, "draft") They can write it as: change_column_default(:posts, :state, from: nil, to: "draft")
* Avoid the heredoc in one line queries and simple queriesRyuta Kamizono2015-05-191-20/+5
| | | | Related with #20028.
* :nodoc: postgresql add_columnTony Miller2015-05-131-3/+1
|
* :nodoc: rename_column in postgresql/schema_statements.rbTony Miller2015-05-081-1/+1
| | | | | Its already doc'ed in activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
* Use `select_value` for avoid `ActiveRecord::Result` instance creatingRyuta Kamizono2015-05-051-21/+16
| | | | | `exec_query` create `ActiveRecord::Result` instance. It is better to use `select_value` instead of `exec_query` for performance.
* PostgreSQL: `:collation` support for string and text columnsRyuta Kamizono2015-05-041-2/+12
| | | | | | | | | Example: create_table :foos do |t| t.string :string_en, collation: 'en_US.UTF-8' t.text :text_ja, collation: 'ja_JP.UTF-8' end
* Move the collation handling code from the MySQL adapter to common classesRyuta Kamizono2015-05-041-2/+2
| | | | | Some databases like MySQL allow defining collation charset for specific columns.
* `:nodoc:` postgresql's change_columnTony Miller2015-05-031-2/+1
| | | | | Its nodoc'ed for the other implementations, and doc'ed in the base class, just like the other change_column* methods.