puerta/schema.sql

63 lines
1.5 KiB
MySQL
Raw Normal View History

2022-12-30 06:51:51 +00:00
CREATE TABLE user(
id INTEGER PRIMARY KEY AUTOINCREMENT,
handle VARCHAR(255) NOT NULL UNIQUE,
name TEXT NOT NULL,
2022-12-30 06:51:51 +00:00
password TEXT,
expires TEXT, -- datetime
greeting TEXT,
max_ttl TEXT DEFAULT "30d", -- golang auth.TTL
schedule TEXT, -- golang auth.UserSchedule
2022-12-30 06:51:51 +00:00
second_factor BOOLEAN DEFAULT 1,
2023-04-16 21:17:36 +00:00
is_admin BOOLEAN DEFAULT 0 NOT NULL,
receives_notifications BOOLEAN DEFAULT 0 NOT NULL
2022-12-30 06:51:51 +00:00
);
CREATE INDEX user_id ON user(id);
CREATE INDEX user_handle ON user(handle);
2022-12-30 06:51:51 +00:00
CREATE TABLE credential(
user INTEGER NOT NULL,
data TEXT NOT NULL,
FOREIGN KEY(user) REFERENCES user(id) ON DELETE CASCADE
2022-12-30 06:51:51 +00:00
);
2023-01-04 04:21:49 +00:00
CREATE INDEX credential_user ON credential(user);
2022-12-30 06:51:51 +00:00
CREATE TABLE session(
token TEXT PRIMARY KEY,
user INTEGER NOT NULL,
expires TEXT NOT NULL, -- datetime
FOREIGN KEY(user) REFERENCES user(id) ON DELETE CASCADE
);
CREATE INDEX session_token ON session(token);
CREATE TABLE log(
timestamp TEXT PRIMARY KEY,
user TEXT NOT NULL,
second_factor BOOLEAN NOT NULL,
failure VARCHAR(255),
error TEXT,
ip_address varchar(255) NOT NULL,
user_agent varchar(255) NOT NULL
2022-12-30 06:51:51 +00:00
);
2023-04-16 21:17:36 +00:00
CREATE TABLE subscription(
user INTEGER NOT NULL,
data TEXT NOT NULL,
FOREIGN KEY(user) REFERENCES user(id) ON DELETE CASCADE
);
CREATE INDEX subscription_user ON subscription(user);
CREATE INDEX log_timestamp_idx ON log(timestamp);
CREATE INDEX log_timestamp_error_idx ON log(timestamp,error);
CREATE INDEX log_timestamp_user_idx ON log(timestamp,user);
2023-04-16 21:17:36 +00:00
CREATE TABLE migrations (
name TEXT NOT NULL,
applied TEXT NOT NULL
);