-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbntp_sqlite.sql
89 lines (76 loc) · 2.52 KB
/
bntp_sqlite.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
PRAGMA foreign_keys = ON;
-- TODO: It might be worth exploring tables which support caching, ideas below:
/*
CREATE TABLE table_cache_states
(
table_name NOT NULL TEXT PRIMARY KEY,
is_dirty NOT NULL INTEGER
);
CREATE TABLE dirty_entries
(
dirty_rows_pk TEXT NOT NULL PRIMARY KEY,
table_name TEXT NOT NULL
);
*/
CREATE TABLE tags
(
id INTEGER PRIMARY KEY NOT NULL,
tag TEXT NOT NULL,
parent_tag INTEGER REFERENCES tags(id) DEFERRABLE INITIALLY DEFERRED,
-- Stores list of parent ids from root to self
-- e.g. "1;2;3"
path TEXT NOT NULL UNIQUE,
-- Stores lis of children ids
-- e.g. "1;2;3"
children TEXT NOT NULL
);
CREATE TABLE bookmark_types
(
id INTEGER PRIMARY KEY NOT NULL,
bookmark_type TEXT NOT NULL UNIQUE
);
CREATE TABLE bookmarks
(
id INTEGER PRIMARY KEY NOT NULL,
is_read INTEGER NOT NULL DEFAULT 0,
title TEXT UNIQUE,
url TEXT NOT NULL UNIQUE,
bookmark_type_id INTEGER REFERENCES bookmark_types(id) DEFERRABLE INITIALLY DEFERRED,
is_collection INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
deleted_at TIMESTAMP
);
CREATE TABLE document_types
(
id INTEGER PRIMARY KEY NOT NULL,
document_type TEXT NOT NULL UNIQUE
);
CREATE TABLE documents
(
id INTEGER PRIMARY KEY NOT NULL,
path TEXT NOT NULL UNIQUE,
document_type_id INTEGER REFERENCES document_types(id) DEFERRABLE INITIALLY DEFERRED,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
deleted_at TIMESTAMP
);
CREATE TABLE links
(
source_id INTEGER NOT NULL REFERENCES documents(id) DEFERRABLE INITIALLY DEFERRED,
destination_id INTEGER NOT NULL REFERENCES documents(id) DEFERRABLE INITIALLY DEFERRED,
PRIMARY KEY(source_id, destination_id),
CHECK(source_id != destination_id)
);
CREATE TABLE bookmark_contexts
(
bookmark_id INTEGER NOT NULL REFERENCES bookmarks(id) DEFERRABLE INITIALLY DEFERRED,
tag_id INTEGER NOT NULL REFERENCES tags(id) DEFERRABLE INITIALLY DEFERRED,
PRIMARY KEY(tag_id, bookmark_id)
);
CREATE TABLE document_contexts
(
document_id INTEGER NOT NULL REFERENCES documents(id) DEFERRABLE INITIALLY DEFERRED,
tag_id INTEGER NOT NULL REFERENCES tags(id) DEFERRABLE INITIALLY DEFERRED,
PRIMARY KEY(tag_id, document_id)
);