2022-07-02 05:47:16 +03:00
|
|
|
-- drop all tables
|
2022-09-21 14:34:54 +03:00
|
|
|
DROP TABLE IF EXISTS `system_setting`;
|
|
|
|
DROP TABLE IF EXISTS `memo_resource`;
|
2022-07-02 05:47:16 +03:00
|
|
|
DROP TABLE IF EXISTS `memo_organizer`;
|
|
|
|
DROP TABLE IF EXISTS `memo`;
|
|
|
|
DROP TABLE IF EXISTS `shortcut`;
|
|
|
|
DROP TABLE IF EXISTS `resource`;
|
2022-08-13 09:35:33 +03:00
|
|
|
DROP TABLE IF EXISTS `user_setting`;
|
2022-07-02 05:47:16 +03:00
|
|
|
DROP TABLE IF EXISTS `user`;
|
|
|
|
|
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-05-16 17:19:39 +03:00
|
|
|
email TEXT NOT NULL UNIQUE,
|
2022-07-08 17:16:18 +03:00
|
|
|
role TEXT NOT NULL CHECK (role IN ('HOST', 'USER')) DEFAULT 'USER',
|
2022-02-03 10:32:03 +03:00
|
|
|
name TEXT NOT NULL,
|
2022-02-06 11:19:20 +03:00
|
|
|
password_hash TEXT NOT NULL,
|
2022-05-17 16:21:13 +03:00
|
|
|
open_id TEXT NOT NULL UNIQUE
|
2022-02-03 10:32:03 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO
|
|
|
|
sqlite_sequence (name, seq)
|
|
|
|
VALUES
|
2022-02-05 06:43:25 +03:00
|
|
|
('user', 100);
|
2022-02-03 10:32:03 +03:00
|
|
|
|
|
|
|
CREATE TRIGGER IF NOT EXISTS `trigger_update_user_modification_time`
|
|
|
|
AFTER
|
|
|
|
UPDATE
|
|
|
|
ON `user` FOR EACH ROW BEGIN
|
|
|
|
UPDATE
|
|
|
|
`user`
|
|
|
|
SET
|
|
|
|
updated_ts = (strftime('%s', 'now'))
|
|
|
|
WHERE
|
|
|
|
rowid = old.rowid;
|
|
|
|
END;
|
|
|
|
|
|
|
|
-- 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-07-24 16:01:56 +03:00
|
|
|
visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED', 'PRIVATE')) DEFAULT 'PRIVATE',
|
2022-05-28 02:43:07 +03:00
|
|
|
FOREIGN KEY(creator_id) REFERENCES user(id) ON DELETE CASCADE
|
2022-02-03 10:32:03 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO
|
|
|
|
sqlite_sequence (name, seq)
|
|
|
|
VALUES
|
2022-07-10 03:15:34 +03:00
|
|
|
('memo', 1000);
|
2022-02-03 10:32:03 +03:00
|
|
|
|
|
|
|
CREATE TRIGGER IF NOT EXISTS `trigger_update_memo_modification_time`
|
|
|
|
AFTER
|
|
|
|
UPDATE
|
|
|
|
ON `memo` FOR EACH ROW BEGIN
|
|
|
|
UPDATE
|
|
|
|
`memo`
|
|
|
|
SET
|
|
|
|
updated_ts = (strftime('%s', 'now'))
|
|
|
|
WHERE
|
|
|
|
rowid = old.rowid;
|
|
|
|
END;
|
|
|
|
|
2022-05-19 13:32:04 +03:00
|
|
|
-- memo_organizer
|
|
|
|
CREATE TABLE memo_organizer (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
memo_id INTEGER NOT NULL,
|
|
|
|
user_id INTEGER NOT NULL,
|
|
|
|
pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0,
|
2022-05-28 02:43:07 +03:00
|
|
|
FOREIGN KEY(memo_id) REFERENCES memo(id) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY(user_id) REFERENCES user(id) ON DELETE CASCADE,
|
2022-05-19 13:32:04 +03:00
|
|
|
UNIQUE(memo_id, user_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO
|
|
|
|
sqlite_sequence (name, seq)
|
|
|
|
VALUES
|
2022-07-10 03:15:34 +03:00
|
|
|
('memo_organizer', 1000);
|
2022-05-19 13:32:04 +03:00
|
|
|
|
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-05-03 06:49:10 +03:00
|
|
|
payload TEXT NOT NULL DEFAULT '{}',
|
2022-05-28 02:43:07 +03:00
|
|
|
FOREIGN KEY(creator_id) REFERENCES user(id) ON DELETE CASCADE
|
2022-02-03 10:32:03 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO
|
|
|
|
sqlite_sequence (name, seq)
|
|
|
|
VALUES
|
2022-07-10 03:15:34 +03:00
|
|
|
('shortcut', 10000);
|
2022-02-03 10:32:03 +03:00
|
|
|
|
|
|
|
CREATE TRIGGER IF NOT EXISTS `trigger_update_shortcut_modification_time`
|
|
|
|
AFTER
|
|
|
|
UPDATE
|
|
|
|
ON `shortcut` FOR EACH ROW BEGIN
|
|
|
|
UPDATE
|
|
|
|
`shortcut`
|
|
|
|
SET
|
|
|
|
updated_ts = (strftime('%s', 'now'))
|
|
|
|
WHERE
|
|
|
|
rowid = old.rowid;
|
|
|
|
END;
|
|
|
|
|
|
|
|
-- 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 '',
|
|
|
|
size INTEGER NOT NULL DEFAULT 0,
|
2022-05-28 02:43:07 +03:00
|
|
|
FOREIGN KEY(creator_id) REFERENCES user(id) ON DELETE CASCADE
|
2022-02-03 10:32:03 +03:00
|
|
|
);
|
|
|
|
|
2022-02-05 06:43:25 +03:00
|
|
|
INSERT INTO
|
|
|
|
sqlite_sequence (name, seq)
|
|
|
|
VALUES
|
2022-07-10 03:15:34 +03:00
|
|
|
('resource', 10000);
|
2022-02-05 06:43:25 +03:00
|
|
|
|
2022-02-03 10:32:03 +03:00
|
|
|
CREATE TRIGGER IF NOT EXISTS `trigger_update_resource_modification_time`
|
|
|
|
AFTER
|
|
|
|
UPDATE
|
|
|
|
ON `resource` FOR EACH ROW BEGIN
|
|
|
|
UPDATE
|
|
|
|
`resource`
|
|
|
|
SET
|
|
|
|
updated_ts = (strftime('%s', 'now'))
|
|
|
|
WHERE
|
|
|
|
rowid = old.rowid;
|
|
|
|
END;
|
2022-08-13 09:35:33 +03:00
|
|
|
|
|
|
|
-- user_setting
|
|
|
|
CREATE TABLE user_setting (
|
|
|
|
user_id INTEGER NOT NULL,
|
|
|
|
key TEXT NOT NULL,
|
|
|
|
value TEXT NOT NULL,
|
2022-10-03 13:47:31 +03:00
|
|
|
FOREIGN KEY(user_id) REFERENCES user(id) ON DELETE CASCADE,
|
|
|
|
UNIQUE(user_id, key)
|
2022-08-13 09:35:33 +03:00
|
|
|
);
|
|
|
|
|
2022-10-03 13:47:31 +03:00
|
|
|
-- memo_resource
|
2022-09-21 14:34:54 +03:00
|
|
|
CREATE TABLE memo_resource (
|
|
|
|
memo_id INTEGER NOT NULL,
|
|
|
|
resource_id INTEGER NOT NULL,
|
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
2022-09-30 15:20:00 +03:00
|
|
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
2022-09-21 14:34:54 +03:00
|
|
|
FOREIGN KEY(memo_id) REFERENCES memo(id) ON DELETE CASCADE,
|
2022-10-03 13:47:31 +03:00
|
|
|
FOREIGN KEY(resource_id) REFERENCES resource(id) ON DELETE CASCADE,
|
|
|
|
UNIQUE(memo_id, resource_id)
|
2022-09-21 14:34:54 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
-- system_setting
|
|
|
|
CREATE TABLE system_setting (
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
value TEXT NOT NULL,
|
2022-10-03 13:47:31 +03:00
|
|
|
description TEXT NOT NULL DEFAULT '',
|
|
|
|
UNIQUE(name)
|
2022-09-21 14:34:54 +03:00
|
|
|
);
|