26 lines
960 B
SQL
26 lines
960 B
SQL
CREATE TABLE draft (
|
|
id uuid PRIMARY KEY,
|
|
household_id uuid NOT NULL,
|
|
subject text NOT NULL,
|
|
original_text text NOT NULL,
|
|
candidates jsonb NOT NULL DEFAULT '[]',
|
|
status text NOT NULL CHECK (status IN
|
|
('GENERATING','READY','MODEL_UNAVAILABLE','PROCESSING','COMPLETED','NEEDS_REVIEW')),
|
|
version integer NOT NULL DEFAULT 0,
|
|
created_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
|
|
CREATE TABLE confirm_operation (
|
|
id uuid PRIMARY KEY,
|
|
draft_id uuid NOT NULL REFERENCES draft(id),
|
|
draft_version integer NOT NULL,
|
|
payload jsonb NOT NULL,
|
|
status text NOT NULL DEFAULT 'PROCESSING'
|
|
CHECK (status IN ('PROCESSING','COMPLETED','REJECTED','NEEDS_REVIEW')),
|
|
attempts integer NOT NULL DEFAULT 0,
|
|
available_at timestamptz NOT NULL DEFAULT now(),
|
|
lease_until timestamptz,
|
|
UNIQUE (draft_id, draft_version)
|
|
);
|
|
CREATE INDEX active_outbox ON confirm_operation(available_at) WHERE status='PROCESSING';
|