2022-11-25 17:17:24 +03:00
|
|
|
-- migration_history
|
|
|
|
CREATE TABLE migration_history (
|
|
|
|
version TEXT NOT NULL PRIMARY KEY,
|
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now'))
|
|
|
|
);
|
|
|
|
|
|
|
|
-- system_setting
|
|
|
|
CREATE TABLE system_setting (
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
value TEXT NOT NULL,
|
|
|
|
description TEXT NOT NULL DEFAULT '',
|
|
|
|
UNIQUE(name)
|
|
|
|
);
|
|
|
|
|
2022-02-03 10:32:03 +03:00
|
|
|
-- user
|
|
|
|
CREATE TABLE user (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-05-17 16:21:13 +03:00
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
2022-05-19 13:32:04 +03:00
|
|
|
row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',
|
2022-11-25 17:17:24 +03:00
|
|
|
username TEXT NOT NULL UNIQUE,
|
|
|
|
role TEXT NOT NULL CHECK (role IN ('HOST', 'ADMIN', 'USER')) DEFAULT 'USER',
|
|
|
|
email TEXT NOT NULL DEFAULT '',
|
|
|
|
nickname TEXT NOT NULL DEFAULT '',
|
2022-02-06 11:19:20 +03:00
|
|
|
password_hash TEXT NOT NULL,
|
2023-02-24 03:31:54 +03:00
|
|
|
avatar_url TEXT NOT NULL DEFAULT ''
|
2022-02-03 10:32:03 +03:00
|
|
|
);
|
|
|
|
|
2023-07-15 05:26:31 +03:00
|
|
|
CREATE INDEX idx_user_username ON user (username);
|
|
|
|
|
2022-11-25 17:17:24 +03:00
|
|
|
-- user_setting
|
|
|
|
CREATE TABLE user_setting (
|
|
|
|
user_id INTEGER NOT NULL,
|
|
|
|
key TEXT NOT NULL,
|
|
|
|
value TEXT NOT NULL,
|
|
|
|
UNIQUE(user_id, key)
|
|
|
|
);
|
|
|
|
|
2022-02-03 10:32:03 +03:00
|
|
|
-- memo
|
|
|
|
CREATE TABLE memo (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-05-17 16:21:13 +03:00
|
|
|
creator_id INTEGER NOT NULL,
|
2022-02-03 10:32:03 +03:00
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
2022-05-19 13:32:04 +03:00
|
|
|
row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',
|
2022-02-03 10:32:03 +03:00
|
|
|
content TEXT NOT NULL DEFAULT '',
|
2022-10-26 18:00:09 +03:00
|
|
|
visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED', 'PRIVATE')) DEFAULT 'PRIVATE'
|
2022-02-03 10:32:03 +03:00
|
|
|
);
|
|
|
|
|
2023-07-15 05:26:31 +03:00
|
|
|
CREATE INDEX idx_memo_creator_id ON memo (creator_id);
|
|
|
|
CREATE INDEX idx_memo_content ON memo (content);
|
|
|
|
CREATE INDEX idx_memo_visibility ON memo (visibility);
|
|
|
|
|
2022-05-19 13:32:04 +03:00
|
|
|
-- memo_organizer
|
|
|
|
CREATE TABLE memo_organizer (
|
|
|
|
memo_id INTEGER NOT NULL,
|
|
|
|
user_id INTEGER NOT NULL,
|
|
|
|
pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0,
|
|
|
|
UNIQUE(memo_id, user_id)
|
|
|
|
);
|
|
|
|
|
2022-02-03 10:32:03 +03:00
|
|
|
-- shortcut
|
|
|
|
CREATE TABLE shortcut (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-05-17 16:21:13 +03:00
|
|
|
creator_id INTEGER NOT NULL,
|
2022-02-03 10:32:03 +03:00
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
2022-05-19 13:32:04 +03:00
|
|
|
row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL',
|
2022-02-03 10:32:03 +03:00
|
|
|
title TEXT NOT NULL DEFAULT '',
|
2022-10-26 18:00:09 +03:00
|
|
|
payload TEXT NOT NULL DEFAULT '{}'
|
2022-02-03 10:32:03 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
-- resource
|
|
|
|
CREATE TABLE resource (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-05-17 16:21:13 +03:00
|
|
|
creator_id INTEGER NOT NULL,
|
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
2022-02-03 10:32:03 +03:00
|
|
|
filename TEXT NOT NULL DEFAULT '',
|
2022-10-03 13:47:31 +03:00
|
|
|
blob BLOB DEFAULT NULL,
|
|
|
|
external_link TEXT NOT NULL DEFAULT '',
|
2022-02-03 10:32:03 +03:00
|
|
|
type TEXT NOT NULL DEFAULT '',
|
2023-04-03 09:13:22 +03:00
|
|
|
size INTEGER NOT NULL DEFAULT 0,
|
2023-07-08 06:29:50 +03:00
|
|
|
internal_path TEXT NOT NULL DEFAULT ''
|
2022-02-03 10:32:03 +03:00
|
|
|
);
|
|
|
|
|
2023-07-15 05:26:31 +03:00
|
|
|
CREATE INDEX idx_resource_creator_id ON resource (creator_id);
|
|
|
|
|
2022-10-03 13:47:31 +03:00
|
|
|
-- memo_resource
|
|
|
|
CREATE TABLE memo_resource (
|
|
|
|
memo_id INTEGER NOT NULL,
|
|
|
|
resource_id INTEGER NOT NULL,
|
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
UNIQUE(memo_id, resource_id)
|
2022-08-20 06:36:24 +03:00
|
|
|
);
|
2022-12-23 14:49:55 +03:00
|
|
|
|
|
|
|
-- tag
|
|
|
|
CREATE TABLE tag (
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
creator_id INTEGER NOT NULL,
|
|
|
|
UNIQUE(name, creator_id)
|
|
|
|
);
|
2023-01-07 05:51:34 +03:00
|
|
|
|
|
|
|
-- activity
|
|
|
|
CREATE TABLE activity (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
creator_id INTEGER NOT NULL,
|
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
type TEXT NOT NULL DEFAULT '',
|
|
|
|
level TEXT NOT NULL CHECK (level IN ('INFO', 'WARN', 'ERROR')) DEFAULT 'INFO',
|
|
|
|
payload TEXT NOT NULL DEFAULT '{}'
|
2023-02-24 03:31:54 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
-- storage
|
|
|
|
CREATE TABLE storage (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
type TEXT NOT NULL,
|
|
|
|
config TEXT NOT NULL DEFAULT '{}'
|
|
|
|
);
|
|
|
|
|
|
|
|
-- idp
|
|
|
|
CREATE TABLE idp (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
type TEXT NOT NULL,
|
|
|
|
identifier_filter TEXT NOT NULL DEFAULT '',
|
|
|
|
config TEXT NOT NULL DEFAULT '{}'
|
2023-05-20 05:16:19 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
-- memo_relation
|
|
|
|
CREATE TABLE memo_relation (
|
|
|
|
memo_id INTEGER NOT NULL,
|
|
|
|
related_memo_id INTEGER NOT NULL,
|
|
|
|
type TEXT NOT NULL,
|
|
|
|
UNIQUE(memo_id, related_memo_id, type)
|
2023-07-15 05:26:31 +03:00
|
|
|
);
|