Files
it_cost_dashboard/prisma/schema.prisma
T
2026-09-08 17:46:28 +08:00

59 lines
1.7 KiB
Plaintext

// Prisma schema for the IT Cost Dashboard.
//
// Datasource provider is hardcoded to "sqlite" for local dev because Prisma does
// NOT support env() for the `provider` field (only for `url`). Production on RDS
// uses a separate MySQL schema at prisma/prod/schema.prisma with its own
// migration history in prisma/prod/migrations (see DEPLOY.md). Keep the two
// schemas' models in sync.
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
// One row per (name, region, year). e.g. "Cloud Hosting" in AMEA IT 2026 is a
// distinct row from "Cloud Hosting" in EMEA IT 2026. Cost is never stored — it is
// always derived as SUM(subItems.subCost).
model CostItem {
id Int @id @default(autoincrement())
name String
region String
year Int
subItems SubCostItem[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([region, year])
}
model SubCostItem {
id Int @id @default(autoincrement())
name String
subCost Float
costItem CostItem @relation(fields: [costItemId], references: [id], onDelete: Cascade)
costItemId Int
@@index([costItemId])
}
// The TrendAI percentage that splits each item's Cost into TrendAI vs TrendLife
// for a given region+year. Applies uniformly to all items in that region+year.
model TrendAiPercentage {
id Int @id @default(autoincrement())
region String
year Int
percentage Float
@@unique([region, year])
}
// The set of years available for selection across the app. Managed on the Year
// Creation page. Cost items reference years by value (not FK) so a year can exist
// with no cost data yet.
model Year {
year Int @id
}