Support for PostgreSQL citext data type. #12523

Merged
merged 1 commit into from Mar 11, 2014

Projects

None yet

9 participants

@lsylvester

citext makes it possible to use AR Hash finders for case-insensitive
matching as sql UPPER/LOWER functions are not needed.

This is an updated version of #9182 and #10231.

The schema.rb dumps now include citext columns and unknown OID warning that appeared in the test has been fixed by reconnecting to the database after the extension was enabled.

@pftg pftg commented on the diff Oct 14, 2013
activerecord/test/schema/postgresql_specific_schema.rb
@@ -111,6 +111,15 @@
_SQL
end
+ if 't' == select_value("select 'citext'=ANY(select typname from pg_type)")
+ execute <<_SQL
@pftg
pftg Oct 14, 2013

May you indent this code.

@lsylvester
lsylvester Oct 14, 2013

None of the other create table statements in this file are indented. I think that it would be best to indent them all in a separate pull request if having them indented is preferred.

@pftg
pftg Oct 14, 2013

That PR will be rejected, as cosmetic changes. Better way to use code style for current changes.

@rafaelfranca
rafaelfranca Oct 14, 2013

It is fine in the way it is. I already tried to change the style on this file and I don't think it is worth

@rafaelfranca
Ruby on Rails member

This pull request needs a rebase

@rafaelfranca
Ruby on Rails member

Could you add a test for the schema.rb dump. I didn't saw this being tested

@lsylvester

Rebased, and test for schema.rb dump has been added

@carlosantoniodasilva
Ruby on Rails member

@rafaelfranca do you have anything else to add here?

@robin850
Ruby on Rails member

@carlosantoniodasilva @rafaelfranca : What do you think about improving the documentation and adding a note about this feature in the "Ruby on Rails 4.1 Release Notes" guide (if this will be in 4.1) ?

@exviva

I'd also be interested in getting this merged. Anything I can do to help?

@jalada

👍 I'm sad this got missed from 4.1; I'm getting bored of the citext errors in my console when I use it manually.

@carlosantoniodasilva carlosantoniodasilva commented on an outdated diff Dec 18, 2013
...erecord/test/cases/adapters/postgresql/citext_test.rb
+ def test_column
+ assert_equal :citext, @column.type
+ end
+
+ def test_write
+ x = Citext.new(cival: 'Some CI Text')
+ assert x.save!
+ end
+
+ def test_select_case_insensitive
+ @connection.execute "insert into citexts (cival) values('Cased Text')"
+ x = Citext.where(cival: 'cased text').first
+ assert_equal('Cased Text', x.cival)
+ end
+end
+
@carlosantoniodasilva carlosantoniodasilva commented on an outdated diff Dec 18, 2013
activerecord/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Support for Postgres citext data type enabling case-insensitive where
+ values without needing to wrap in UPPER/LOWER sql functions
@carlosantoniodasilva
carlosantoniodasilva Dec 18, 2013

PostgreSQL. citext with wrapped backticks for highlight. And please end with ..

@carlosantoniodasilva
Ruby on Rails member

Can you rebase this from master? Thanks.

@rafaelfranca mind taking a look here? ❤️

@senny senny commented on an outdated diff Mar 8, 2014
...b/active_record/connection_adapters/postgresql/oid.rb
@@ -371,6 +371,7 @@ def self.registered_type?(name)
register_type 'circle', OID::Identity.new
register_type 'hstore', OID::Hstore.new
register_type 'json', OID::Json.new
+ register_type 'citext', OID::Identity.new
@senny
senny Mar 8, 2014

we should map it to OID::Text.new

@senny
Ruby on Rails member

@lsylvester can you push a rebased and squashed version of this PR? You can use brackets in the commit message to give credits to the authors:

git commit -m "register OID for PostgreSQL citex datatype [Author A & Author B]"
@lsylvester

@senny I have rebased

@senny
Ruby on Rails member

@lsylvester can we include citex_test.rb as the two referenced PR's do?

@lsylvester lsylvester register OID for PostgreSQL citex datatype [Troy Kruthoff & Lachlan S…
…ylvester]

