-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
executable file
·52 lines (48 loc) · 2.26 KB
/
Copy pathschema.sql
File metadata and controls
executable file
·52 lines (48 loc) · 2.26 KB
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
-- finally.help — Cloudflare D1 schema
-- Apply locally: wrangler d1 execute finally-help-db --local --file=schema.sql
-- Apply to prod: wrangler d1 execute finally-help-db --remote --file=schema.sql
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
username TEXT UNIQUE NOT NULL, -- lowercased, used for login + uniqueness
display TEXT NOT NULL, -- what the user typed (original case)
pass_salt TEXT NOT NULL,
pass_hash TEXT NOT NULL,
xp INTEGER NOT NULL DEFAULT 0,
bulbs INTEGER NOT NULL DEFAULT 20,
avatar TEXT NOT NULL DEFAULT '🙂',
inventory TEXT NOT NULL DEFAULT '{"boosts":{"double":0,"freeze":0,"hint":0},"avatars":["🙂"],"themes":["paper"],"theme":"paper","flairGold":false,"pet":false}',
read_ids TEXT NOT NULL DEFAULT '[]', -- JSON array of explainer ids the user has claimed
streak_count INTEGER NOT NULL DEFAULT 0,
streak_last TEXT, -- YYYY-MM-DD
comment_day TEXT, -- YYYY-MM-DD for daily comment-reward cap
comment_n INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS sessions (
token_hash TEXT PRIMARY KEY, -- sha256(cookie token)
user_id TEXT NOT NULL,
expires_at INTEGER NOT NULL, -- epoch ms
created_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(user_id);
CREATE TABLE IF NOT EXISTS explainers (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
title TEXT NOT NULL,
teaser TEXT,
body TEXT NOT NULL,
created_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_explainers_user ON explainers(user_id);
CREATE TABLE IF NOT EXISTS comments (
id TEXT PRIMARY KEY,
subject TEXT NOT NULL, -- explainer id / topic key the comment belongs to
user_id TEXT NOT NULL,
display TEXT NOT NULL,
avatar TEXT,
flair TEXT,
text TEXT NOT NULL,
reacts TEXT NOT NULL DEFAULT '{}', -- JSON: { "👍": ["username", ...], ... }
created_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_comments_subject ON comments(subject);