experiments in a post-browser web
1-- Generated by schema/codegen.js
2-- Schema version: 1
3-- DO NOT EDIT - regenerate with: yarn schema:codegen
4
5-- Unified content storage - URLs, text notes, tagsets, and images
6CREATE TABLE IF NOT EXISTS items (
7 id TEXT PRIMARY KEY NOT NULL,
8 type TEXT NOT NULL CHECK(type IN ('url', 'text', 'tagset', 'image', 'series', 'feed')),
9 content TEXT,
10 mimeType TEXT DEFAULT '',
11 metadata TEXT DEFAULT '{}',
12 syncId TEXT DEFAULT '',
13 syncSource TEXT DEFAULT '',
14 syncedAt INTEGER DEFAULT 0,
15 createdAt INTEGER NOT NULL,
16 updatedAt INTEGER NOT NULL,
17 deletedAt INTEGER DEFAULT 0,
18 starred INTEGER DEFAULT 0,
19 archived INTEGER DEFAULT 0,
20 visitCount INTEGER DEFAULT 0,
21 lastVisitAt INTEGER DEFAULT 0,
22 frecencyScore INTEGER DEFAULT 0,
23 title TEXT DEFAULT '',
24 domain TEXT DEFAULT '',
25 favicon TEXT DEFAULT ''
26);
27
28CREATE INDEX IF NOT EXISTS idx_items_type ON items(type);
29CREATE INDEX IF NOT EXISTS idx_items_syncId ON items(syncId);
30CREATE INDEX IF NOT EXISTS idx_items_deletedAt ON items(deletedAt);
31CREATE INDEX IF NOT EXISTS idx_items_createdAt ON items(createdAt DESC);
32CREATE INDEX IF NOT EXISTS idx_items_starred ON items(starred);
33CREATE INDEX IF NOT EXISTS idx_items_lastVisitAt ON items(lastVisitAt);
34CREATE INDEX IF NOT EXISTS idx_items_visitCount ON items(visitCount);
35CREATE INDEX IF NOT EXISTS idx_items_frecencyScore ON items(frecencyScore DESC);
36CREATE INDEX IF NOT EXISTS idx_items_domain ON items(domain);
37
38-- Tag definitions with frecency tracking
39CREATE TABLE IF NOT EXISTS tags (
40 id TEXT PRIMARY KEY NOT NULL,
41 name TEXT NOT NULL UNIQUE,
42 frequency INTEGER DEFAULT 1,
43 lastUsed INTEGER NOT NULL,
44 frecencyScore REAL DEFAULT 0.0,
45 createdAt INTEGER NOT NULL,
46 updatedAt INTEGER NOT NULL,
47 slug TEXT,
48 color TEXT DEFAULT '#999999',
49 parentId TEXT DEFAULT '',
50 description TEXT DEFAULT '',
51 metadata TEXT DEFAULT '{}'
52);
53
54CREATE INDEX IF NOT EXISTS idx_tags_name ON tags(name);
55CREATE INDEX IF NOT EXISTS idx_tags_frecency ON tags(frecencyScore DESC);
56CREATE INDEX IF NOT EXISTS idx_tags_slug ON tags(slug);
57CREATE INDEX IF NOT EXISTS idx_tags_parentId ON tags(parentId);
58
59-- Junction table linking items to tags
60CREATE TABLE IF NOT EXISTS item_tags (
61 id TEXT PRIMARY KEY NOT NULL,
62 itemId TEXT NOT NULL,
63 tagId TEXT NOT NULL,
64 createdAt INTEGER NOT NULL
65);
66
67CREATE INDEX IF NOT EXISTS idx_item_tags_itemId ON item_tags(itemId);
68CREATE INDEX IF NOT EXISTS idx_item_tags_tagId ON item_tags(tagId);
69CREATE UNIQUE INDEX IF NOT EXISTS idx_item_tags_unique ON item_tags(itemId, tagId);
70
71-- Events/entries for series and feeds - append-only time-series data
72CREATE TABLE IF NOT EXISTS item_events (
73 id TEXT PRIMARY KEY NOT NULL,
74 itemId TEXT NOT NULL,
75 content TEXT,
76 value REAL,
77 occurredAt INTEGER NOT NULL,
78 metadata TEXT DEFAULT '{}',
79 createdAt INTEGER NOT NULL
80);
81
82CREATE INDEX IF NOT EXISTS idx_item_events_item_time ON item_events(itemId, occurredAt DESC);
83CREATE INDEX IF NOT EXISTS idx_item_events_occurred ON item_events(occurredAt DESC);