db/schema/0201_thread.sql
Orion Kindel 4a81f5fbde
Some checks failed
migrate-devel / migrate-devel (push) Failing after 7s
migrate-stage / migrate-stage (push) Failing after 8s
feat: human uid
2023-07-15 22:17:16 -04:00

71 lines
3.0 KiB
SQL

create type public.thread_kind as enum
( 'feed'
, 'message_feed'
, 'message'
, 'post_feed'
, 'post'
, 'comment'
, 'symbolic'
);
create table public.thread
( id int not null primary key generated always as identity
, uid human_uuid.huid not null unique default human_uuid.huid()
, deleted boolean not null default false
, kind public.thread_kind not null
);
select audit('public', 'thread', array[] :: audited_column[], soft_delete => true);
select immutable('public', 'thread', array['id', 'uid', 'kind']);
create table public.thread_feed
( id int not null primary key generated always as identity
, uid human_uuid.huid not null unique default human_uuid.huid()
, deleted boolean not null default false
, thread int not null references public.thread(id)
-- , community int not null references public.community(id)
);
select audit('public', 'thread_feed', array[] :: audited_column[], soft_delete => true);
select immutable('public', 'thread_feed', array['id', 'uid', 'thread', 'community']);
create type public.thread_attachment_kind as enum
( 'vote'
, 'emoji'
);
create type public.thread_attachment_vote_direction as enum
( 'up'
, 'down'
);
create table public.thread_attachment
( id int not null primary key generated always as identity
, uid human_uuid.huid not null unique default human_uuid.huid()
, thread int not null references public.thread(id)
, kind public.thread_attachment_kind not null
);
select audit('public', 'thread_attachment', array[] :: audited_column[], soft_delete => true);
select immutable('public', 'thread_attachment', array['id', 'uid', 'thread', 'kind']);
create table public.thread_attachment_emoji
( id int not null primary key generated always as identity
, uid human_uuid.huid not null unique default human_uuid.huid()
, thread_attachment int not null references public.thread_attachment(id)
, emoji text not null
);
select audit('public', 'thread_attachment_emoji', array[] :: audited_column[], soft_delete => true);
select immutable('public', 'thread_attachment_emoji', array['id', 'uid', 'thread_attachment', 'emoji']);
create table public.thread_attachment_vote
( id int not null primary key generated always as identity
, uid human_uuid.huid not null unique default human_uuid.huid()
, thread_attachment int not null references public.thread_attachment(id)
, direction public.thread_attachment_vote_direction not null
);
select audit('public', 'thread_attachment_vote', array[] :: audited_column[], soft_delete => true);
select immutable('public', 'thread_attachment_vote', array['id', 'uid', 'thread_attachment', 'direction']);