aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/uuid_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Reduce unused allocations when casting UUIDs for PostgresCarl Thuringer2019-02-201-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Using the subscript method `#[]` on a string has several overloads and rather complex implementation. One of the overloads is the capability to accept a regular expression and then run a match, then return the receiver (if it matched) or one of the groups from the MatchData. The function of the `UUID#cast` method is to cast a UUID to a type and format acceptable by postgres. Naturally UUIDs are supposed to be string and of a certain format, but it had been determined that it was not ideal for the framework to send just any old string to Postgres and allow the engine to complain when "foobar" or "" was sent, being obviously of the wrong format for a valid UUID. Therefore this code was written to facilitate the checking, and if it were not of the correct format, a `nil` would be returned as is conventional in Rails. Now, the subscript method will allocate one or more strings on a match and return one of them, based on the index parameter. However, there is no need for a new string, as a UUID of the correct format is already such, and so long as the format was verified then the string supplied is adequate for consumption by the database. The subscript method also creates a MatchData object which will never be used, and so must eventually be garbage collected. Garbage collection indeed. This innocuous method tends to be called quite a lot, for example if the primary key of a table is a uuid, then this method will be called. If the foreign key of a relation is a UUID, once again this method is called. If that foreign key is belonging to a has_many relationship with dozens of objects, then again dozens of UUIDs shall be cast to a dup of themselves, and spawn dozens of MatchData objects, and so on. So, for users that: * Use UUIDs as primary keys * Use Postgres * Operate on collections of objects This accomplishes a significant savings in total allocations, and may save many garbage collections.
* Don't allow `where` with invalid value matches to nil valuesRyuta Kamizono2019-02-181-0/+6
| | | | | | | | | That is considered as silently leaking information. If type casting doesn't return any actual value, it should not be matched to any record. Fixes #33624. Closes #33946.
* Use squiggly heredoc to strip odd indentation in the executed SQLRyuta Kamizono2018-11-221-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)) ```
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-4/+4
|
* `supports_extensions?` return always true since PostgreSQL 9.1Yasuo Honda2017-10-241-98/+92
| | | | | | | | since the minimum version of PostgreSQL currently Rails supports is 9.1, there is no need to handle if `supports_extensions?` Refer https://www.postgresql.org/docs/9.1/static/sql-createextension.html "CREATE EXTENSION"
* Add an extra assertion to ensure dumping schema default as expectedRyuta Kamizono2017-09-081-1/+4
|
* Fix `quote_default_expression` for UUID with array defaultRyuta Kamizono2017-09-081-0/+10
| | | | Fixes #30539.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Don't allow uuids with orphan curly bracespdebelak2017-07-071-1/+3
| | | | | | | | 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.
* 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
|
* Allow `uuid_test.rb` to be loaded on all adaptersEugene Kenny2017-06-141-1/+2
| | | | | | | | | Running `bin/test` from the activerecord directory produces this error: test/cases/adapters/postgresql/uuid_test.rb:43:in `<class:PostgresqlUUIDTest>': undefined method `supports_pgcrypto_uuid?' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x007fc405e72a68> (NoMethodError) The test only actually runs on the PostgreSQL adapter; we can avoid triggering the error on other adapters with this `respond_to?` guard.
* Remove assert_nothing_raised, as test is already testing the required concernsPrathamesh Sonpatki2017-06-031-3/+3
|
* Fix UUID column with `null: true` and `default: nil`Ryuta Kamizono2017-05-301-0/+10
| | | | | | | `quote_default_expression` can be passed nil value when `null: true` and `default: nil`. This addressed in that case. Fixes #29222.
* Use a query that's compatible with PostgreSQL 9.2Matthew Draper2017-04-121-3/+7
| | | | | | 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.
* Add `Style/EmptyLinesAroundMethodBody` in `.rubocop.yml` and remove extra ↵Ryuta Kamizono2017-02-121-1/+0
| | | | empty lines
* Fix UUID primary key with default nil in legacy migrationRyuta Kamizono2017-01-091-0/+19
| | | | | | UUID primary key with no default value feature (#10404, #18206) was lost in legacy migration caused by #25395 got merged. Restore the feature again in legacy migration.
* Should test uuid legacy migration without `supports_pgcrypto_uuid?`Ryuta Kamizono2017-01-091-19/+17
|
* "Use assert_nil if expecting nil from ...:in `...'. This will fail in MT6."Akira Matsuda2016-12-251-2/+2
|
* "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-251-1/+1
|
* Should test `test_change_column_default` in `PostgresqlUUIDTest`Ryuta Kamizono2016-11-251-13/+13
| | | | Follow up to #25395.
* Merge pull request #27171 from kamipo/suppress_migration_messageMatthew Draper2016-11-251-0/+4
|\ | | | | Suppress migration message in the test
| * Suppress migration message in the testRyuta Kamizono2016-11-251-0/+4
| |
* | Remove blank else blockRyuta Kamizono2016-11-251-1/+0
|/
* For `PostgreSQL >= 9.4` use `gen_random_uuid()`Yaw Boakye2016-11-221-14/+59
| | | | | | | | | | Since 9.4, PostgreSQL recommends using `pgcrypto`'s `gen_random_uuid()` to generate version 4 UUIDs instead of the functions in the `uuid-ossp` extension. These changes uses the appropriate UUID function depending on the underlying PostgreSQL server's version, while maintaining `uuid_generate_v4()` in older migrations.
* Fix CI failure caused by df84e9867219e9311aef6f4efd5dd9ec675bee5cRyuta Kamizono2016-08-231-2/+2
|
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-2/+2
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-40/+40
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Add expression support on the schema defaultRyuta Kamizono2016-01-131-4/+4
| | | | | | | | Example: create_table :posts do |t| t.datetime :published_at, default: -> { 'NOW()' } end
* Remove unnecessary enable,disable_extension on testsFumiaki MATSUSHIMA2016-01-021-9/+0
| | | | | | | uuid-ossp extension is alreadly enabled on test schema. And `disable_extension!('uuid-ossp', connection)` can be a cause of test failure. `ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: function uuid_generate_v1() does not exist` will happen depending on the execution order.
* Ensure uuid-ossp extension is present before we rely on itMatthew Draper2015-12-151-0/+2
|
* make it possible to run AR tests with bin/testYves Senn2015-06-111-4/+4
|
* Remove duplicated testRyuta Kamizono2015-03-041-20/+0
| | | | | `PostgresqlLargeKeysTest` is duplicated `PrimaryKeyBigSerialTest` in `primary_keys_test.rb`.
* prefer `drop_table if_exists: true` over raw SQL.Yves Senn2015-02-181-1/+1
| | | | | | | /cc @yahonda This makes it easier for third party adapters to run our tests, even if that database does not support IF EXISTS.
* rm `Type#number?`Sean Griffin2015-02-071-1/+0
| | | | | This predicate is only used in `query_attribute`, and is relatively easy to remove without adding a bunch of is a checks.
* Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 ↵Vipul A M2015-02-031-1/+0
| | | | onwards.
* Remove most type related predicates from `Column`Sean Griffin2015-01-301-2/+4
| | | | | | Remaining are `limit`, `precision`, `scale`, and `type` (the symbol version). These will remain on the column, since they mirror the options to the `column` method in the schema definition DSL
* Should escape regexp wildcard character `.`Ryuta Kamizono2015-01-191-1/+1
| | | | | `.` is regexp meta character. It should be escape for `assert_match` correctly.
* Prefer `array?` rather than `array`Ryuta Kamizono2015-01-041-1/+1
| | | | | | Slightly refactoring `PostgreSQLColumn`. `array` should be readonly. `default_function` should be initialized by `super`. `sql_type` has been removed `[]`. Since we already choose to remove it we should not change.
* Correctly ignore `case_sensitive` for UUID uniqueness validationSean Griffin2014-12-261-0/+17
| | | | | | | | I think we should deprecate this behavior and just error if you tell us to do a case insensitive comparison for types which are not case sensitive. Partially reverts 35592307 Fixes #18195
* Dump the default `nil` for PostgreSQL UUID primary key.Ryuta Kamizono2014-12-261-0/+6
|
* `force: :cascade` to recreate tables referenced by foreign-keys.Yves Senn2014-12-191-1/+1
|
* Relax the UUID regexGodfrey Chan2014-12-181-3/+7
| | | | | | | | Apparently PG does not validate against RFC 4122. The intent of the original patch is just to protect against PG errors (which potentially breaks txns, etc) because of bad user input, so we shouldn't try any harder than PG itself. Closes #17931
* tests, move schema shorthand assertions into pg specific tests.Yves Senn2014-12-021-0/+6
|
* tests, remove unneeded requires.Yves Senn2014-11-061-3/+0
|
* tests, use SchemaDumpingHelper to dump a specific table.Yves Senn2014-11-061-12/+12
| | | | | This makes debugging the generated schema output much easier. As a side effect it also shaves off 2.5 seconds of test runtime.
* add bigserial pk supportAaron Patterson2014-10-291-0/+20
|
* Added enable_extension! to helperAbdelkader Boudih2014-09-051-5/+6
|
* adding the exception RecordNotFound to UUID findJoseLuis Torres2014-08-211-0/+14
|