Merge pull request #7117 from betagouv/remove_duplicate_attestation_part_2

Ajoute un index unique sur attestation dossier_id
This commit is contained in:
LeSim 2022-04-05 15:46:56 +02:00 committed by GitHub
commit be86384125
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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.
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|

View file

@ -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