This commit is contained in:
Tom Chien (IQ-AS)
2026-09-08 17:46:28 +08:00
commit e25c995560
55 changed files with 6928 additions and 0 deletions
@@ -0,0 +1,44 @@
-- CreateTable
CREATE TABLE `CostItem` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,
`region` VARCHAR(191) NOT NULL,
`year` INTEGER NOT NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updatedAt` DATETIME(3) NOT NULL,
INDEX `CostItem_region_year_idx`(`region`, `year`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `SubCostItem` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(191) NOT NULL,
`subCost` DOUBLE NOT NULL,
`costItemId` INTEGER NOT NULL,
INDEX `SubCostItem_costItemId_idx`(`costItemId`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `TrendAiPercentage` (
`id` INTEGER NOT NULL AUTO_INCREMENT,
`region` VARCHAR(191) NOT NULL,
`year` INTEGER NOT NULL,
`percentage` DOUBLE NOT NULL,
UNIQUE INDEX `TrendAiPercentage_region_year_key`(`region`, `year`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- CreateTable
CREATE TABLE `Year` (
`year` INTEGER NOT NULL,
PRIMARY KEY (`year`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddForeignKey
ALTER TABLE `SubCostItem` ADD CONSTRAINT `SubCostItem_costItemId_fkey` FOREIGN KEY (`costItemId`) REFERENCES `CostItem`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "mysql"
+61
View File
@@ -0,0 +1,61 @@
// Production Prisma schema for the IT Cost Dashboard (MySQL / AWS RDS).
//
// This mirrors prisma/schema.prisma exactly except the datasource provider is
// "mysql". Prisma does NOT support env() for the `provider` field, so dev
// (SQLite) and prod (MySQL) each need their own schema file + migrations.
//
// Usage on the production EC2 box (see DEPLOY.md):
// npm run prod:generate # prisma generate --schema=prisma/prod/schema.prisma
// npm run prod:migrate # prisma migrate deploy --schema=prisma/prod/schema.prisma
// npm run build:prod
datasource db {
provider = "mysql"
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
}