djezzzl / database_consistency

The tool to avoid various issues due to inconsistencies and inefficiencies between a database schema and application models.
MIT License
1.02k stars 43 forks source link

UniqueIndexChecker and postgresql partial indexes #195

Open tconst opened 1 year ago

tconst commented 1 year ago

In postgresql you can create partial indexes that allow you specify a where condition. I was able to add a uniqueness validation that enforces these, using a combination of scope and conditions, e.g. validates_uniqueness_of :account_id, scope: :default, condition: -> { where(default: true}. This example enforces a single default per account. It would be awesome if the gem could identify these so that they aren't being flagged.

djezzzl commented 1 year ago

Hi @tconst,

Thank you for the suggestion! Indeed, it would be cool to have such. Would you like to investigate and contribute?