ALTER TABLE attachments ADD COLUMN status text NOT NULL DEFAULT 'ready' CHECK(status IN ('queued','processing','ready','failed')); ALTER TABLE attachments ADD COLUMN variants jsonb NOT NULL DEFAULT '[]'; ALTER TABLE attachments ADD COLUMN error_code text; CREATE TABLE attachment_jobs ( id uuid PRIMARY KEY, attachment_id uuid NOT NULL UNIQUE REFERENCES attachments(id), staging_key text NOT NULL, pipeline_version integer NOT NULL DEFAULT 1, attempts integer NOT NULL DEFAULT 0, next_attempt_at timestamptz NOT NULL DEFAULT now(), lease_until timestamptz, published_at timestamptz, created_at timestamptz NOT NULL DEFAULT now() );