@@ -0,0 +1,59 @@
|
||||
-- RedefineTables
|
||||
PRAGMA defer_foreign_keys=ON;
|
||||
PRAGMA foreign_keys=OFF;
|
||||
CREATE TABLE "new_Assembly" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"projectId" TEXT NOT NULL,
|
||||
"code" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"qty" INTEGER NOT NULL DEFAULT 1,
|
||||
"notes" TEXT,
|
||||
"stepFileId" TEXT,
|
||||
"drawingFileId" TEXT,
|
||||
"cutFileId" TEXT,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "Assembly_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT "Assembly_stepFileId_fkey" FOREIGN KEY ("stepFileId") REFERENCES "FileAsset" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT "Assembly_drawingFileId_fkey" FOREIGN KEY ("drawingFileId") REFERENCES "FileAsset" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT "Assembly_cutFileId_fkey" FOREIGN KEY ("cutFileId") REFERENCES "FileAsset" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_Assembly" ("code", "createdAt", "id", "name", "notes", "projectId", "qty", "updatedAt") SELECT "code", "createdAt", "id", "name", "notes", "projectId", "qty", "updatedAt" FROM "Assembly";
|
||||
DROP TABLE "Assembly";
|
||||
ALTER TABLE "new_Assembly" RENAME TO "Assembly";
|
||||
CREATE UNIQUE INDEX "Assembly_projectId_code_key" ON "Assembly"("projectId", "code");
|
||||
CREATE TABLE "new_Operation" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"partId" TEXT NOT NULL,
|
||||
"sequence" INTEGER NOT NULL,
|
||||
"templateId" TEXT,
|
||||
"name" TEXT NOT NULL,
|
||||
"machineId" TEXT,
|
||||
"settings" TEXT,
|
||||
"materialNotes" TEXT,
|
||||
"instructions" TEXT,
|
||||
"qcRequired" BOOLEAN NOT NULL DEFAULT false,
|
||||
"status" TEXT NOT NULL DEFAULT 'pending',
|
||||
"qrToken" TEXT NOT NULL,
|
||||
"claimedByUserId" TEXT,
|
||||
"claimedAt" DATETIME,
|
||||
"completedAt" DATETIME,
|
||||
"plannedMinutes" INTEGER,
|
||||
"plannedUnits" INTEGER,
|
||||
"unitsCompleted" INTEGER NOT NULL DEFAULT 0,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "Operation_partId_fkey" FOREIGN KEY ("partId") REFERENCES "Part" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT "Operation_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "OperationTemplate" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT "Operation_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "Machine" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT "Operation_claimedByUserId_fkey" FOREIGN KEY ("claimedByUserId") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
INSERT INTO "new_Operation" ("claimedAt", "claimedByUserId", "completedAt", "createdAt", "id", "instructions", "machineId", "materialNotes", "name", "partId", "plannedMinutes", "plannedUnits", "qcRequired", "qrToken", "sequence", "settings", "status", "templateId", "updatedAt") SELECT "claimedAt", "claimedByUserId", "completedAt", "createdAt", "id", "instructions", "machineId", "materialNotes", "name", "partId", "plannedMinutes", "plannedUnits", "qcRequired", "qrToken", "sequence", "settings", "status", "templateId", "updatedAt" FROM "Operation";
|
||||
DROP TABLE "Operation";
|
||||
ALTER TABLE "new_Operation" RENAME TO "Operation";
|
||||
CREATE UNIQUE INDEX "Operation_qrToken_key" ON "Operation"("qrToken");
|
||||
CREATE INDEX "Operation_status_idx" ON "Operation"("status");
|
||||
CREATE INDEX "Operation_claimedByUserId_idx" ON "Operation"("claimedByUserId");
|
||||
CREATE UNIQUE INDEX "Operation_partId_sequence_key" ON "Operation"("partId", "sequence");
|
||||
PRAGMA foreign_keys=ON;
|
||||
PRAGMA defer_foreign_keys=OFF;
|
||||
+28
-16
@@ -112,17 +112,23 @@ model Project {
|
||||
}
|
||||
|
||||
model Assembly {
|
||||
id String @id @default(cuid())
|
||||
projectId String
|
||||
code String
|
||||
name String
|
||||
qty Int @default(1)
|
||||
notes String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id @default(cuid())
|
||||
projectId String
|
||||
code String
|
||||
name String
|
||||
qty Int @default(1)
|
||||
notes String?
|
||||
stepFileId String?
|
||||
drawingFileId String?
|
||||
cutFileId String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
|
||||
parts Part[]
|
||||
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
|
||||
parts Part[]
|
||||
stepFile FileAsset? @relation("AssemblyStep", fields: [stepFileId], references: [id], onDelete: SetNull)
|
||||
drawingFile FileAsset? @relation("AssemblyDrawing", fields: [drawingFileId], references: [id], onDelete: SetNull)
|
||||
cutFile FileAsset? @relation("AssemblyCut", fields: [cutFileId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@unique([projectId, code])
|
||||
}
|
||||
@@ -165,13 +171,16 @@ model Operation {
|
||||
materialNotes String?
|
||||
instructions String?
|
||||
qcRequired Boolean @default(false)
|
||||
status String @default("pending") // pending | in_progress | completed
|
||||
status String @default("pending") // pending | in_progress | partial | completed
|
||||
qrToken String @unique
|
||||
claimedByUserId String?
|
||||
claimedAt DateTime?
|
||||
completedAt DateTime?
|
||||
plannedMinutes Int?
|
||||
plannedUnits Int?
|
||||
/// Cumulative units recorded across every Start→Pause/Done cycle on this op.
|
||||
/// Incremented whenever an operator hands in a non-zero `unitsProcessed`.
|
||||
unitsCompleted Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@ -286,11 +295,14 @@ model FileAsset {
|
||||
uploadedBy String?
|
||||
uploadedAt DateTime @default(now())
|
||||
|
||||
partStep Part[] @relation("PartStep")
|
||||
partDrawing Part[] @relation("PartDrawing")
|
||||
partCut Part[] @relation("PartCut")
|
||||
partThumbnail Part[] @relation("PartThumbnail")
|
||||
poPdfs PurchaseOrder[] @relation("PoPdf")
|
||||
partStep Part[] @relation("PartStep")
|
||||
partDrawing Part[] @relation("PartDrawing")
|
||||
partCut Part[] @relation("PartCut")
|
||||
partThumbnail Part[] @relation("PartThumbnail")
|
||||
assemblyStep Assembly[] @relation("AssemblyStep")
|
||||
assemblyDrawing Assembly[] @relation("AssemblyDrawing")
|
||||
assemblyCut Assembly[] @relation("AssemblyCut")
|
||||
poPdfs PurchaseOrder[] @relation("PoPdf")
|
||||
}
|
||||
|
||||
model AuditLog {
|
||||
|
||||
Reference in New Issue
Block a user