forked from dachan/dach
1
0
Fork 0
dach/database_schematic.pgsql

48 lines
1.2 KiB
PL/PgSQL

CREATE TABLE boards (
board_id VARCHAR(5) PRIMARY KEY,
board_name VARCHAR(32) NOT NULL,
threads_ids INT8[]
);
CREATE TABLE threads (
thread_id SERIAL8 PRIMARY KEY,
thread_name VARCHAR(32),
posts_ids INT[],
is_locked boolean NOT NULL,
is_pinned boolean NOT NULL
options VARCHAR(255)
);
CREATE TABLE media (
media_id VARCHAR(22) PRIMARY KEY -- format: ${thread_id}-${media_number}, len(thread_id) = 20, + "-" + len(media_number) = 1 = 22
);
CREATE TABLE posts (
post_id SERIAL8 PRIMARY KEY,
content TEXT NOT NULL,
media_ids VARCHAR(22)[],
is_root BOOL NOT NULL,
date DATE NOT NULL,
internal_id INT NOT NULL, -- id of the post inside of the thread
user_ip CIDR NOT NULL
);
CREATE TABLE admins (
login VARCHAR(16) PRIMARY KEY,
password_hash CHAR(60) NOT NULL,
privelege_name VARCHAR(16) NOT NULL
);
CREATE TABLE priveleges (
privelege_name VARCHAR(16) PRIMARY KEY,
access_level INT2 NOT NULL
);
CREATE TABLE bans (
ban_id SERIAL8 PRIMARY KEY,
user_ip CIDR NOT NULL,
duration INT8, -- duration in seconds
reason VARCHAR(255),
date DATE NOT NULL,
admin_issued VARCHAR(16) NOT NULL
);