add uniq index on attestation dossier_id

This commit is contained in:
simon lehericey 2022-04-05 12:13:25 +02:00
parent 4baa9ee43c
commit 200e8680d5
3 changed files with 12 additions and 5 deletions

View file

@ -0,0 +1,9 @@
class AddUniqIndexOnAttestationDossierId < ActiveRecord::Migration[6.1]
include Database::MigrationHelpers
disable_ddl_transaction!
def up
remove_index :attestations, :dossier_id
add_concurrent_index :attestations, :dossier_id, unique: true
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: 2022_03_23_120846) do ActiveRecord::Schema.define(version: 2022_04_05_100354) 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"
@ -134,7 +134,7 @@ ActiveRecord::Schema.define(version: 2022_03_23_120846) do
t.integer "dossier_id", null: false t.integer "dossier_id", null: false
t.string "title" t.string "title"
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.index ["dossier_id"], name: "index_attestations_on_dossier_id" t.index ["dossier_id"], name: "index_attestations_on_dossier_id", unique: true
end end
create_table "avis", id: :serial, force: :cascade do |t| create_table "avis", id: :serial, force: :cascade do |t|

View file

@ -1480,12 +1480,10 @@ describe Dossier do
before do before do
create(:dossier, transfer: transfer) create(:dossier, transfer: transfer)
create(:attestation, dossier: dossier) create(:attestation, dossier: dossier)
create(:attestation, dossier: dossier)
end end
it "can destroy dossier with two attestations" do it "can destroy dossier" do
expect(dossier.destroy).to be_truthy expect(dossier.destroy).to be_truthy
expect(transfer.reload).not_to be_nil
end end
end end