2022-05-02 17:19:37 +02:00
|
|
|
-- 2022-05-02: initial schema
|
|
|
|
|
2023-08-16 03:30:34 +02:00
|
|
|
-- +migrate Up
|
|
|
|
|
2022-05-02 17:19:37 +02:00
|
|
|
create table users (
|
|
|
|
id text primary key,
|
|
|
|
username text not null unique,
|
|
|
|
display_name text,
|
|
|
|
bio text,
|
|
|
|
|
2022-09-20 14:12:29 +02:00
|
|
|
avatar_urls text[],
|
|
|
|
links text[],
|
2022-05-02 17:19:37 +02:00
|
|
|
|
2022-05-04 16:27:16 +02:00
|
|
|
discord text unique, -- for Discord oauth
|
2022-11-18 15:27:52 +01:00
|
|
|
discord_username text,
|
|
|
|
|
2023-01-04 22:41:29 +01:00
|
|
|
max_invites int not null default 10
|
2022-05-02 17:19:37 +02:00
|
|
|
);
|
|
|
|
|
2022-09-06 23:24:06 +02:00
|
|
|
create table user_names (
|
|
|
|
user_id text not null references users (id) on delete cascade,
|
|
|
|
id bigserial primary key, -- ID is used for sorting; when order changes, existing rows are deleted and new ones are created
|
|
|
|
name text not null,
|
|
|
|
status int not null
|
2022-09-20 12:55:00 +02:00
|
|
|
);
|
2022-09-06 23:24:06 +02:00
|
|
|
|
|
|
|
create table user_pronouns (
|
|
|
|
user_id text not null references users (id) on delete cascade,
|
|
|
|
id bigserial primary key,
|
|
|
|
display_text text, -- if unset, falls back to first 2 parts of pronouns
|
|
|
|
pronouns text not null,
|
|
|
|
status int not null
|
|
|
|
);
|
|
|
|
|
2022-05-02 17:19:37 +02:00
|
|
|
create table user_fields (
|
|
|
|
user_id text not null references users (id) on delete cascade,
|
|
|
|
id bigserial primary key,
|
|
|
|
name text not null,
|
|
|
|
|
2022-09-20 14:12:29 +02:00
|
|
|
favourite text[],
|
|
|
|
okay text[],
|
|
|
|
jokingly text[],
|
|
|
|
friends_only text[],
|
|
|
|
avoid text[]
|
2022-05-02 17:19:37 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
create table members (
|
|
|
|
id text primary key,
|
|
|
|
user_id text not null references users (id) on delete cascade,
|
|
|
|
name text not null,
|
|
|
|
bio text,
|
|
|
|
|
2022-09-20 14:12:29 +02:00
|
|
|
avatar_urls text[],
|
|
|
|
links text[]
|
2022-05-02 17:19:37 +02:00
|
|
|
);
|
|
|
|
|
2022-10-03 10:59:30 +02:00
|
|
|
create unique index members_user_name_idx on members (user_id, lower(name));
|
|
|
|
|
2022-09-06 23:24:06 +02:00
|
|
|
create table member_names (
|
|
|
|
member_id text not null references members (id) on delete cascade,
|
|
|
|
id bigserial primary key, -- ID is used for sorting; when order changes, existing rows are deleted and new ones are created
|
|
|
|
name text not null,
|
|
|
|
status int not null
|
2022-09-20 12:55:00 +02:00
|
|
|
);
|
2022-09-06 23:24:06 +02:00
|
|
|
|
|
|
|
create table member_pronouns (
|
|
|
|
member_id text not null references members (id) on delete cascade,
|
|
|
|
id bigserial primary key,
|
|
|
|
display_text text, -- if unset, falls back to first 2 parts of pronouns
|
|
|
|
pronouns text not null,
|
|
|
|
status int not null
|
|
|
|
);
|
|
|
|
|
2022-05-02 17:19:37 +02:00
|
|
|
create table member_fields (
|
|
|
|
member_id text not null references members (id) on delete cascade,
|
|
|
|
id bigserial primary key,
|
|
|
|
name text not null,
|
|
|
|
|
2022-09-20 14:12:29 +02:00
|
|
|
favourite text[],
|
|
|
|
okay text[],
|
|
|
|
jokingly text[],
|
|
|
|
friends_only text[],
|
|
|
|
avoid text[]
|
2022-05-02 17:19:37 +02:00
|
|
|
);
|
2022-11-18 15:27:52 +01:00
|
|
|
|
|
|
|
create table invites (
|
|
|
|
user_id text not null references users (id) on delete cascade,
|
|
|
|
code text primary key,
|
|
|
|
created timestamp not null default (current_timestamp at time zone 'utc'),
|
|
|
|
used boolean not null default false
|
|
|
|
);
|
2023-08-16 03:30:34 +02:00
|
|
|
|
|
|
|
-- +migrate Down
|
|
|
|
|
|
|
|
drop table invites;
|
|
|
|
drop table member_fields;
|
|
|
|
drop table member_pronouns;
|
|
|
|
drop table member_names;
|
|
|
|
drop index members_user_name_idx;
|
|
|
|
drop table members;
|
|
|
|
drop table user_fields;
|
|
|
|
drop table user_pronouns;
|
|
|
|
drop table user_names;
|
|
|
|
drop table users;
|