Downtime catalog
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
-- Reason catalog: relational storage (replaces JSON in org_settings for new data).
|
||||
|
||||
CREATE TABLE "reason_catalog_category" (
|
||||
"id" TEXT NOT NULL,
|
||||
"org_id" TEXT NOT NULL,
|
||||
"kind" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"code_prefix" TEXT NOT NULL,
|
||||
"sort_order" INTEGER NOT NULL DEFAULT 0,
|
||||
"active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "reason_catalog_category_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE TABLE "reason_catalog_item" (
|
||||
"id" TEXT NOT NULL,
|
||||
"org_id" TEXT NOT NULL,
|
||||
"category_id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"code_suffix" TEXT NOT NULL,
|
||||
"reason_code" TEXT NOT NULL,
|
||||
"sort_order" INTEGER NOT NULL DEFAULT 0,
|
||||
"active" BOOLEAN NOT NULL DEFAULT true,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "reason_catalog_item_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE INDEX "reason_catalog_category_org_id_kind_active_idx" ON "reason_catalog_category"("org_id", "kind", "active");
|
||||
|
||||
CREATE UNIQUE INDEX "reason_catalog_item_org_id_reason_code_key" ON "reason_catalog_item"("org_id", "reason_code");
|
||||
|
||||
CREATE INDEX "reason_catalog_item_org_id_category_id_idx" ON "reason_catalog_item"("org_id", "category_id");
|
||||
|
||||
ALTER TABLE "reason_catalog_category" ADD CONSTRAINT "reason_catalog_category_org_id_fkey" FOREIGN KEY ("org_id") REFERENCES "Org"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "reason_catalog_item" ADD CONSTRAINT "reason_catalog_item_org_id_fkey" FOREIGN KEY ("org_id") REFERENCES "Org"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE "reason_catalog_item" ADD CONSTRAINT "reason_catalog_item_category_id_fkey" FOREIGN KEY ("category_id") REFERENCES "reason_catalog_category"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -33,6 +33,8 @@ model Org {
|
||||
shifts OrgShift[]
|
||||
productCostOverrides ProductCostOverride[]
|
||||
settingsAudits SettingsAudit[]
|
||||
reasonCatalogCategories ReasonCatalogCategory[]
|
||||
reasonCatalogItems ReasonCatalogItem[]
|
||||
}
|
||||
|
||||
model User {
|
||||
@@ -290,6 +292,42 @@ model IngestLog {
|
||||
@@index([machineId, seq])
|
||||
}
|
||||
|
||||
model ReasonCatalogCategory {
|
||||
id String @id @default(uuid())
|
||||
orgId String @map("org_id")
|
||||
kind String
|
||||
name String
|
||||
codePrefix String @map("code_prefix")
|
||||
sortOrder Int @default(0) @map("sort_order")
|
||||
active Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
|
||||
items ReasonCatalogItem[]
|
||||
|
||||
@@index([orgId, kind, active])
|
||||
@@map("reason_catalog_category")
|
||||
}
|
||||
|
||||
model ReasonCatalogItem {
|
||||
id String @id @default(uuid())
|
||||
orgId String @map("org_id")
|
||||
categoryId String @map("category_id")
|
||||
name String
|
||||
codeSuffix String @map("code_suffix")
|
||||
reasonCode String @map("reason_code")
|
||||
sortOrder Int @default(0) @map("sort_order")
|
||||
active Boolean @default(true)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
|
||||
category ReasonCatalogCategory @relation(fields: [categoryId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([orgId, reasonCode])
|
||||
@@index([orgId, categoryId])
|
||||
@@map("reason_catalog_item")
|
||||
}
|
||||
|
||||
model OrgSettings {
|
||||
orgId String @id @map("org_id")
|
||||
timezone String @default("UTC")
|
||||
|
||||
Reference in New Issue
Block a user