db/schema/021_thread.sql

71 lines
2.9 KiB
MySQL
Raw Normal View History

2023-06-10 22:43:27 +00:00
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 uuid not null default gen_random_uuid()
, deleted boolean not null default false
, kind public.thread_kind not null
);
2023-06-11 16:26:39 +00:00
select audit('public', 'thread', array[] :: audited_column[], soft_delete => true);
select immutable('public', 'thread', array['id', 'uid', 'kind']);
2023-06-10 22:43:27 +00:00
create table public.thread_feed
( id int not null primary key generated always as identity
, uid uuid not null default gen_random_uuid()
, deleted boolean not null default false
, thread int not null references public.thread(id)
-- , community int not null references public.community(id)
);
2023-06-11 16:26:39 +00:00
select audit('public', 'thread_feed', array[] :: audited_column[], soft_delete => true);
select immutable('public', 'thread_feed', array['id', 'uid', 'thread', 'community']);
2023-06-10 22:43:27 +00:00
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 uuid not null default gen_random_uuid()
, thread int not null references public.thread(id)
, kind public.thread_attachment_kind not null
);
2023-06-11 16:26:39 +00:00
select audit('public', 'thread_attachment', array[] :: audited_column[], soft_delete => true);
select immutable('public', 'thread_attachment', array['id', 'uid', 'thread', 'kind']);
2023-06-10 22:43:27 +00:00
create table public.thread_attachment_emoji
( id int not null primary key generated always as identity
, uid uuid not null default gen_random_uuid()
, thread_attachment int not null references public.thread_attachment(id)
, emoji text not null
);
2023-06-11 16:26:39 +00:00
select audit('public', 'thread_attachment_emoji', array[] :: audited_column[], soft_delete => true);
select immutable('public', 'thread_attachment_emoji', array['id', 'uid', 'thread_attachment', 'emoji']);
2023-06-10 22:43:27 +00:00
create table public.thread_attachment_vote
( id int not null primary key generated always as identity
, uid uuid not null default gen_random_uuid()
, thread_attachment int not null references public.thread_attachment(id)
, direction public.thread_attachment_vote_direction not null
);
2023-06-11 16:26:39 +00:00
select audit('public', 'thread_attachment_vote', array[] :: audited_column[], soft_delete => true);
select immutable('public', 'thread_attachment_vote', array['id', 'uid', 'thread_attachment', 'direction']);