2023-12-03 13:31:29 +08:00
|
|
|
-- migration_history
|
|
|
|
CREATE TABLE migration_history (
|
2023-12-09 12:05:45 +08:00
|
|
|
version TEXT NOT NULL PRIMARY KEY,
|
2023-12-09 23:19:57 +08:00
|
|
|
created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW())
|
2023-12-03 13:31:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- system_setting
|
|
|
|
CREATE TABLE system_setting (
|
2023-12-09 12:05:45 +08:00
|
|
|
name TEXT NOT NULL PRIMARY KEY,
|
2023-12-03 13:31:29 +08:00
|
|
|
value TEXT NOT NULL,
|
|
|
|
description TEXT NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
-- user
|
|
|
|
CREATE TABLE "user" (
|
|
|
|
id SERIAL PRIMARY KEY,
|
2023-12-09 23:19:57 +08:00
|
|
|
created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
|
2023-12-09 12:05:45 +08:00
|
|
|
row_status TEXT NOT NULL DEFAULT 'NORMAL',
|
|
|
|
username TEXT NOT NULL UNIQUE,
|
|
|
|
role TEXT NOT NULL DEFAULT 'USER',
|
|
|
|
email TEXT NOT NULL DEFAULT '',
|
|
|
|
nickname TEXT NOT NULL DEFAULT '',
|
|
|
|
password_hash TEXT NOT NULL,
|
2023-12-03 13:31:29 +08:00
|
|
|
avatar_url TEXT NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
-- user_setting
|
|
|
|
CREATE TABLE user_setting (
|
2023-12-09 12:05:45 +08:00
|
|
|
user_id INTEGER NOT NULL,
|
|
|
|
key TEXT NOT NULL,
|
2023-12-03 13:31:29 +08:00
|
|
|
value TEXT NOT NULL,
|
2023-12-09 12:05:45 +08:00
|
|
|
UNIQUE(user_id, key)
|
2023-12-03 13:31:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- memo
|
|
|
|
CREATE TABLE memo (
|
|
|
|
id SERIAL PRIMARY KEY,
|
2024-01-21 01:23:55 +08:00
|
|
|
resource_name TEXT NOT NULL UNIQUE,
|
2023-12-09 12:05:45 +08:00
|
|
|
creator_id INTEGER NOT NULL,
|
2023-12-09 23:19:57 +08:00
|
|
|
created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
|
2023-12-09 12:05:45 +08:00
|
|
|
row_status TEXT NOT NULL DEFAULT 'NORMAL',
|
2023-12-03 13:31:29 +08:00
|
|
|
content TEXT NOT NULL,
|
2023-12-09 12:05:45 +08:00
|
|
|
visibility TEXT NOT NULL DEFAULT 'PRIVATE'
|
2023-12-03 13:31:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- memo_organizer
|
|
|
|
CREATE TABLE memo_organizer (
|
2023-12-09 12:05:45 +08:00
|
|
|
memo_id INTEGER NOT NULL,
|
|
|
|
user_id INTEGER NOT NULL,
|
|
|
|
pinned INTEGER NOT NULL DEFAULT 0,
|
2023-12-03 13:31:29 +08:00
|
|
|
UNIQUE(memo_id, user_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
-- memo_relation
|
|
|
|
CREATE TABLE memo_relation (
|
2023-12-09 12:05:45 +08:00
|
|
|
memo_id INTEGER NOT NULL,
|
|
|
|
related_memo_id INTEGER NOT NULL,
|
|
|
|
type TEXT NOT NULL,
|
|
|
|
UNIQUE(memo_id, related_memo_id, type)
|
2023-12-03 13:31:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- resource
|
|
|
|
CREATE TABLE resource (
|
|
|
|
id SERIAL PRIMARY KEY,
|
2023-12-09 12:05:45 +08:00
|
|
|
creator_id INTEGER NOT NULL,
|
2023-12-09 23:19:57 +08:00
|
|
|
created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
|
2023-12-03 13:31:29 +08:00
|
|
|
filename TEXT NOT NULL,
|
|
|
|
blob BYTEA,
|
|
|
|
external_link TEXT NOT NULL,
|
2023-12-09 12:05:45 +08:00
|
|
|
type TEXT NOT NULL DEFAULT '',
|
|
|
|
size INTEGER NOT NULL DEFAULT 0,
|
|
|
|
internal_path TEXT NOT NULL DEFAULT '',
|
|
|
|
memo_id INTEGER DEFAULT NULL
|
2023-12-03 13:31:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- tag
|
|
|
|
CREATE TABLE tag (
|
2023-12-09 12:05:45 +08:00
|
|
|
name TEXT NOT NULL,
|
|
|
|
creator_id INTEGER NOT NULL,
|
2023-12-03 13:31:29 +08:00
|
|
|
UNIQUE(name, creator_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
-- activity
|
|
|
|
CREATE TABLE activity (
|
|
|
|
id SERIAL PRIMARY KEY,
|
2023-12-09 12:05:45 +08:00
|
|
|
creator_id INTEGER NOT NULL,
|
2023-12-09 23:19:57 +08:00
|
|
|
created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
|
2023-12-09 12:05:45 +08:00
|
|
|
type TEXT NOT NULL DEFAULT '',
|
|
|
|
level TEXT NOT NULL DEFAULT 'INFO',
|
|
|
|
payload JSONB NOT NULL DEFAULT '{}'
|
2023-12-03 13:31:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- storage
|
|
|
|
CREATE TABLE storage (
|
|
|
|
id SERIAL PRIMARY KEY,
|
2023-12-09 12:05:45 +08:00
|
|
|
name TEXT NOT NULL,
|
|
|
|
type TEXT NOT NULL,
|
|
|
|
config JSONB NOT NULL DEFAULT '{}'
|
2023-12-03 13:31:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- idp
|
|
|
|
CREATE TABLE idp (
|
|
|
|
id SERIAL PRIMARY KEY,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
type TEXT NOT NULL,
|
2023-12-09 12:05:45 +08:00
|
|
|
identifier_filter TEXT NOT NULL DEFAULT '',
|
|
|
|
config JSONB NOT NULL DEFAULT '{}'
|
2023-12-03 13:31:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- inbox
|
|
|
|
CREATE TABLE inbox (
|
|
|
|
id SERIAL PRIMARY KEY,
|
2023-12-09 23:19:57 +08:00
|
|
|
created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
|
2023-12-09 12:05:45 +08:00
|
|
|
sender_id INTEGER NOT NULL,
|
|
|
|
receiver_id INTEGER NOT NULL,
|
2023-12-03 13:31:29 +08:00
|
|
|
status TEXT NOT NULL,
|
|
|
|
message TEXT NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
-- webhook
|
|
|
|
CREATE TABLE webhook (
|
|
|
|
id SERIAL PRIMARY KEY,
|
2023-12-09 23:19:57 +08:00
|
|
|
created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
|
2023-12-03 13:31:29 +08:00
|
|
|
row_status TEXT NOT NULL DEFAULT 'NORMAL',
|
2023-12-09 12:05:45 +08:00
|
|
|
creator_id INTEGER NOT NULL,
|
2023-12-03 13:31:29 +08:00
|
|
|
name TEXT NOT NULL,
|
|
|
|
url TEXT NOT NULL
|
2023-12-09 12:05:45 +08:00
|
|
|
);
|