rusty-bever/migrations/2021-08-20-110251_users-and.../up.sql

45 lines
1.2 KiB
MySQL
Raw Normal View History

2021-08-20 14:06:01 +02:00
-- Users
CREATE TABLE users (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
username varchar(32) UNIQUE NOT NULL,
2021-08-20 14:46:19 +02:00
-- Hashed + salted representation of the username
password text NOT NULL,
-- Wether the user is currently blocked
2021-08-20 16:52:58 +02:00
blocked boolean NOT NULL DEFAULT false
2021-08-20 14:06:01 +02:00
);
-- Permissions that a user can have
CREATE TABLE permissions (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
user_id uuid REFERENCES users (id) NOT NULL,
2021-08-20 16:52:58 +02:00
name varchar(64) NOT NULL,
2021-08-20 14:06:01 +02:00
UNIQUE (user_id, name)
);
2021-08-20 14:46:19 +02:00
2021-08-20 16:52:58 +02:00
-- Security reports (e.g. when a user is blocked)
CREATE TABLE security_reports (
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
-- When the report was made
report_time timestamp NOT NULL DEFAULT now(),
-- What type of report it is
report_type varchar(64) NOT NULL,
-- Contents of the report
content TEXT NOT NULL
);
2021-08-20 14:46:19 +02:00
-- Stores refresh tokens
CREATE TABLE refresh_tokens (
-- This is more efficient than storing the text
token bytea PRIMARY KEY,
-- The user for whom the token was created
user_id uuid NOT NULL REFERENCES users(id),
-- When the token expires
expires_at timestamp NOT NULL,
-- When the token was last used (is NULL until used)
last_used_at timestamp
);