10 lines
696 B
SQL
10 lines
696 B
SQL
CREATE TABLE email_deliveries (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(), event_id uuid NOT NULL REFERENCES events(id) ON DELETE CASCADE,
|
|
recipient text NOT NULL, payload jsonb NOT NULL, provider text NOT NULL,
|
|
status text NOT NULL DEFAULT 'pending', attempts integer NOT NULL DEFAULT 0,
|
|
first_attempt_at timestamptz, next_attempt_at timestamptz NOT NULL DEFAULT now(),
|
|
provider_id text, last_error text, created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
CREATE UNIQUE INDEX email_deliveries_event_recipient_idx ON email_deliveries(event_id, recipient);
|
|
CREATE INDEX email_deliveries_queue_idx ON email_deliveries(status, next_attempt_at);
|