db: add uniqueness constraints

Enforce uniqueness constraints at the database level, on:
- Invites,
- Procedures,
- Individuals.

These are the one less likely to have duplicates. A follow-up
PR will contains similar migrations, but more likely to have
existing duplicates that need to be removed.
This commit is contained in:
Pierre de La Morinerie 2021-04-27 11:55:39 +00:00
parent 0cb2162a65
commit d024b9ab9e
4 changed files with 46 additions and 2 deletions

View file

@ -0,0 +1,14 @@
class AddUniqueIndexToIndividuals < ActiveRecord::Migration[6.1]
include Database::MigrationHelpers
disable_ddl_transaction!
def up
delete_duplicates :individuals, [:dossier_id]
add_concurrent_index :individuals, [:dossier_id], unique: true
end
def down
remove_index :individuals, [:dossier_id]
end
end