citext makes it possible to use AR Hash finders for case-insensitive matching as sql UPPER/LOWER functions are not needed.
b3e0da3
@lsylvester

@senny I have added a citext_test.rb.

@senny senny removed the openacademy label Mar 11, 2014
@senny senny merged commit 0e0b41d into rails:master Mar 11, 2014

1 check passed

Details default The Travis CI build passed
@senny
Ruby on Rails member

@lsylvester thank you for your patience 💛

@tenderlove tenderlove added a commit that referenced this pull request Mar 13, 2014
@tenderlove tenderlove Merge branch 'master' into adequaterecord
* master: (108 commits)
  make tests pass on Ruby 2.2
  Use Sqlite3 adapter in examples
  use the body proxy to freeze headers
  just ask the response for the commit status, we do not need to ask the jar
  only write the jar if the response isn't committed
  Fix a grammatical error in the i18n guide [ci skip]
  use method_defined? to check whether or not a method is defined
  Enhance docs for update_attribute [ci-skip]
  Change usec to 0 on tests that compare seconds
  Unit test for mysql quote time usec
  Changelog entry for mysql56 microseconds
  Test microsecond on mysql 5.6
  MySQL 5.6 and later supports microsecond precision in datetime.
  [ci skip] Add documentation for original_fullpath.
  Remove mocking on save, when not necessary
  comment why we are modifying global state. [ci skip]
  `change_table` supports `citext`. Follow up to #12523.
  Removed unnecessary command "application"
  register OID for PostgreSQL citex datatype [Troy Kruthoff & Lachlan Sylvester]
  Fixes STI when 2+ levels deep.
  ...
66e0321
@prathamesh-sonpatki prathamesh-sonpatki added a commit to prathamesh-sonpatki/exercism.io that referenced this pull request Mar 22, 2015
@prathamesh-sonpatki prathamesh-sonpatki Bump to use ActiveRecord and ActiveSupport 4.2.1
 - The registering of citext is no longer required because Rails 4.2
   added support for it in rails/rails#12523.
 - Also Rails 4.2 has locked minitest version to 5.5.1 so removed
   locking it to lower version in test_helper.
3856c9f
@prathamesh-sonpatki prathamesh-sonpatki added a commit to prathamesh-sonpatki/exercism.io that referenced this pull request Mar 22, 2015
@prathamesh-sonpatki prathamesh-sonpatki Bump to use ActiveRecord and ActiveSupport 4.2.1
 - The registering of citext is no longer required because Rails 4.2
   added support for it in rails/rails#12523.
 - Also Rails 4.2 has locked minitest version to 5.5.1 so removed
   locking it to lower version in test_helper.
3e80a77
@trayo trayo added a commit to trayo/exercism.io that referenced this pull request May 11, 2015
@prathamesh-sonpatki prathamesh-sonpatki Bump to use ActiveRecord and ActiveSupport 4.2.1
 - The registering of citext is no longer required because Rails 4.2
   added support for it in rails/rails#12523.
 - Also Rails 4.2 has locked minitest version to 5.5.1 so removed
   locking it to lower version in test_helper.
f65fdb5
@treiff treiff added a commit to treiff/exercism.io that referenced this pull request Aug 6, 2015
@prathamesh-sonpatki prathamesh-sonpatki Bump to use ActiveRecord and ActiveSupport 4.2.1
 - The registering of citext is no longer required because Rails 4.2
   added support for it in rails/rails#12523.
 - Also Rails 4.2 has locked minitest version to 5.5.1 so removed
   locking it to lower version in test_helper.
758b834
@treiff treiff added a commit to treiff/exercism.io that referenced this pull request Aug 15, 2015
@prathamesh-sonpatki prathamesh-sonpatki Bump to use ActiveRecord and ActiveSupport 4.2.1
 - The registering of citext is no longer required because Rails 4.2
   added support for it in rails/rails#12523.
 - Also Rails 4.2 has locked minitest version to 5.5.1 so removed
   locking it to lower version in test_helper.
2760721
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment