aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql
Commit message (Collapse)AuthorAgeFilesLines
* Add support for PostgreSQL operator classes to add_indexGreg Navis2017-11-301-12/+20
| | | | | | | | | | | | 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}
* Implement `PostgreSQL::SchemaDumper#extensions`Yasuo Honda2017-10-251-0/+12
| | | | | | | and abstract `SchemaDumper#extensions` is now an empty method. Since #30337, every database adapter has its own `SchemaDumper`. `extensions` are only supported by PostgreSQL database and postgresql database adapter.
* Remove `supports_disable_referential_integrity?`Yasuo Honda2017-10-231-25/+17
| | | | | | | | | | | | | | | | `supports_disable_referential_integrity?` used to handle if PostgreSQL database supports `ALTER TABLE <table name> DISABLE/ENABLE TRIGGER` statements. Refer https://github.com/rails/rails/commit/9a947af0e79cfb8692eb7e5ae94c1b8c40756f49 These statements have been documented since 8.1. https://www.postgresql.org/docs/8.1/static/sql-altertable.html > DISABLE/ENABLE TRIGGER Now Rails supports PostgreSQL 9.1 or higher only. No need to handle `supports_disable_referential_integrity?` anymore. Also, this method does not exist in any other adapters including AbstractAdapter.
* Remove deprecated argument `name` from `#indexes`Rafael Mendonça França2017-10-231-9/+1
|
* Remove deprecated argument `default` from `index_name_exists?`Rafael Mendonça França2017-10-231-6/+1
|
* [Active Record] require => require_relativeAkira Matsuda2017-10-211-21/+21
| | | | This basically reverts 9d4f79d3d394edb74fa2192e5d9ad7b09ce50c6d
* Fix longer sequence name detection for serial columns (#28339)Ryuta Kamizono2017-10-152-1/+22
| | | | | | | | We already found the longer sequence name, but we could not consider whether it was the sequence name created by serial type due to missed a max identifier length limitation. I've addressed the sequence name consideration to respect the max identifier length. Fixes #28332.
* `Postgres::OID::Range` serializes to a `Range`, quote in `Quoting`Thomas Cannon2017-09-262-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PostgreSQL 9.1+ introduced range types, and Rails added support for using this datatype in ActiveRecord. However, the serialization of `PostgreSQL::OID::Range` was incomplete, because it did not properly quote the bounds that make up the range. A clear example of this is a `tsrange`. Normally, ActiveRecord quotes Date/Time objects to include the milliseconds. However, the way `PostgreSQL::OID::Range` serialized its bounds, the milliseconds were dropped. This meant that the value was incomplete and not equal to the submitted value. An example of normal timestamps vs. a `tsrange`. Note how the bounds for the range do not include their milliseconds (they were present in the ruby Range): UPDATE "iterations" SET "updated_at" = $1, "range" = $2 WHERE "iterations"."id" = $3 [["updated_at", "2017-09-23 17:07:01.304864"], ["range", "[2017-09-23 00:00:00 UTC,2017-09-23 23:59:59 UTC]"], ["id", 1234]] `PostgreSQL::OID::Range` serialized the range by interpolating a string for the range, which works for most cases, but does not work for timestamps: def serialize(value) if value.is_a?(::Range) from = type_cast_single_for_database(value.begin) to = type_cast_single_for_database(value.end) "[#{from},#{to}#{value.exclude_end? ? ')' : ']'}" else super end end (byebug) from = type_cast_single_for_database(value.begin) 2010-01-01 13:30:00 UTC (byebug) to = type_cast_single_for_database(value.end) 2011-02-02 19:30:00 UTC (byebug) "[#{from},#{to}#{value.exclude_end? ? ')' : ']'}" "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)" @sgrif (the original implementer for Postgres Range support) provided some feedback about where the quoting should occur: Yeah, quoting at all is definitely wrong here. I'm not sure what I was thinking in 02579b5, but what this is doing is definitely in the wrong place. It should probably just be returning a range of subtype.serialize(value.begin) and subtype.serialize(value.end), and letting the adapter handle the rest. `Postgres::OID::Range` now returns a `Range` object, and `ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting` can now encode and quote a `Range`: def encode_range(range) "[#{type_cast(range.first)},#{type_cast(range.last)}#{range.exclude_end? ? ')' : ']'}" end ... encode_range(range) #=> "['2010-01-01 13:30:00.670277','2011-02-02 19:30:00.745125')" This commit includes tests to make sure the milliseconds are preserved in `tsrange` and `tstzrange` columns
* Extract `integer_like_primary_key_type` to ease to handle it for adaptersRyuta Kamizono2017-09-251-6/+3
|
* Move integer-like primary key normalization to `new_column_definition`Ryuta Kamizono2017-09-231-7/+12
| | | | | | Currently the normalization only exists in `primary_key` shorthand. It should be moved to `new_column_definition` to also affect to `add_column` with primary key.
* Fix collided sequence name detectionRyuta Kamizono2017-09-181-1/+8
| | | | | | If collided named sequence already exists, newly created serial column will generate alternative sequence name. Fix sequence name detection to allow the alternative names.
* Fix `quote_default_expression` for UUID with array defaultRyuta Kamizono2017-09-081-1/+1
| | | | Fixes #30539.
* Refactor `SchemaDumper` to make it possible to adapter specific customizationRyuta Kamizono2017-08-222-1/+5
| | | | | | | Currently `SchemaDumper` is only customizable for column options. But 3rd party connection adapters (oracle-enhanced etc) need to customizable for table or index dumping also. To make it possible, I introduced adapter specific `SchemaDumper` classes for that.
* Remove deprecated `#migration_keys`Ryuta Kamizono2017-08-221-5/+0
|
* Place `update_table_definition` consistently in `SchemaStatements`Ryuta Kamizono2017-08-211-0/+4
|
* Don't expose `prepare_column_options`Ryuta Kamizono2017-08-211-7/+5
| | | | | This is only used for the internal `column_spec` and `column_spec_for_primary_key`.
* Restore `to_sql` to return only SQL (#29945)Ryuta Kamizono2017-08-181-2/+1
| | | | Because `to_sql` is public API. I introduced `to_sql_and_binds` internal API to return SQL and binds.
* Change http postgresql.org links to https [ci skip]yuuji.yaginuma2017-07-301-1/+1
| | | | | It seems that it accepts only HTTPS connections. Ref: https://github.com/postgres/postgres/commit/7f77cbd996855a06fb742ea11adbe55c42b48fe2
* Refactor Active Record to let Arel manage bind paramsSean Griffin2017-07-241-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A common source of bugs and code bloat within Active Record has been the need for us to maintain the list of bind values separately from the AST they're associated with. This makes any sort of AST manipulation incredibly difficult, as any time we want to potentially insert or remove an AST node, we need to traverse the entire tree to find where the associated bind parameters are. With this change, the bind parameters now live on the AST directly. Active Record does not need to know or care about them until the final AST traversal for SQL construction. Rather than returning just the SQL, the Arel collector will now return both the SQL and the bind parameters. At this point the connection adapter will have all the values that it had before. A bit of this code is janky and something I'd like to refactor later. In particular, I don't like how we're handling associations in the predicate builder, the special casing of `StatementCache::Substitute` in `QueryAttribute`, or generally how we're handling bind value replacement in the statement cache when prepared statements are disabled. This also mostly reverts #26378, as it moved all the code into a location that I wanted to delete. /cc @metaskills @yahonda, this change will affect the adapters Fixes #29766. Fixes #29804. Fixes #26541. Close #28539. Close #24769. Close #26468. Close #26202. There are probably other issues/PRs that can be closed because of this commit, but that's all I could find on the first few pages.
* Merge pull request #29869 from kamipo/make_type_map_to_privateRafael França2017-07-211-2/+2
|\ | | | | Make `type_map` to private because it is only used in the connection adapter
| * Make `type_map` to private because it is only used in the connection adapterRyuta Kamizono2017-07-201-2/+2
| | | | | | | | | | | | | | `type_map` is an internal API and it is only used in the connection adapter. And also, some type map initializer methods requires passed `type_map`, but those instances already has `type_map` in itself. So we don't need explicit passing `type_map` to the initializers.
* | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-1932-0/+64
|/
* [Action Record] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-111-0/+1
|
* Merge pull request #29655 from kirs/frozen-friendly-ap-arMatthew Draper2017-07-101-1/+2
|\ | | | | Prepare AP and AR to be frozen string friendly
| * Prepare AP and AR to be frozen string friendlyKir Shatrov2017-07-061-1/+2
| |
* | Don't allow uuids with orphan curly bracespdebelak2017-07-071-1/+1
| | | | | | | | | | | | | | | | The uuid validation regex was allowing uuids to have a single leading curly brace or single trailing curly brace. Saving with such a uuid would cause Postgres to generate an exception even though the record seemed valid. With this change, the regex requires both a leading *and* a trailing curly brace or neither to be valid.
* | Remove database specific JSON typesRyuta Kamizono2017-07-052-11/+0
|/ | | | We already have database agnostic `Type::Json` since #29220.
* Merge branch 'master' into require_relative_2017Xavier Noria2017-07-022-25/+23
|\
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-0234-34/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-0234-0/+34
| |\ | | | | | | | | | Enforce frozen string in Rubocop
| | * Enforce frozen string in RubocopKir Shatrov2017-07-0134-0/+34
| | |
| * | Merge pull request #29506 from pat/frozen-string-literalsMatthew Draper2017-07-021-3/+3
| |\ \ | | | | | | | | | | | | Make ActiveSupport frozen-string-literal friendly.
| | * | Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-201-3/+3
| | | |
| * | | Don't cache queries for schema statementsRyuta Kamizono2017-06-302-22/+20
| | |/ | |/| | | | | | | | | | | | | `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.
* / | [Active Record] require => require_relativeAkira Matsuda2017-07-011-22/+22
|/ /
* | Use `quote` method rather than single quotes to identifiers in SQLRyuta Kamizono2017-06-292-6/+10
| | | | | | | | | | | | Because identifiers in SQL could include a single quote. Related #24950, #26784.
* | Ensure query caching for `select_*` methods in connection adaptersRyuta Kamizono2017-06-151-32/+0
|/
* Merge pull request #29220 from kamipo/consolidate_database_specific_json_typesMatthew Draper2017-06-012-2/+2
|\ | | | | Consolidate database specific JSON types to `Type::Json`
| * Consolidate database specific JSON types to `Type::Json`Ryuta Kamizono2017-05-302-2/+2
| |
* | 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`.
* Merge pull request #29273 from ↵Rafael França2017-05-291-10/+0
|\ | | | | | | | | kamipo/deserialize_raw_value_from_database_for_json Deserialize a raw value from the database in `changed_in_place?` for `AbstractJson`
| * Deserialize a raw value from the database in `changed_in_place?` for ↵Ryuta Kamizono2017-05-301-10/+0
| | | | | | | | | | | | | | | | `AbstractJson` Structured type values sometimes caused representation problems (keys sort order, spaces, etc). A raw value from the database should be deserialized (normalized) to prevent the problems.
* | Fix UUID column with `null: true` and `default: nil`Ryuta Kamizono2017-05-301-1/+1
|/ | | | | | | `quote_default_expression` can be passed nil value when `null: true` and `default: nil`. This addressed in that case. Fixes #29222.
* `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
|
* Revert "Merge pull request #27636 from ↵Rafael Mendonça França2017-04-261-43/+4
| | | | | | | | | mtsmfm/disable-referential-integrity-without-superuser-privilege-take-2" This reverts commit c1faca6333abe4b938b98fedc8d1f47b88209ecf, reversing changes made to 8c658a0ecc7f2b5fc015d424baf9edf6f3eb2b0b. See https://github.com/rails/rails/pull/27636#issuecomment-297534129
* 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.