diff --git a/docs/erd.svg b/docs/erd.svg
index 7011ffd..5ee4b12 100644
--- a/docs/erd.svg
+++ b/docs/erd.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/prisma/migrations/20260426202231_add_entity_codes/migration.sql b/prisma/migrations/20260426202231_add_entity_codes/migration.sql
new file mode 100644
index 0000000..ecf5565
--- /dev/null
+++ b/prisma/migrations/20260426202231_add_entity_codes/migration.sql
@@ -0,0 +1,9 @@
+-- AlterTable
+ALTER TABLE "products" ADD COLUMN "code" VARCHAR(30);
+ALTER TABLE "pbis" ADD COLUMN "code" VARCHAR(30);
+ALTER TABLE "stories" ADD COLUMN "code" VARCHAR(30);
+
+-- CreateIndex
+CREATE UNIQUE INDEX "products_user_id_code_key" ON "products"("user_id", "code");
+CREATE UNIQUE INDEX "pbis_product_id_code_key" ON "pbis"("product_id", "code");
+CREATE UNIQUE INDEX "stories_product_id_code_key" ON "stories"("product_id", "code");
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index bf68dba..6acf5a1 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -95,6 +95,7 @@ model Product {
user User @relation(fields: [user_id], references: [id], onDelete: Cascade)
user_id String
name String
+ code String? @db.VarChar(30)
description String?
repo_url String?
definition_of_done String
@@ -108,6 +109,7 @@ model Product {
members ProductMember[]
@@unique([user_id, name])
+ @@unique([user_id, code])
@@index([user_id, archived])
@@map("products")
}
@@ -116,6 +118,7 @@ model Pbi {
id String @id @default(cuid())
product Product @relation(fields: [product_id], references: [id], onDelete: Cascade)
product_id String
+ code String? @db.VarChar(30)
title String
description String?
priority Int
@@ -124,6 +127,7 @@ model Pbi {
updated_at DateTime @updatedAt
stories Story[]
+ @@unique([product_id, code])
@@index([product_id, priority, sort_order])
@@map("pbis")
}
@@ -138,6 +142,7 @@ model Story {
sprint_id String?
assignee User? @relation("StoryAssignee", fields: [assignee_id], references: [id], onDelete: SetNull)
assignee_id String?
+ code String? @db.VarChar(30)
title String
description String?
acceptance_criteria String?
@@ -149,6 +154,7 @@ model Story {
logs StoryLog[]
tasks Task[]
+ @@unique([product_id, code])
@@index([pbi_id, priority, sort_order])
@@index([sprint_id, sort_order])
@@index([product_id, status])