Add unique index to entity attributes to avoid ruby-level race conditions.

WIP