Files
dataroom/prisma/schema/workflow.prisma
zeekayandHanzo Dev 8dfcb6af82 feat(db): migrate Prisma datasource postgres -> sqlite (native, file-backed)
Drops the shared sql-0 postgres dependency in favor of an embedded SQLite
file (DATABASE_URL=file:/data/<db>), WAL-replicated to SeaweedFS by the
operator persistence sidecar — same pattern as esign (Documenso).

Schema changes for the sqlite connector:
- datasource provider postgresql -> sqlite; drop directUrl/shadowDatabaseUrl
- 18 enums -> String (values preserved as string defaults)
- scalar-list fields (String[]/Int[]) -> Json @default("[]") (arrays
  round-trip through Prisma Json at runtime; next.config ignoreBuildErrors
  keeps the type-only churn out of the build)
- strip pg-native @db.* attributes (@db.Text/@db.Timestamp)
- startup: prisma migrate deploy -> prisma db push (pg migration history is
  postgres-specific; db push reconciles the sqlite schema idempotently)

CI: amd64-only (DOKS has no arm64); deploy:false — rollout is operator-managed
via the universe Service CR, never `kubectl set image`.

Verified: `prisma validate` + `prisma db push` materialize all 62 tables on a
fresh sqlite file. Source DB is empty (0 app rows), so cutover is data-safe.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-05 00:33:13 -07:00

80 lines
2.5 KiB
Plaintext

// Workflow models for routing visitors based on email/domain rules
model Workflow {
id String @id @default(cuid())
name String
description String?
entryLinkId String @unique
teamId String
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
entryLink Link @relation(fields: [entryLinkId], references: [id], onDelete: Cascade)
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
steps WorkflowStep[]
executions WorkflowExecution[]
@@index([entryLinkId])
@@index([teamId])
@@index([isActive])
}
model WorkflowStep {
id String @id @default(cuid())
workflowId String
name String
stepOrder Int // Execution order (priority-based routing)
stepType String @default("ROUTER")
conditions Json // JSON array of conditions to evaluate
actions Json // JSON array of actions to execute
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
workflow Workflow @relation(fields: [workflowId], references: [id], onDelete: Cascade)
executionLogs WorkflowStepLog[]
@@unique([workflowId, stepOrder])
@@index([workflowId])
}
model WorkflowExecution {
id String @id @default(cuid())
workflowId String
visitorEmail String?
visitorIp String?
status String
startedAt DateTime @default(now())
completedAt DateTime?
result Json? // Final result/output (routing target)
metadata Json? // Context data (referrer, user agent, etc.)
workflow Workflow @relation(fields: [workflowId], references: [id], onDelete: Cascade)
stepLogs WorkflowStepLog[]
@@index([workflowId, startedAt])
@@index([visitorEmail])
@@index([status])
}
model WorkflowStepLog {
id String @id @default(cuid())
executionId String
workflowStepId String
conditionsMatched Boolean
conditionResults Json? // Which conditions passed/failed
actionsExecuted Json? // Which actions ran
executedAt DateTime @default(now())
duration Int? // Execution time in ms
error String?
execution WorkflowExecution @relation(fields: [executionId], references: [id], onDelete: Cascade)
step WorkflowStep @relation(fields: [workflowStepId], references: [id], onDelete: Cascade)
@@index([executionId])
@@index([workflowStepId])
}