holey-bytes/depell/src/schema.sql

56 lines
1.3 KiB
MySQL
Raw Normal View History

2024-10-08 17:17:13 -05:00
PRAGMA foreign_keys = ON;
CREATE TABLE IF NOT EXISTS user(
name TEXT NOT NULL,
password_hash TEXT NOT NULL,
PRIMARY KEY (name)
) WITHOUT ROWID;
CREATE TABLE IF NOT EXISTS session(
id BLOB NOT NULL,
username TEXT NOT NULL,
expiration INTEGER NOT NULL,
FOREIGN KEY (username) REFERENCES user (name)
PRIMARY KEY (username)
) WITHOUT ROWID;
CREATE UNIQUE INDEX IF NOT EXISTS
session_id ON session (id);
CREATE TABLE IF NOT EXISTS post(
name TEXT NOT NULL,
author TEXT,
timestamp INTEGER,
code TEXT NOT NULL,
2024-10-14 15:04:18 -05:00
FOREIGN KEY (author) REFERENCES user(name) ON DELETE SET NULL,
2024-10-08 17:17:13 -05:00
PRIMARY KEY (author, name)
);
2024-10-14 15:04:18 -05:00
CREATE INDEX IF NOT EXISTS
post_timestamp ON post(timestamp DESC);
2024-10-08 17:17:13 -05:00
CREATE TABLE IF NOT EXISTS import(
from_name TEXT NOT NULL,
from_author TEXT,
to_name TEXT NOT NULL,
to_author TEXT,
2024-10-14 15:04:18 -05:00
FOREIGN KEY (from_name, from_author) REFERENCES post(name, author),
FOREIGN KEY (to_name, to_author) REFERENCES post(name, author)
2024-10-08 17:17:13 -05:00
);
CREATE INDEX IF NOT EXISTS
dependencies ON import(from_name, from_author);
CREATE INDEX IF NOT EXISTS
dependants ON import(to_name, to_author);
CREATE TABLE IF NOT EXISTS run(
code_name TEXT NOT NULL,
code_author TEXT NOT NULL,
runner TEXT NOT NULL,
2024-10-14 15:04:18 -05:00
FOREIGN KEY (code_name, code_author) REFERENCES post(name, author),
2024-10-08 17:17:13 -05:00
FOREIGN KEY (runner) REFERENCES user(name),
PRIMARY KEY (code_name, code_author, runner)
);
2024-10-14 06:25:38 -05:00