feat(backend): enforce unique names and surface duplicate errors

This commit is contained in:
Matthieu
2025-10-13 17:03:36 +02:00
parent dc4a12440b
commit 582a6fd7e1
6 changed files with 228 additions and 58 deletions

View File

@@ -0,0 +1,16 @@
-- Drop previous non-unique index to replace it with a unique constraint
DROP INDEX IF EXISTS "ModelType_category_name_idx";
-- Ensure unique names for machines, components, and pieces
ALTER TABLE "machines"
ADD CONSTRAINT "machines_name_key" UNIQUE ("name");
ALTER TABLE "composants"
ADD CONSTRAINT "composants_name_key" UNIQUE ("name");
ALTER TABLE "pieces"
ADD CONSTRAINT "pieces_name_key" UNIQUE ("name");
-- Enforce unique category/name pairs for model types (component & piece categories)
ALTER TABLE "ModelType"
ADD CONSTRAINT "ModelType_category_name_key" UNIQUE ("category", "name");