From 200e8680d507e175c6d969bf0223313cad25ef98 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 5 Apr 2022 12:13:25 +0200 Subject: [PATCH] add uniq index on attestation dossier_id --- ...405100354_add_uniq_index_on_attestation_dossier_id.rb | 9 +++++++++ db/schema.rb | 4 ++-- spec/models/dossier_spec.rb | 4 +--- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20220405100354_add_uniq_index_on_attestation_dossier_id.rb diff --git a/db/migrate/20220405100354_add_uniq_index_on_attestation_dossier_id.rb b/db/migrate/20220405100354_add_uniq_index_on_attestation_dossier_id.rb new file mode 100644 index 000000000..21b7c8d09 --- /dev/null +++ b/db/migrate/20220405100354_add_uniq_index_on_attestation_dossier_id.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 40d9f2ece..11feb6627 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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 enable_extension "plpgsql" @@ -134,7 +134,7 @@ ActiveRecord::Schema.define(version: 2022_03_23_120846) do t.integer "dossier_id", null: false t.string "title" 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 create_table "avis", id: :serial, force: :cascade do |t| diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index ce5249bc6..2b8298a50 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1480,12 +1480,10 @@ describe Dossier do before do create(:dossier, transfer: transfer) create(:attestation, dossier: dossier) - create(:attestation, dossier: dossier) end - it "can destroy dossier with two attestations" do + it "can destroy dossier" do expect(dossier.destroy).to be_truthy - expect(transfer.reload).not_to be_nil end end