db: add uniqueness constraints to DeletedDossiers

This commit is contained in:
Pierre de La Morinerie 2021-07-22 15:56:16 +00:00
parent 3d25fc995a
commit dea3395c91
2 changed files with 16 additions and 1 deletions

View file

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

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_07_22_133440) do
ActiveRecord::Schema.define(version: 2021_07_22_133531) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -229,6 +229,7 @@ ActiveRecord::Schema.define(version: 2021_07_22_133440) do
t.bigint "user_id"
t.bigint "groupe_instructeur_id"
t.bigint "revision_id"
t.index ["dossier_id"], name: "index_deleted_dossiers_on_dossier_id", unique: true
t.index ["procedure_id"], name: "index_deleted_dossiers_on_procedure_id"
end