aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* | 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.
* :nodoc: change_column_null in the implmenting adaptersTony Miller2015-05-031-1/+1
| | | | | | `change_column_null` is doc'ed only in ActiveRecord::ConnectionAdapters::SchemaStatements, so it would make sense to :nodoc: it elsewhere.
* Added documentation for PostGreSQL database_statements [ci skip]Prathamesh Sonpatki2015-04-301-0/+3
| | | | | | - Added documentation for index_name_exists? and rename_index. - Also changed rails to \Rails in documentation of allowed_index_name_length.
* No need to document drop_table in the PostgreSQLAdapterRafael Mendonça França2015-04-061-9/+1
| | | | | | It behaves in the same way that the abstract adapter. [ci skip]
* change the explanation of :if_exists option [ci skip]Mehmet Emin İNAÇ2015-04-061-1/+1
|
* drop_table method documentation for mysql and postgresql adapters [ci skip]Mehmet Emin İNAÇ2015-04-061-0/+8
|
* Make method as nodoc since we are already docummenting at AbstractAdapterRafael Mendonça França2015-03-311-1/+1
|
* 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.
* [ci skip] Fix a typo for PostgreSQL text limit, GB instead of Gb.Juanito Fatas2015-03-031-2/+2
|
* Allow `:precision` option for time type columnsRyuta Kamizono2015-02-201-6/+0
|
* Handle array option in `type_to_sql`Ryuta Kamizono2015-02-191-19/+16
| | | | | `[]` is a part of `sql_type`, so it is always necessary to respect to array option when `type_to_sql` is called.
* Should handle array option for `:cast_as`Ryuta Kamizono2015-02-191-4/+8
|
* Revert "Allow `:precision` option for time type columns"Sean Griffin2015-02-171-0/+7
| | | | | | | | | | This reverts commit 1502caefd30b137fd1a0865be34c5bbf85ba64c1. The test suite for the mysql adapter broke when this commit was used with MySQL 5.6. Conflicts: activerecord/CHANGELOG.md
* Allow `:precision` option for time type columnsRyuta Kamizono2015-02-121-7/+0
|
* Refactor `quote_default_expression`Ryuta Kamizono2015-02-111-10/+2
| | | | | | | `quote_default_expression` and `quote_default_value` are almost the same handling for do not quote default function of `:uuid` columns. Rename `quote_default_value` to `quote_default_expression`, and remove duplicate code.
* An array type is a part of `sql_type`Ryuta Kamizono2015-02-081-18/+3
| | | | | | `sql_type` is reused in `lookup_cast_type`. If making it a part of `sql_type` when handled array option first, it isn't necessary to do again.
* rm `Column#cast_type`Sean Griffin2015-02-031-5/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The type from the column is never used, except when being passed to the attributes API. While leaving the type on the column wasn't necessarily a bad thing, I worry that it's existence there implies that it is something which should be used. During the design and implementation process of the attributes API, there have been plenty of cases where getting the "right" type object was hard, but I had easy access to the column objects. For any contributor who isn't intimately familiar with the intents behind the type casting system, grabbing the type from the column might easily seem like the "correct" thing to do. As such, the goal of this change is to express that the column is not something that should be used for type casting. The only places that are "valid" (at the time of this commit) uses of acquiring a type object from the column are fixtures (as the YAML file is going to mirror the database more closely than the AR object), and looking up the type during schema detection to pass to the attributes API Many of the failing tests were removed, as they've been made obsolete over the last year. All of the PG column tests were testing nothing beyond polymorphism. The Mysql2 tests were duplicating the mysql tests, since they now share a column class. The implementation is a little hairy, and slightly verbose, but it felt preferable to going back to 20 constructor options for the columns. If you are git blaming to figure out wtf I was thinking with them, and have a better idea, go for it. Just don't use a type object for this.
* Remove most uses of `Column#cast_type`Sean Griffin2015-01-301-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The goal is to remove the type object from the column, and remove columns from the type casting process entirely. The primary motivation for this is clarity. The connection adapter does not have sufficient type information, since the type we want to work with might have been overriden at the class level. By taking this object from the column, it is easy to mistakenly think that the column object which exists on the connection adapter is sufficient. It isn't. A concrete example of this is `serialize`. In 4.2 and earlier, `where` worked in a very inconsistent and confusing manner. If you passed a single value to `where`, it would serialize it before querying, and do the right thing. However, passing it as part of an array, hash, or range would cause it to not work. This is because it would stop using prepared statements, so the type casting would come from arel. Arel would have no choice but to get the column from the connection adapter, which would treat it as any other string column, and query for the wrong value. There are a handful of cases where using the column object to find the cast type is appropriate. These are cases where there is not actually a class involved, such as the migration DSL, or fixtures. For all other cases, the API should be designed as such that the type is provided before we get to the connection adapter. (For an example of this, see the work done to decorate the arel table object with a type caster, or the introduction of `QueryAttribute` to `Relation`). There are times that it is appropriate to use information from the column to change behavior in the connection adapter. These cases are when the primitive used to represent that type before it goes to the database does not sufficiently express what needs to happen. An example of this that affects every adapter is binary vs varchar, where the primitive used for both is a string. In this case it is appropriate to look at the column object to determine which quoting method to use, as this is something schema dependent. An example of something which would not be appropriate is to look at the type and see that it is a datetime, and performing string parsing when given a string instead of a date. This is the type of logic that should live entirely on the type. The value which comes out of the type should be a sufficiently generic primitive that the adapter can be expected to know how to work with it. The one place that is still using the column for type information which should not be necessary is the connection adapter type caster which is sometimes given to the arel table when we can't find the associated table. This will hopefully go away in the near future.
* Add an `:if_exists` option to `drop_table`Stefan Kanev2015-01-191-1/+1
| | | | | | | | | | | If set to `if_exists: true`, it generates a statement like: DROP TABLE IF EXISTS posts This syntax is supported in the popular SQL servers, that is (at least) SQLite, PostgreSQL, MySQL, Oracle and MS SQL Sever. Closes #16366.