Macrostop and timeline segmentation
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "machine_work_orders" (
|
||||
"id" TEXT NOT NULL,
|
||||
"orgId" TEXT NOT NULL,
|
||||
"machineId" TEXT NOT NULL,
|
||||
"workOrderId" TEXT NOT NULL,
|
||||
"sku" TEXT,
|
||||
"targetQty" INTEGER,
|
||||
"cycleTime" DOUBLE PRECISION,
|
||||
"status" TEXT NOT NULL DEFAULT 'PENDING',
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "machine_work_orders_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "machine_work_orders_machineId_workOrderId_key" ON "machine_work_orders"("machineId", "workOrderId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "machine_work_orders_orgId_machineId_idx" ON "machine_work_orders"("orgId", "machineId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "machine_work_orders_orgId_workOrderId_idx" ON "machine_work_orders"("orgId", "workOrderId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "machine_work_orders" ADD CONSTRAINT "machine_work_orders_orgId_fkey" FOREIGN KEY ("orgId") REFERENCES "Org"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "machine_work_orders" ADD CONSTRAINT "machine_work_orders_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "Machine"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,90 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "org_settings" (
|
||||
"org_id" TEXT NOT NULL,
|
||||
"timezone" TEXT NOT NULL DEFAULT 'UTC',
|
||||
"shift_change_comp_min" INTEGER NOT NULL DEFAULT 10,
|
||||
"lunch_break_min" INTEGER NOT NULL DEFAULT 30,
|
||||
"stoppage_multiplier" DOUBLE PRECISION NOT NULL DEFAULT 1.5,
|
||||
"oee_alert_threshold_pct" DOUBLE PRECISION NOT NULL DEFAULT 90,
|
||||
"macro_stoppage_multiplier" DOUBLE PRECISION NOT NULL DEFAULT 5,
|
||||
"performance_threshold_pct" DOUBLE PRECISION NOT NULL DEFAULT 85,
|
||||
"quality_spike_delta_pct" DOUBLE PRECISION NOT NULL DEFAULT 5,
|
||||
"alerts_json" JSONB,
|
||||
"defaults_json" JSONB,
|
||||
"version" INTEGER NOT NULL DEFAULT 1,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
"updated_by" TEXT,
|
||||
|
||||
CONSTRAINT "org_settings_pkey" PRIMARY KEY ("org_id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "org_shifts" (
|
||||
"id" TEXT NOT NULL,
|
||||
"org_id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"start_time" TEXT NOT NULL,
|
||||
"end_time" TEXT NOT NULL,
|
||||
"sort_order" INTEGER NOT NULL,
|
||||
"enabled" BOOLEAN NOT NULL DEFAULT true,
|
||||
|
||||
CONSTRAINT "org_shifts_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "machine_settings" (
|
||||
"machine_id" TEXT NOT NULL,
|
||||
"org_id" TEXT NOT NULL,
|
||||
"overrides_json" JSONB,
|
||||
"updated_at" TIMESTAMP(3) NOT NULL,
|
||||
"updated_by" TEXT,
|
||||
|
||||
CONSTRAINT "machine_settings_pkey" PRIMARY KEY ("machine_id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "settings_audit" (
|
||||
"id" TEXT NOT NULL,
|
||||
"org_id" TEXT NOT NULL,
|
||||
"machine_id" TEXT,
|
||||
"actor_id" TEXT,
|
||||
"source" TEXT NOT NULL,
|
||||
"payload_json" JSONB NOT NULL,
|
||||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "settings_audit_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "org_shifts_org_id_idx" ON "org_shifts"("org_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "org_shifts_org_id_sort_order_idx" ON "org_shifts"("org_id", "sort_order");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "machine_settings_org_id_idx" ON "machine_settings"("org_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "settings_audit_org_id_created_at_idx" ON "settings_audit"("org_id", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "settings_audit_machine_id_created_at_idx" ON "settings_audit"("machine_id", "created_at");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "org_settings" ADD CONSTRAINT "org_settings_org_id_fkey" FOREIGN KEY ("org_id") REFERENCES "Org"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "org_shifts" ADD CONSTRAINT "org_shifts_org_id_fkey" FOREIGN KEY ("org_id") REFERENCES "Org"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "machine_settings" ADD CONSTRAINT "machine_settings_org_id_fkey" FOREIGN KEY ("org_id") REFERENCES "Org"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "machine_settings" ADD CONSTRAINT "machine_settings_machine_id_fkey" FOREIGN KEY ("machine_id") REFERENCES "Machine"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "settings_audit" ADD CONSTRAINT "settings_audit_org_id_fkey" FOREIGN KEY ("org_id") REFERENCES "Org"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "settings_audit" ADD CONSTRAINT "settings_audit_machine_id_fkey" FOREIGN KEY ("machine_id") REFERENCES "Machine"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
@@ -19,6 +19,7 @@ model Org {
|
||||
heartbeats MachineHeartbeat[]
|
||||
kpiSnapshots MachineKpiSnapshot[]
|
||||
events MachineEvent[]
|
||||
workOrders MachineWorkOrder[]
|
||||
settings OrgSettings?
|
||||
shifts OrgShift[]
|
||||
machineSettings MachineSettings[]
|
||||
@@ -119,6 +120,7 @@ model Machine {
|
||||
kpiSnapshots MachineKpiSnapshot[]
|
||||
events MachineEvent[]
|
||||
cycles MachineCycle[]
|
||||
workOrders MachineWorkOrder[]
|
||||
settings MachineSettings?
|
||||
settingsAudits SettingsAudit[]
|
||||
|
||||
@@ -239,6 +241,27 @@ model MachineCycle {
|
||||
@@index([orgId, machineId, cycleCount])
|
||||
}
|
||||
|
||||
model MachineWorkOrder {
|
||||
id String @id @default(uuid())
|
||||
orgId String
|
||||
machineId String
|
||||
workOrderId String
|
||||
sku String?
|
||||
targetQty Int?
|
||||
cycleTime Float?
|
||||
status String @default("PENDING")
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
|
||||
machine Machine @relation(fields: [machineId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([machineId, workOrderId])
|
||||
@@index([orgId, machineId])
|
||||
@@index([orgId, workOrderId])
|
||||
@@map("machine_work_orders")
|
||||
}
|
||||
|
||||
model IngestLog {
|
||||
id String @id @default(uuid())
|
||||
orgId String?
|
||||
@@ -269,6 +292,7 @@ model OrgSettings {
|
||||
lunchBreakMin Int @default(30) @map("lunch_break_min")
|
||||
stoppageMultiplier Float @default(1.5) @map("stoppage_multiplier")
|
||||
oeeAlertThresholdPct Float @default(90) @map("oee_alert_threshold_pct")
|
||||
macroStoppageMultiplier Float @default(5) @map("macro_stoppage_multiplier")
|
||||
performanceThresholdPct Float @default(85) @map("performance_threshold_pct")
|
||||
qualitySpikeDeltaPct Float @default(5) @map("quality_spike_delta_pct")
|
||||
alertsJson Json? @map("alerts_json")
|
||||
|
||||
@@ -53,6 +53,7 @@ async function main() {
|
||||
lunchBreakMin: 30,
|
||||
stoppageMultiplier: 1.5,
|
||||
oeeAlertThresholdPct: 90,
|
||||
macroStoppageMultiplier: 5,
|
||||
performanceThresholdPct: 85,
|
||||
qualitySpikeDeltaPct: 5,
|
||||
alertsJson: {
|
||||
|
||||
Reference in New Issue
Block a user