demarches-normaliennes/db/migrate/20210427120001_add_unique_index_to_procedures.rb
Pierre de La Morinerie d024b9ab9e 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.
2021-04-27 15:36:22 +02:00

14 lines
501 B
Ruby

class AddUniqueIndexToProcedures < ActiveRecord::Migration[6.1]
include Database::MigrationHelpers
disable_ddl_transaction!
def up
delete_duplicates :procedures, [:path, :closed_at, :hidden_at, :unpublished_at]
add_concurrent_index :procedures, [:path, :closed_at, :hidden_at, :unpublished_at], name: 'procedure_path_uniqueness', unique: true
end
def down
remove_index :procedures, [:path, :closed_at, :hidden_at, :unpublished_at], name: 'procedure_path_uniqueness'
end
end