2019-10-28 19:15:27 +00:00
-- Create proxy_tag compound type if it doesn't exist
do $ $ begin
create type proxy_tag as (
prefix text ,
suffix text
) ;
exception when duplicate_object then null ;
end $ $ ;
2019-07-09 18:39:29 +00:00
create table if not exists systems
(
id serial primary key ,
hid char ( 5 ) unique not null ,
name text ,
description text ,
tag text ,
avatar_url text ,
token text ,
created timestamp not null default ( current_timestamp at time zone ' utc ' ) ,
ui_tz text not null default ' UTC '
) ;
2019-12-22 13:15:56 +00:00
create table if not exists system_guild
(
system serial not null references systems ( id ) on delete cascade ,
guild bigint not null ,
proxy_enabled bool not null default true ,
primary key ( system , guild )
) ;
2019-07-09 18:39:29 +00:00
create table if not exists members
(
2019-08-09 08:12:38 +00:00
id serial primary key ,
hid char ( 5 ) unique not null ,
system serial not null references systems ( id ) on delete cascade ,
color char ( 6 ) ,
avatar_url text ,
name text not null ,
display_name text ,
birthday date ,
pronouns text ,
description text ,
2019-11-02 22:38:25 +00:00
proxy_tags proxy_tag [ ] not null default array [ ] : : proxy_tag [ ] , -- Rationale on making this an array rather than a separate table - we never need to query them individually, only access them as part of a selected Member struct
2019-10-30 08:26:50 +00:00
keep_proxy bool not null default false ,
2019-08-09 08:12:38 +00:00
created timestamp not null default ( current_timestamp at time zone ' utc ' )
2019-07-09 18:39:29 +00:00
) ;
create table if not exists accounts
(
uid bigint primary key ,
system serial not null references systems ( id ) on delete cascade
) ;
create table if not exists messages
(
2019-07-24 11:38:54 +00:00
mid bigint primary key ,
channel bigint not null ,
member serial not null references members ( id ) on delete cascade ,
sender bigint not null ,
original_mid bigint
2019-07-09 18:39:29 +00:00
) ;
create table if not exists switches
(
id serial primary key ,
system serial not null references systems ( id ) on delete cascade ,
timestamp timestamp not null default ( current_timestamp at time zone ' utc ' )
) ;
2019-10-05 20:30:55 +00:00
CREATE INDEX IF NOT EXISTS idx_switches_system
ON switches USING btree (
system ASC NULL S LAST
) INCLUDE ( " timestamp " ) ;
2019-07-09 18:39:29 +00:00
create table if not exists switch_members
(
id serial primary key ,
switch serial not null references switches ( id ) on delete cascade ,
member serial not null references members ( id ) on delete cascade
) ;
2019-10-05 20:30:55 +00:00
CREATE INDEX IF NOT EXISTS idx_switch_members_switch
ON switch_members USING btree (
switch ASC NULL S LAST
) INCLUDE ( member ) ;
2019-07-09 18:39:29 +00:00
2019-12-21 20:42:34 +00:00
create index if not exists idx_message_member on messages ( member ) ;
2019-07-09 18:39:29 +00:00
create table if not exists webhooks
(
channel bigint primary key ,
webhook bigint not null ,
token text not null
) ;
create table if not exists servers
(
2019-11-03 18:15:50 +00:00
id bigint primary key ,
log_channel bigint ,
log_blacklist bigint [ ] not null default array [ ] : : bigint [ ] ,
blacklist bigint [ ] not null default array [ ] : : bigint [ ]
2019-07-09 18:39:29 +00:00
) ;