nim/sql/schema.sql
2025-06-01 21:20:08 +08:00

37 lines
1 KiB
SQL

CREATE TYPE post_phase AS ENUM('pending', 'rejected', 'admin_rejected','ok', 'deleted');
CREATE TABLE posts (
id serial PRIMARY KEY,
content varchar(200) not null,
signing varchar(20),
hash char(64) UNIQUE NOT NULL,
post_at timestamp with time zone DEFAULT now(),
heart integer NOT NULL DEFAULT 0,
phase post_phase NOT NULL DEFAULT 'pending',
igid varchar(22)
);
CREATE TABLE comment (
id serial PRIMARY KEY,
post_id integer not null REFERENCES posts (id),
content varchar(200) not null,
signing varchar(20),
hash char(64) UNIQUE NOT NULL,
post_at timestamp with time zone DEFAULT now(),
heart integer NOT NULL DEFAULT 0
);
CREATE TABLE media (
url varchar(59) NOT NULL UNIQUE,
post_id integer REFERENCES posts (id),
comment_id integer REFERENCES comment (id),
visible boolean DEFAULT false,
CONSTRAINT uni_id CHECK ((post_id IS NULL) <> (comment_id IS NULL))
);
CREATE TABLE admin (
username varchar(20) NOT NULL UNIQUE PRIMARY KEY,
password char(45) NOT NULL,
totp char(33) NOT NULL,
super bool NOT NULL DEFAULT false
);