···11+-- Queue schema for project-q messenger (Postgres transport)
22+CREATE SCHEMA IF NOT EXISTS queue;
33+44+CREATE TABLE IF NOT EXISTS queue.messages (
55+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
66+ queue_name TEXT NOT NULL,
77+ body JSONB NOT NULL,
88+ headers JSONB NOT NULL DEFAULT '{}',
99+ available_at TIMESTAMPTZ NOT NULL DEFAULT now(),
1010+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
1111+ delivered_at TIMESTAMPTZ
1212+);
1313+1414+CREATE INDEX IF NOT EXISTS idx_queue_dequeue
1515+ ON queue.messages (queue_name, available_at)
1616+ WHERE delivered_at IS NULL;