consistency_fail
consistency_fail copied to clipboard
Does not recognize expression indexes in Postgres
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.
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.
@adsteel did u ever come up with a workaround for this? just ran into this issue myself.
@kelvintyb I did not.