I have an array column which is part of unique validation in rails.
So a table with column a,b,c,d,e .
Validation: validates_uniqueness_of :d, scope: [:a, :b]
Now since I have multiple rails servers , sometimes there would be duplicate rows in the table because there is no DB level constraint. More on it: http://robots.thoughtbot.com/the-perils-of-uniqueness-validations/
So, I am trying to add a unique index on the table like this: add_index :table, ["a", "b","d"], unique: true ,using: :gin
I am using gin . See http://www.postgresql.org/docs/current/static/gin-intro.html Can PostgreSQL index array columns?
However,
seems like I am still able to add duplicate rows after doing db:migrate . I am assuming this is because the unique index on array did not work .
Any pointers ?
Thanks!
- I am using Rails4
- Normalizing the table is not an option currently