caribou / caribou-core

Core functionality for Caribou
44 stars 3 forks source link

Unique constraint on fields uses easily conflicting name #30

Closed fpoms closed 10 years ago

fpoms commented 10 years ago

When a model uses the :disjoint true modifier in a field definition, a constraint is created on that field in caribou.db using the following sql statement:

alter table {model_name} add constraint {field_name}_unique unique ({field_name})

(Replaced % arguments with {name} to indicate replacement) https://github.com/caribou/caribou-core/blob/master/src/caribou/db.clj#L190

In PostgresSQL, constraint names must be globally unique. Imagine two models both have a field named 'email' which has a unique constraint on it. This would cause both constraints to be called 'email_unique'.

The constraint names should be made that fields with the same name on different models should not cause a conflict.