2022-02-03 10:32:03 +03:00
|
|
|
-- user
|
|
|
|
CREATE TABLE user (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-05-15 05:57:54 +03:00
|
|
|
email TEXT NOT NULL,
|
|
|
|
role TEXT NOT NULL CHECK (role IN ('OWNER', '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-02-03 10:32:03 +03:00
|
|
|
open_id TEXT NOT NULL,
|
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
2022-05-15 05:57:54 +03:00
|
|
|
UNIQUE(`email`, `open_id`)
|
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,
|
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
2022-05-02 05:57:20 +03:00
|
|
|
-- allowed row status are 'NORMAL', 'ARCHIVED', 'HIDDEN'.
|
2022-02-03 10:32:03 +03:00
|
|
|
row_status TEXT NOT NULL DEFAULT 'NORMAL',
|
|
|
|
content TEXT NOT NULL DEFAULT '',
|
|
|
|
creator_id INTEGER NOT NULL,
|
|
|
|
FOREIGN KEY(creator_id) REFERENCES users(id)
|
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO
|
|
|
|
sqlite_sequence (name, seq)
|
|
|
|
VALUES
|
|
|
|
('memo', 100);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
-- shortcut
|
|
|
|
CREATE TABLE shortcut (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
|
|
|
|
title TEXT NOT NULL DEFAULT '',
|
2022-05-03 06:49:10 +03:00
|
|
|
payload TEXT NOT NULL DEFAULT '{}',
|
2022-02-03 10:32:03 +03:00
|
|
|
creator_id INTEGER NOT NULL,
|
2022-05-02 05:57:20 +03:00
|
|
|
-- allowed row status are 'NORMAL', 'ARCHIVED'.
|
2022-02-04 11:51:48 +03:00
|
|
|
row_status TEXT NOT NULL DEFAULT 'NORMAL',
|
2022-02-03 10:32:03 +03:00
|
|
|
FOREIGN KEY(creator_id) REFERENCES users(id)
|
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO
|
|
|
|
sqlite_sequence (name, seq)
|
|
|
|
VALUES
|
2022-02-05 06:43:25 +03:00
|
|
|
('shortcut', 100);
|
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,
|
|
|
|
filename TEXT NOT NULL DEFAULT '',
|
|
|
|
blob BLOB NOT NULL,
|
|
|
|
type TEXT NOT NULL DEFAULT '',
|
|
|
|
size INTEGER NOT NULL DEFAULT 0,
|
|
|
|
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
|
|
creator_id INTEGER NOT NULL,
|
|
|
|
FOREIGN KEY(creator_id) REFERENCES users(id)
|
|
|
|
);
|
|
|
|
|
2022-02-05 06:43:25 +03:00
|
|
|
INSERT INTO
|
|
|
|
sqlite_sequence (name, seq)
|
|
|
|
VALUES
|
|
|
|
('resource', 100);
|
|
|
|
|
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;
|