ServerDatabase
Background Jobs & Notifications
Database tables defining the asynchronous execution job queue and transactional email/SMS logs.
Background Jobs & Notifications
This module schedules asynchronous tasks (such as overnight meal plan generations) and logs transactional notifications.
Migrated by: 00007_create_background_jobs_and_notifications.sql
1. Background Jobs Queue
background_jobs
Defines a transactional database-backed worker queue supporting retries and scheduled execution.
- Schema:
Column Type Constraints Default Description iduuidPRIMARY KEYgen_random_uuid()Unique job identifier. queue_nametextNOT NULL'default'Worker lane targeting (e.g. 'default','high_priority').job_typetextNOT NULL- Action name (e.g., 'meal_plan_generation').payloadjsonbNOT NULL'{}'Task parameters passed to the background handler. statustextNOT NULL'queued'State: 'queued','processing','completed', or'failed'.attemptsintegerNOT NULL0Number of executed attempts. max_attemptsintegerNOT NULL3Maximum retry limit before marking as failed. run_attimestamptzNOT NULLnow()Target scheduled execution time. locked_attimestamptz- - Lock timestamp when a worker claims the task. locked_byuuid- - Worker process identity uuid. started_attimestamptz- - Execution start timestamp. completed_attimestamptz- - Execution complete timestamp. error_logtext- - Error stack trace if the execution failed. created_attimestamptzNOT NULLnow()Record creation timestamp. updated_attimestamptzNOT NULLnow()Record change timestamp.
2. Notification Audit Log
notification_logs
Chronicles all outgoing transactional customer alerts.
- Schema:
Column Type Constraints Default Description iduuidPRIMARY KEYgen_random_uuid()Audit log identifier. user_iduuidREFERENCES users(id) ON DELETE SET NULL- Target recipient user profile. channeltextNOT NULL- Target delivery mechanism: 'email'or'sms'.recipienttextNOT NULL- Target destination (e.g., phone number or email address). statustextNOT NULL'queued'Delivery status: 'queued','sent', or'failed'.providertext- - Sending provider (e.g., 'sendgrid','twilio').provider_message_idtext- - Unique tracking ID generated by provider. error_messagetext- - Error warning message returned if sending failed. sent_attimestamptz- - Timestamp when provider confirmed dispatch. created_attimestamptzNOT NULLnow()Record creation timestamp.