This commit is contained in:
Marcelo
2025-12-18 20:17:20 +00:00
parent 0e9b2dd72d
commit ffc39a5c90
9 changed files with 1268 additions and 69 deletions

View File

@@ -0,0 +1,27 @@
-- CreateTable
CREATE TABLE "MachineCycle" (
"id" TEXT NOT NULL,
"orgId" TEXT NOT NULL,
"machineId" TEXT NOT NULL,
"ts" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"cycleCount" INTEGER,
"actualCycleTime" DOUBLE PRECISION NOT NULL,
"theoreticalCycleTime" DOUBLE PRECISION,
"workOrderId" TEXT,
"sku" TEXT,
"cavities" INTEGER,
"goodDelta" INTEGER,
"scrapDelta" INTEGER,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "MachineCycle_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE INDEX "MachineCycle_orgId_machineId_ts_idx" ON "MachineCycle"("orgId", "machineId", "ts");
-- CreateIndex
CREATE INDEX "MachineCycle_orgId_machineId_cycleCount_idx" ON "MachineCycle"("orgId", "machineId", "cycleCount");
-- AddForeignKey
ALTER TABLE "MachineCycle" ADD CONSTRAINT "MachineCycle_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "Machine"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -81,6 +81,8 @@ model Machine {
heartbeats MachineHeartbeat[]
kpiSnapshots MachineKpiSnapshot[]
events MachineEvent[]
cycles MachineCycle[]
@@unique([orgId, name])
@@index([orgId])
@@ -161,3 +163,27 @@ model MachineEvent {
@@index([orgId, machineId, ts])
@@index([orgId, machineId, eventType, ts])
}
model MachineCycle {
id String @id @default(uuid())
orgId String
machineId String
ts DateTime @default(now())
cycleCount Int?
actualCycleTime Float
theoreticalCycleTime Float?
workOrderId String?
sku String?
cavities Int?
goodDelta Int?
scrapDelta Int?
createdAt DateTime @default(now())
machine Machine @relation(fields: [machineId], references: [id])
@@index([orgId, machineId, ts])
@@index([orgId, machineId, cycleCount])
}