Case-insensitive unique index in Rails/ActiveRecord?

前端 未结 8 1618
天命终不由人
天命终不由人 2020-12-09 03:38

I need to create a case-insensitive index on a column in rails. I did this via SQL:

execute(
   \"CREATE UNIQUE INDEX index_users_on_lower_email_index 
    O         


        
8条回答
  •  Happy的楠姐
    2020-12-09 03:46

    Have you considered using schema_plus (https://github.com/lomba/schema_plus)? Among other things (support for enforcing foreign keys in the database and for views), it supports setting case-insensitive indexes for PostgreSQL databases and handles dumping them in the schema. From the Readme, "If you’re using Postgresql, SchemaPlus provides support for conditions, expressions, index methods, and case-insensitive indexes."

提交回复
热议问题