35 lines
1.3 KiB
SQL
35 lines
1.3 KiB
SQL
-- The LibreDesk conversations, copied by poller/poll.py (docs/superpowers/specs/2026-11-24-conversations-supabase-design.md).
|
|||
|
|
-- raw: LibreDesk's response as is; the other columns are taken from it, for searching.
|
||
|
|
create table conversations (
|
||
|
|
uuid text primary key,
|
||
|
|
reference_number text,
|
||
|
|
subject text,
|
||
|
|
status text,
|
||
|
|
inbox_name text,
|
||
|
|
contact_email text,
|
||
|
|
created_at timestamptz,
|
||
|
|
updated_at timestamptz not null,
|
||
|
|
raw jsonb not null
|
||
|
|
);
|
||
|
|
create index conversations_updated_at on conversations (updated_at desc);
|
||
|
|
|
||
|
|
create table messages (
|
||
|
|
uuid text primary key,
|
||
|
|
conversation_uuid text not null references conversations (uuid),
|
||
|
|
type text,
|
||
|
|
sender_type text,
|
||
|
|
private boolean,
|
||
|
|
created_at timestamptz,
|
||
|
|
raw jsonb not null
|
||
|
|
);
|
||
|
|
create index messages_conversation on messages (conversation_uuid, created_at);
|
||
|
|
|
||
|
|
-- The checkpoint of the last complete run (the equivalent of pumped.json).
|
||
|
|
create table checkpoints (name text primary key, until timestamptz not null);
|
||
|
|
|
||
|
|
alter table conversations enable row level security;
|
||
|
|
alter table messages enable row level security;
|
||
|
|
alter table checkpoints enable row level security;
|
||
|
|
grant all on conversations, messages, checkpoints to service_role;
|
||
|
|
|
||
|
|
insert into storage.buckets (id, name, public) values ('attachments', 'attachments', false);
|