Files
schedtxt_api/migrations/20260613211440_init.sql
T
phoenix 7873e8ed00
textsender_api PR / Rustfmt (pull_request) Successful in 40s
textsender_api PR / Check (pull_request) Successful in 1m33s
textsender_api PR / Clippy (pull_request) Successful in 2m12s
Create scheduled message event (#17)
Reviewed-on: phoenix/textsender_api#17
2026-06-18 18:39:24 -04:00

46 lines
1.3 KiB
SQL

-- Add migration script here
CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE IF NOT EXISTS "contacts" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
phone_number TEXT NOT NULL,
user_id UUID NOT NULL,
firstname TEXT NULL,
lastname TEXT NULL,
nickname TEXT NULL
);
CREATE TABLE IF NOT EXISTS "messages" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
content TEXT NOT NULL,
user_id UUID NOT NULL
);
CREATE TABLE IF NOT EXISTS "scheduled_messages" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
scheduled timestamptz NOT NULL,
created timestamptz DEFAULT now(),
status TEXT CHECK (status IN ('PENDING', 'READY', 'PROCESSING', 'DONE')),
user_id UUID NOT NULL
);
CREATE TABLE IF NOT EXISTS "scheduled_message_events" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
contact_id UUID NOT NULL,
message_id UUID NOT NULL,
scheduled_message_id UUID NOT NULL,
created timestamptz DEFAULT now()
);
CREATE TABLE IF NOT EXISTS "message_event_responses" (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
scheduled_message_event_id UUID NULL,
response JSONB NOT NULL,
user_id UUID NOT NULL,
sent timestamptz NOT NULL,
contact_id UUID NULL,
message_id UUID NULL,
status TEXT CHECK (status IN ('INSTANT', 'SCHEDULED'))
);