If I have an unique index, schema validations will create validates_uniqueness_of validators for my model. However, if my index definition contains a function like COALESCE it does not work properly.
For example:
CREATE UNIQUE INDEX "abc" ON "xyz" ("column1", "column2", COALESCE(column3, 0);
Schema validations will generate validates_uniqueness_of for column1 in scope of column2 and another for column2 in scope of column1. It completely ignores column3. The work around was to add the following in my model:
If I have an unique index, schema validations will create validates_uniqueness_of validators for my model. However, if my index definition contains a function like COALESCE it does not work properly.
For example: CREATE UNIQUE INDEX "abc" ON "xyz" ("column1", "column2", COALESCE(column3, 0);
Schema validations will generate validates_uniqueness_of for column1 in scope of column2 and another for column2 in scope of column1. It completely ignores column3. The work around was to add the following in my model:
schema_validations except_type: :validates_uniqueness_of
IMHO, if a unique index contains a function, schema validations should not attempt to create an uniqueness validator (and note it in the log).