Skip to main content

Trigger Rules & Scheduled Jobs

Overview

This domain has 4 tables: trigger_rule stores rules describing "when this happens, do that" (source + action as JSONB), trigger_log records every rule firing and its outcome, scheduled_action holds actions queued for later execution, and scheduled_trigger_execution records the result of each scheduled run of a rule

Table trigger_rule

ColumnTypeNullableDefaultDescription
idSERIALNOnextval(...)Primary key
nameVARCHAR(255)NO-Trigger rule name
source_typeVARCHAR(30)NO-Type of the event source that fires the rule
source_configJSONBNO-Event source configuration (trigger conditions)
action_typeVARCHAR(30)NO-Type of action performed when the rule fires
action_configJSONBNO-Action configuration
enabledBOOLEANNOtrueWhether the rule is enabled
frequencyVARCHAR(20)NO'once_per_hour'Maximum firing frequency for this rule
cooldown_secondsINTEGERYES-Cooldown before the rule may fire again (seconds)
line_oa_idINTEGERNO-LINE OA the rule belongs to
organization_idINTEGERNO-Organization that owns the rule
created_byINTEGERYES-Creator (user id)
updated_byINTEGERYES-Last updater (user id)
created_dateTIMESTAMPTZ(3)NOnow()Creation timestamp
updated_dateTIMESTAMPTZ(3)YES-Last update timestamp
deleted_dateTIMESTAMPTZ(3)YES-Deletion timestamp (soft delete)
workflow_idINTEGERYES-Workflow this rule is part of (FK to workflow.id)
workflow_node_pathVARCHAR(500)YES-Path of the workflow node this rule refers to

Table trigger_log

ColumnTypeNullableDefaultDescription
idBIGSERIALNOnextval(...)Primary key
trigger_rule_idINTEGERNO-Rule that fired
audience_idINTEGERYES-Audience involved in this firing
user_idVARCHAR(255)NO-User the rule acted on (LINE user id)
trigger_onVARCHAR(20)NO-Event that caused the rule to fire
action_typeVARCHAR(30)NO-Type of action that was performed
action_configJSONBYES-Action configuration actually used for this run
statusVARCHAR(20)NO'success'Outcome of the action
error_messageTEXTYES-Error message when the action failed
line_oa_idINTEGERNO-Related LINE OA
organization_idINTEGERNO-Related organization
created_dateTIMESTAMPTZ(3)NOnow()Log timestamp

Table scheduled_action

ColumnTypeNullableDefaultDescription
idSERIALNOnextval(...)Primary key
trigger_rule_idINTEGERYES-Rule that created this scheduled action
user_idVARCHAR(64)NO-Target user of the action (LINE user id)
line_oa_idINTEGERNO-Related LINE OA
organization_idINTEGERNO-Related organization
action_typeVARCHAR(30)NO-Type of action to perform when due
action_configJSONBNO-Action configuration
source_configJSONBYES-Configuration of the event source that produced this action
execute_atTIMESTAMPTZNO-Time the action is scheduled to run
expires_atTIMESTAMPTZYES-Time after which the action is no longer valid
statusVARCHAR(20)NO'pending'Status of the action in the queue
retry_countINTEGERNO0Number of retry attempts
created_atTIMESTAMPTZNOnow()Creation timestamp
updated_atTIMESTAMPTZNOnow()Last update timestamp
executed_atTIMESTAMPTZYES-Time the action actually ran
workflow_idINTEGERYES-Workflow this action originated from
workflow_node_pathVARCHAR(500)YES-Workflow node path that created this action

Table scheduled_trigger_execution

ColumnTypeNullableDefaultDescription
idSERIALNOnextval(...)Primary key
trigger_rule_idINTEGERNO-Rule executed in this run
scheduled_atTIMESTAMPTZNO-Scheduled time of this run
started_atTIMESTAMPTZNOnow()Time the run started
completed_atTIMESTAMPTZYES-Time the run finished
statusVARCHAR(20)NO'processing'Status of the run
total_usersINTEGERNO0Total users in this run
processed_usersINTEGERNO0Users processed successfully
failed_usersINTEGERNO0Users that failed processing
error_messageTEXTYES-Error message for the run
created_atTIMESTAMPTZNOnow()Record creation timestamp

Notes

  • trigger_rule.workflow_id is the only schema-level FK in this group — it points to workflow.id (see Workflow Automation)
  • trigger_log.trigger_rule_id, scheduled_action.trigger_rule_id and scheduled_trigger_execution.trigger_rule_id reference trigger_rule.id logically but are not declared as FKs in the schema
  • scheduled_trigger_execution has the unique constraint uq_scheduled_trigger_execution on (trigger_rule_id, scheduled_at), preventing the same run from executing twice
  • scheduled_action has dedicated queue-polling indexes: idx_scheduled_action_pending (on execute_at), idx_scheduled_action_processing (on updated_at) and idx_scheduled_action_user (on user_id, trigger_rule_id)
  • trigger_log is indexed on (trigger_rule_id, created_date DESC) for fetching a rule's most recent logs
  • trigger_rule is indexed on (line_oa_id, organization_id) and on deleted_date
  • Timestamp columns in scheduled_action and scheduled_trigger_execution use TIMESTAMPTZ at default precision (microseconds), unlike most other tables which use TIMESTAMPTZ(3)
  • Some of the events that fire trigger_rule arrive through pg_notify / the event outbox (see pg_notify and Event Outbox)