-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
43 lines (37 loc) · 1.03 KB
/
Copy pathschema.sql
File metadata and controls
43 lines (37 loc) · 1.03 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
-- D1 Database Schema for Cap CF
-- Keys table
CREATE TABLE IF NOT EXISTS keys (
site_key TEXT PRIMARY KEY,
name TEXT NOT NULL,
secret_hash TEXT NOT NULL,
jwt_secret TEXT NOT NULL,
config TEXT NOT NULL, -- JSON string
created_at INTEGER NOT NULL DEFAULT (unixepoch())
);
-- Sessions table
CREATE TABLE IF NOT EXISTS sessions (
hash TEXT PRIMARY KEY,
data TEXT NOT NULL, -- JSON string {created, expires}
expires_at INTEGER NOT NULL
);
-- API Keys table
CREATE TABLE IF NOT EXISTS api_keys (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
token_hash TEXT NOT NULL,
created_at INTEGER NOT NULL DEFAULT (unixepoch())
);
-- Settings table
CREATE TABLE IF NOT EXISTS settings (
key TEXT PRIMARY KEY,
value TEXT NOT NULL
);
-- Index for cleanup
CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expires_at);
-- Cache table (used when CACHE_BACKEND=d1)
CREATE TABLE IF NOT EXISTS cache (
key TEXT PRIMARY KEY,
value TEXT NOT NULL,
expires_at INTEGER
);
CREATE INDEX IF NOT EXISTS idx_cache_expires ON cache(expires_at);