-- +goose Up CREATE TABLE notification_outbox ( id BIGSERIAL PRIMARY KEY, channel_id BIGINT NOT NULL REFERENCES notification_channels(id) ON DELETE CASCADE, event_type TEXT NOT NULL DEFAULT '', body TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending', attempt_count INTEGER NOT NULL DEFAULT 0, next_attempt_at BIGINT NOT NULL DEFAULT 0, lease_expires_at BIGINT NOT NULL DEFAULT 0, worker_token TEXT NOT NULL DEFAULT '', last_error TEXT NOT NULL DEFAULT '', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); CREATE INDEX idx_notification_outbox_due ON notification_outbox(status, next_attempt_at, lease_expires_at); -- +goose Down DROP TABLE IF EXISTS notification_outbox;