Voyage/voyage.sql
2020-01-20 13:18:47 -05:00

36 lines
905 B
SQL

CREATE TABLE IF NOT EXISTS thread (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
time TIMESTAMP WITH TIME ZONE NOT NULL
);
CREATE TABLE IF NOT EXISTS post (
thread_id INTEGER REFERENCES thread(id) ON DELETE CASCADE NOT NULL,
id INTEGER PRIMARY KEY,
subject TEXT,
name TEXT NOT NULL,
email TEXT,
tripcode TEXT,
user_id TEXT,
time TIMESTAMP WITH TIME ZONE NOT NULL,
body TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS link (
link_from INTEGER REFERENCES post(id) ON DELETE CASCADE NOT NULL,
link_to INTEGER REFERENCES post(id) ON DELETE CASCADE NOT NULL,
PRIMARY KEY (link_from, link_to)
);
CREATE TABLE IF NOT EXISTS tag (
post_id INTEGER REFERENCES post(id) ON DELETE CASCADE NOT NULL,
name TEXT NOT NULL,
PRIMARY KEY (post_id, name)
);
CREATE TABLE IF NOT EXISTS file (
post_id INTEGER REFERENCES post(id) ON DELETE CASCADE NOT NULL,
chan_file_name TEXT,
original_file_name TEXT
);