town/sql/create_town_db.sql

35 lines
958 B
MySQL
Raw Permalink Normal View History

2023-02-20 08:43:14 +00:00
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
created TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M', 'now', 'localtime')),
username TEXT UNIQUE,
state TEXT,
2023-03-06 20:34:29 +00:00
admin INTEGER DEFAULT 0
2023-02-20 08:43:14 +00:00
);
2023-03-06 03:04:27 +00:00
-- TODO address /should/ be unique but leaving it duplicable for now since i can think of some cases where there might be >1 account for the same human
2023-02-20 08:43:14 +00:00
CREATE TABLE IF NOT EXISTS emails (
id INTEGER PRIMARY KEY,
2023-03-06 03:04:27 +00:00
address TEXT,
2023-02-20 08:43:14 +00:00
userid INTEGER,
FOREIGN KEY (userid) REFERENCES users(userid)
);
CREATE TABLE IF NOT EXISTS user_notes (
2023-03-06 03:04:27 +00:00
noteid INTEGER,
2023-02-20 08:43:14 +00:00
userid INTEGER,
PRIMARY KEY (noteid, userid),
FOREIGN KEY (noteid) REFERENCES notes(noteid),
FOREIGN KEY (userid) REFERENCES users(userid)
);
CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY,
author INTEGER,
content TEXT,
2023-02-20 08:43:14 +00:00
created TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M', 'now', 'localtime')),
2023-03-06 20:34:29 +00:00
FOREIGN KEY (author) REFERENCES users(author)
2023-02-20 08:43:14 +00:00
);