consistency_fail icon indicating copy to clipboard operation
consistency_fail copied to clipboard

Does not recognize expression indexes in Postgres

Open adsteel opened this issue 8 years ago • 3 comments

If you are using structure.sql in your Rails + Postgres project, you have the ability to use expression indexes. For example:

CREATE UNIQUE INDEX index_users_on_lower_name ON users(LOWER(name));

This can be mirrored in your ActiveRecord model:

class User
  validates :name, uniqueness: { case_insensitive: false }
end

With the above combination, the db constraint is consistent with the model, but this gem does not recognize it. The large number of expression indexes I have on my current project makes this gem difficult to use, though I understand that this practice is probably not too common in the Rails community.

adsteel avatar Jun 03 '16 17:06 adsteel

Ah interesting, yeah this seems like a really useful feature - I'm surprised I haven't heard about it before!

This one and the other issue you opened look like they would be pretty hard to determine reliably and in full generality from a library's perspective. It makes me think maybe the right solution is to provide a way to tell consistency_fail to just ignore some specific "issues" that it detects. Maybe some input file of ignores, something like .gitignore...

But if anyone sees a nice way to actually implement the ideal solution (we correctly detect indexes like the above), then I'm all for that too, of course.

trptcolin avatar Jun 09 '16 16:06 trptcolin

@adsteel did u ever come up with a workaround for this? just ran into this issue myself.

kelvintyb avatar Jun 30 '19 15:06 kelvintyb

@kelvintyb I did not.

adsteel avatar Jul 02 '19 12:07 adsteel