I have a model, Clients
and a corresponding database with lastname
and firstname
columns. Originally there were no constraints on the uniqueness of [lastname, firstname]
, and the database currently contains duplicates. I would like to clean up the database and impose constraints on the model, such as: validates_uniqueness_of :lastname, scope: :firstname
.
Idea that comes to my mind is to back up the data in some fashion, impose constraints on an empty model database and then pull the data back in with duplicates that I can now process separately rescueing from exception.
I feel, however, that I am doing something off-the-wall here.
Is there a better, "rails way" to do this?