-- +goose Up CREATE SCHEMA deliveries; -- A message is one notification on one channel. The composer reads its -- messages straight from here; channels that send (Telegram) get delivery -- attempts when they land. CREATE TABLE deliveries.messages ( seq bigserial PRIMARY KEY, id uuid NOT NULL UNIQUE, org_id text NOT NULL, channel text NOT NULL CHECK (channel IN ('composer')), kind text NOT NULL CHECK (kind IN ('notification')), run_id uuid, title text NOT NULL, body text NOT NULL, -- key makes a notification idempotent: a replayed step can't send twice. key text NOT NULL, created_at timestamptz NOT NULL DEFAULT now(), UNIQUE (org_id, channel, key) ); -- +goose Down DROP SCHEMA deliveries CASCADE;