Batch Item Table
Overview
Stores one batch request, its child job ID, and a durable SQS message. Child lifecycle rows and messages are inserted together in one transaction.
Table Definition
| Logical Name | Physical Name | Column Name | Data Type | Primary Key | Relation | Unique | Nullable | Default Value | Remarks |
|---|---|---|---|---|---|---|---|---|---|
| Batch Item | batch_item | id | string | โฏ | Backend UUIDv7 (varchar(255)) |
||||
| batch_id | string | batch:id | Owning batch / ใใใ (varchar(255)) |
||||||
| position | number | Zero-based input order / 0 ๅงใพใใฎๅ ฅๅ้ ๅบ | |||||||
| request | json | Validated API request / ๆค่จผๆธใฟ API ๅ
ฅๅ (jsonb) |
|||||||
| job_id | string | โฏ | Page Import or Code2Des ID / ๅญใธใงใ ID (varchar(255)) |
||||||
| message | json | โฏ | Durable worker payload / ๆฐธ็ถๅใใใฏใผใซใผๅ
ฅๅ (jsonb) |
||||||
| dispatched_at | datetime | โฏ | SQS accepted timestamp / SQS ้ไฟก็ขบ่ชๆฅๆ | ||||||
| lease_until | datetime | โฏ | Dispatch claim expiry / ใใฃในใใใๅๅพใฎๆๅนๆ้ | ||||||
| dispatch_attempts | number | 0 | Dispatch claim count / ใใฃในใใใ่ฉฆ่กๆฐ | ||||||
| error_message | string | โฏ | Terminal dispatch error / ใใฃในใใใๅคฑๆ็็ฑ (text) |
||||||
| cancelled_at | datetime | โฏ | Cancellation timestamp / ใญใฃใณใปใซๆฅๆ | ||||||
| created_at | datetime | CURRENT_TIMESTAMP | Shared audit field / ๅ ฑ้็ฃๆป้ ็ฎ | ||||||
| updated_at | datetime | CURRENT_TIMESTAMP | Shared audit field / ๅ ฑ้็ฃๆป้ ็ฎ | ||||||
| deleted_at | datetime | โฏ | Soft delete / ่ซ็ๅ้คๆฅๆ | ||||||
| created_by | string | Cognito subject (varchar(50)) |
|||||||
| updated_by | string | Cognito subject (varchar(50)) |
|||||||
| deleted_by | string | โฏ | Cognito subject (varchar(50)) |
Relations
batch_idโbatch.id(delete cascade)job_idresolves topage_import.idorcode2des.idaccording to batch type; no polymorphic foreign key. / ใใใ็จฎๅฅใซๅฟใใๅญใธใงใ IDใๅค้จใญใผๅถ็ดใฏ่จญๅฎใใพใใใ
Indexes
- PRIMARY KEY (
id) - INDEX
batch_item_batch_idx(batch_id,position) - INDEX
batch_item_dispatch_idx(dispatched_at,lease_until)
Notes
- Aggregate status is derived from child jobs and dispatch metadata; counters are not stored separately.
- Dispatch claims expire after 90 seconds. Row locks prevent concurrent claims. Queue delivery is attempted up to three times using the same child ID and message.
-
Workers do not connect to PostgreSQL. Existing webhooks update child job completion.
-
API status is derived:
"0"processing,"1"completed,"2"failed,"3"cancelled. Queued/running are separate counts, not stored statuses.