Repository: novuhq/novu
File: libs/application-generic/src/services/analytic-logs/workflow-run/workflow-run.schema.ts (TypeScript)

Code before:
  status: { type: CHLowCardinality(CHString()) }, // processing, error, completed
  delivery_lifecycle_status: { type: CHLowCardinality(CHString('')) },
  delivery_lifecycle_detail: { type: CHString('') },
  trigger_identifier: { type: CHString() }, // The event identifier that triggered the workflow

  // Correlation and grouping
  transaction_id: { type: CHString() },
  channels: { type: CHString() }, // JSON array of channels: ["email", "sms", "push"]

  // Subscriber context
  subscriber_to: { type: CHNullable(CHString()) }, // JSON representation of the 'to' field
  payload: { type: CHNullable(CHString()) }, // JSON representation of the payload
  control_values: { type: CHNullable(CHString()) }, // JSON representation of controls

  // Topic information
  topics: { type: CHNullable(CHString()) }, // JSON array of topics

  // Digest information
  is_digest: { type: CHLowCardinality(CHString()) }, // 'true' or 'false'
  digested_workflow_run_id: { type: CHNullable(CHString()) }, // Reference to parent digest if this is a digested notification

  // Data retention
  expires_at: { type: CHDateTime64(3, 'UTC') },

  severity: { type: CHNullable(CHString()) }, // severity of the workflow run
  critical: { type: CHNullable(CHBoolean()) }, // critical flag of the workflow run
};

export const ORDER_BY: (keyof typeof schemaDefinition)[] = ['organization_id', 'workflow_run_id'];

export const TTL: keyof typeof schemaDefinition = 'expires_at';

const clickhouseSchemaOptions = {
  table_name: TABLE_NAME,
  engine: 'ReplacingMergeTree(updated_at)',
  order_by: `(${ORDER_BY.join(', ')})` as any,
  additional_options: ['PARTITION BY toYYYYMM(created_at)', `TTL toDateTime(${TTL})`],
};

export const workflowRunSchema = new ClickhouseSchema(schemaDefinition, clickhouseSchemaOptions);

export enum WorkflowRunStatusEnum {
  /**
   * @deprecated please use processing instead nv-6562
   */
  PENDING = 'pending',
  PROCESSING = 'processing',
  /**
   * @deprecated please use COMPLETED instead nv-6562
   */
  SUCCESS = 'success',

Review comment (suggestion):
we can make those not nullable wit default values, it is more performant in ClickHouse to have any other value than null if possible.

```suggestion
  severity: { type: CHLowCardinality(CHString('none')) }, // severity of the workflow run
  critical: { type:CHBoolean(false) }, // critical flag of the workflow run
```

ALTER TABLE workflow_runs 
ADD COLUMN IF NOT EXISTS severity String DEFAULT 'none';

ALTER TABLE workflow_runs 
ADD COLUMN IF NOT EXISTS critical Boolean DEFAULT false';

Code after:
  status: { type: CHLowCardinality(CHString()) }, // processing, error, completed
  delivery_lifecycle_status: { type: CHLowCardinality(CHString('')) },
  delivery_lifecycle_detail: { type: CHString('') },
  trigger_identifier: { type: CHString() }, // The event identifier that triggered the workflow

  // Correlation and grouping
  transaction_id: { type: CHString() },
  channels: { type: CHString() }, // JSON array of channels: ["email", "sms", "push"]

  // Subscriber context
  subscriber_to: { type: CHNullable(CHString()) }, // JSON representation of the 'to' field
  payload: { type: CHNullable(CHString()) }, // JSON representation of the payload
  control_values: { type: CHNullable(CHString()) }, // JSON representation of controls

  // Topic information
  topics: { type: CHNullable(CHString()) }, // JSON array of topics

  // Digest information
  is_digest: { type: CHLowCardinality(CHString()) }, // 'true' or 'false'
  digested_workflow_run_id: { type: CHNullable(CHString()) }, // Reference to parent digest if this is a digested notification

  // Data retention
  expires_at: { type: CHDateTime64(3, 'UTC') },

  severity: { type: CHLowCardinality(CHString(SeverityLevelEnum.NONE)) }, // severity of the workflow run
  critical: { type: CHBoolean(false) }, // critical flag of the workflow run
};

export const ORDER_BY: (keyof typeof schemaDefinition)[] = ['organization_id', 'workflow_run_id'];

export const TTL: keyof typeof schemaDefinition = 'expires_at';

const clickhouseSchemaOptions = {
  table_name: TABLE_NAME,
  engine: 'ReplacingMergeTree(updated_at)',
  order_by: `(${ORDER_BY.join(', ')})` as any,
  additional_options: ['PARTITION BY toYYYYMM(created_at)', `TTL toDateTime(${TTL})`],
};

export const workflowRunSchema = new ClickhouseSchema(schemaDefinition, clickhouseSchemaOptions);

export enum WorkflowRunStatusEnum {
  /**
   * @deprecated please use processing instead nv-6562
   */
  PENDING = 'pending',
  PROCESSING = 'processing',
  /**
   * @deprecated please use COMPLETED instead nv-6562
   */
  SUCCESS = 'success',