PostgreSQL + Rails citext

I am trying to go to heroku which uses PostgreSQL 8.4 which has a citext column type which is good since the application was written for MySQL.

Can I use: citext with rails (so if migrations are done to MySQL, citext will just use the string / text?

I found this ticket, but it looks like it won't be part of the rails for a while: https://rails.lighthouseapp.com/projects/8994/tickets/3174-add-support-for-postgresql-citext-column-type

+2


source to share


3 answers


Rails 4.2+

Rails 4.2 has built-in support for column type citext

.

Rails <4.2



If you are using Rails <4.2 you can try using the activerecord-postgresql-citext gem.

This allows you to write migrations like this:

def up
  enable_extension("citext")                   

  create_table :models, :force => true do |t|  
    t.citext :name                             
    t.timestamps                               
  end                                          
end

      

+3


source


For recording only. It seems like rails 4.2 has built-in support for this.

Added support for the citext column type in the PostgreSQL adapter.



http://guides.rubyonrails.org/4_2_release_notes.html

+1


source


I'm pretty sure Rails only has a limited vocabulary of data types. You will probably have to use good old fashioned SQL to work with any other types.

0


source







All Articles