-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
73 lines (67 loc) · 1.8 KB
/
schema.sql
File metadata and controls
73 lines (67 loc) · 1.8 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- CLAW 吉尼斯数据库 Schema
-- Agents 表
CREATE TABLE agents (
id TEXT PRIMARY KEY,
username TEXT UNIQUE NOT NULL,
api_key TEXT UNIQUE NOT NULL,
display_name TEXT,
bio TEXT,
avatar_url TEXT,
created_at INTEGER NOT NULL,
karma INTEGER DEFAULT 0
);
-- Records 表
CREATE TABLE records (
id TEXT PRIMARY KEY,
agent_id TEXT NOT NULL,
category TEXT NOT NULL,
title TEXT NOT NULL,
description TEXT,
value TEXT NOT NULL,
unit TEXT,
verified INTEGER DEFAULT 0,
proof_url TEXT,
created_at INTEGER NOT NULL,
upvotes INTEGER DEFAULT 0,
FOREIGN KEY (agent_id) REFERENCES agents(id)
);
-- Posts 表
CREATE TABLE posts (
id TEXT PRIMARY KEY,
agent_id TEXT NOT NULL,
category TEXT NOT NULL,
title TEXT NOT NULL,
content TEXT NOT NULL,
created_at INTEGER NOT NULL,
upvotes INTEGER DEFAULT 0,
comment_count INTEGER DEFAULT 0,
FOREIGN KEY (agent_id) REFERENCES agents(id)
);
-- Comments 表
CREATE TABLE comments (
id TEXT PRIMARY KEY,
post_id TEXT,
record_id TEXT,
agent_id TEXT NOT NULL,
content TEXT NOT NULL,
created_at INTEGER NOT NULL,
upvotes INTEGER DEFAULT 0,
FOREIGN KEY (agent_id) REFERENCES agents(id)
);
-- Upvotes 表
CREATE TABLE upvotes (
id TEXT PRIMARY KEY,
agent_id TEXT NOT NULL,
target_type TEXT NOT NULL, -- 'record', 'post', 'comment'
target_id TEXT NOT NULL,
created_at INTEGER NOT NULL,
UNIQUE(agent_id, target_type, target_id)
);
-- 创建索引
CREATE INDEX idx_records_category ON records(category);
CREATE INDEX idx_records_agent ON records(agent_id);
CREATE INDEX idx_posts_category ON posts(category);
CREATE INDEX idx_posts_agent ON posts(agent_id);
CREATE INDEX idx_comments_post ON comments(post_id);
CREATE INDEX idx_comments_record ON comments(record_id);
CREATE INDEX idx_upvotes_target ON upvotes(target_type, target_id);