Skip to main content
This reference documents the database models used by Workflow Builder in the Commenda Logical Backend.

WorkflowTemplate

Stores workflow template definitions:
model WorkflowTemplate {
  id          String  @id @default(cuid())
  name        String
  description String?

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  ActiveVersion   WorkflowTemplateVersion? @relation(
    fields: [activeVersionId], 
    references: [id], 
    name: "active_workflow_template_version"
  )
  activeVersionId String? @unique

  Versions WorkflowTemplateVersion[] @relation("workflow_template_has_version")
  WorkflowTemplateLinks WorkflowTemplateLink[]
}
FieldDescription
idUnique identifier
nameTemplate name
descriptionOptional description
activeVersionIdCurrently active version
VersionsAll versions of this template
WorkflowTemplateLinksTrigger configurations

WorkflowTemplateVersion

Stores versions of workflow templates:
enum WorkflowTemplateVersionStatus {
  DRAFT
  PUBLISHED
  DEPRECATED
}

model WorkflowTemplateVersion {
  id String @id @default(cuid())

  WorkflowTemplate   WorkflowTemplate @relation(
    fields: [workflowTemplateId], 
    references: [id], 
    onDelete: Cascade, 
    name: "workflow_template_has_version"
  )
  workflowTemplateId String

  version     String
  versionNote String?
  definition  Json

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt

  status WorkflowTemplateVersionStatus @default(DRAFT)

  ActiveWorkflowTemplate WorkflowTemplate? @relation(
    name: "active_workflow_template_version"
  )

  WorkflowExecutions WorkflowExecution[]

  @@unique([workflowTemplateId, version])
}
FieldDescription
idUnique identifier
workflowTemplateIdParent template reference
versionSemantic version (e.g., “1.0.0”)
versionNoteChangelog for this version
definitionJSON workflow definition
statusDRAFT, PUBLISHED, or DEPRECATED

Version status lifecycle

DRAFT → PUBLISHED → (activate) → Active
  │                      │
  │                      └──→ DEPRECATED

  └── (edit allowed)
  • DRAFT - Can be edited, not yet ready for production
  • PUBLISHED - Ready to be activated, cannot be edited
  • DEPRECATED - No longer recommended for use
Only one version can be linked as the active version for a template at a time.
Defines how workflows are triggered:
enum WorkflowLinkType {
  SERVICE_CATALOG
  PRODUCT
}

model WorkflowTemplateLink {
  id String @id @default(cuid())

  WorkflowTemplate   WorkflowTemplate @relation(
    fields: [workflowTemplateId], 
    references: [id], 
    onDelete: Cascade
  )
  workflowTemplateId String

  entityType WorkflowLinkType
  entityId   String

  @@unique([entityType, entityId])
}
FieldDescription
workflowTemplateIdTemplate to trigger
entityTypeSERVICE_CATALOG or PRODUCT
entityIdService request type or product ID
TypeTrigger condition
SERVICE_CATALOGWhen a specific service request type is created
PRODUCTWhen a specific product is purchased (from billing)
When a matching entity is created/purchased and a workflow link exists, the active version of the linked template is automatically instantiated.

WorkflowExecution

Represents a running workflow instance:
enum WorkflowExecutionStatus {
  CREATED
  STARTED
  FAILED_TO_START
  COMPLETED
}

model WorkflowExecution {
  id   String @id @default(cuid())
  name String

  WorkflowTemplateVersion   WorkflowTemplateVersion @relation(
    fields: [workflowTemplateVersionId], 
    references: [id]
  )
  workflowTemplateVersionId String

  createdAt DateTime @default(now())

  ParentWorkflowExecution   WorkflowExecution? @relation(
    fields: [parentWorkflowExecutionId], 
    references: [id], 
    onDelete: Cascade, 
    name: "parent_workflow_execution"
  )
  parentWorkflowExecutionId String?

  RootWorkflowExecution   WorkflowExecution? @relation(
    fields: [rootWorkflowExecutionId], 
    references: [id], 
    onDelete: Cascade, 
    name: "root_workflow_execution"
  )
  rootWorkflowExecutionId String?

  context Json?
  status  WorkflowExecutionStatus @default(CREATED)

  ChildWorkflowExecutions WorkflowExecution[] @relation("parent_workflow_execution")
  DescendantWorkflowExecutionsFromRoot WorkflowExecution[] @relation("root_workflow_execution")

  ServiceRequest          ServiceRequest?
  ServiceRequestTaskGroup ServiceRequestTaskGroup?
}
FieldDescription
idUnique execution identifier
nameExecution name
workflowTemplateVersionIdTemplate version being executed
parentWorkflowExecutionIdParent execution (for sub-workflows)
rootWorkflowExecutionIdRoot execution (for correlation)
contextMetadata and global context
statusExecution lifecycle status

Execution status

StatusDescription
CREATEDInstance created, not yet started
STARTEDExecution has begun
FAILED_TO_STARTExecution failed to start
COMPLETEDExecution finished successfully
The status field tracks the database record lifecycle, not the runtime status. Runtime status is tracked in Temporal.

Context field

The context field stores:
  • Workflow metadata - e.g., directorId for DSC workflows
  • Global context - Accessible via __context__ in expressions
Note: This context is separate from the Temporal runtime context.

Hierarchy relationships

Root Execution

    ├── Child Execution 1 (parentWorkflowExecutionId = root)
    │       │
    │       └── Grandchild Execution (rootWorkflowExecutionId = root)

    └── Child Execution 2 (parentWorkflowExecutionId = root)
  • parentWorkflowExecutionId - Direct parent
  • rootWorkflowExecutionId - Ultimate ancestor (for correlation)

Entity relationships

┌──────────────────┐
│ WorkflowTemplate │
└────────┬─────────┘
         │ 1:N

┌────────────────────────┐      ┌─────────────────────┐
│ WorkflowTemplateVersion│──────│ WorkflowTemplateLink│
└────────┬───────────────┘      └─────────────────────┘
         │ 1:N

┌───────────────────┐
│ WorkflowExecution │──┐
└───────────────────┘  │
         ▲             │ (parent/child)
         └─────────────┘

Next steps

Validation rules

Definition validation rules

Service request integration

Legacy service request mapping