db: add uniqueness constraints to Champs

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

View file

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

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_06_04_095054) do ActiveRecord::Schema.define(version: 2021_07_22_133440) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -174,6 +174,7 @@ ActiveRecord::Schema.define(version: 2021_06_04_095054) do
t.index ["parent_id"], name: "index_champs_on_parent_id" t.index ["parent_id"], name: "index_champs_on_parent_id"
t.index ["private"], name: "index_champs_on_private" t.index ["private"], name: "index_champs_on_private"
t.index ["row"], name: "index_champs_on_row" t.index ["row"], name: "index_champs_on_row"
t.index ["type_de_champ_id", "dossier_id", "row"], name: "index_champs_on_type_de_champ_id_and_dossier_id_and_row", unique: true
t.index ["type_de_champ_id"], name: "index_champs_on_type_de_champ_id" t.index ["type_de_champ_id"], name: "index_champs_on_type_de_champ_id"
end end