-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdatabase-schema.js
More file actions
175 lines (150 loc) · 5.87 KB
/
database-schema.js
File metadata and controls
175 lines (150 loc) · 5.87 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import fs from 'fs';
export function initSchema(db) {
db.exec(`
CREATE TABLE IF NOT EXISTS conversations (
id TEXT PRIMARY KEY,
agentId TEXT NOT NULL,
title TEXT,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
status TEXT DEFAULT 'active'
);
CREATE INDEX IF NOT EXISTS idx_conversations_agent ON conversations(agentId);
CREATE INDEX IF NOT EXISTS idx_conversations_updated ON conversations(updated_at DESC);
CREATE TABLE IF NOT EXISTS messages (
id TEXT PRIMARY KEY,
conversationId TEXT NOT NULL,
role TEXT NOT NULL,
content TEXT NOT NULL,
created_at INTEGER NOT NULL,
FOREIGN KEY (conversationId) REFERENCES conversations(id)
);
CREATE INDEX IF NOT EXISTS idx_messages_conversation ON messages(conversationId);
CREATE TABLE IF NOT EXISTS sessions (
id TEXT PRIMARY KEY,
conversationId TEXT NOT NULL,
status TEXT NOT NULL,
started_at INTEGER NOT NULL,
completed_at INTEGER,
response TEXT,
error TEXT,
FOREIGN KEY (conversationId) REFERENCES conversations(id)
);
CREATE INDEX IF NOT EXISTS idx_sessions_conversation ON sessions(conversationId);
CREATE INDEX IF NOT EXISTS idx_sessions_status ON sessions(conversationId, status);
CREATE TABLE IF NOT EXISTS events (
id TEXT PRIMARY KEY,
type TEXT NOT NULL,
conversationId TEXT,
sessionId TEXT,
data TEXT NOT NULL,
created_at INTEGER NOT NULL,
FOREIGN KEY (conversationId) REFERENCES conversations(id),
FOREIGN KEY (sessionId) REFERENCES sessions(id)
);
CREATE INDEX IF NOT EXISTS idx_events_conversation ON events(conversationId);
CREATE TABLE IF NOT EXISTS idempotencyKeys (
key TEXT PRIMARY KEY,
value TEXT NOT NULL,
created_at INTEGER NOT NULL,
ttl INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_idempotency_created ON idempotencyKeys(created_at);
CREATE TABLE IF NOT EXISTS stream_updates (
id TEXT PRIMARY KEY,
sessionId TEXT NOT NULL,
conversationId TEXT NOT NULL,
updateType TEXT NOT NULL,
content TEXT NOT NULL,
sequence INTEGER NOT NULL,
created_at INTEGER NOT NULL,
FOREIGN KEY (sessionId) REFERENCES sessions(id),
FOREIGN KEY (conversationId) REFERENCES conversations(id)
);
CREATE INDEX IF NOT EXISTS idx_stream_updates_session ON stream_updates(sessionId);
CREATE INDEX IF NOT EXISTS idx_stream_updates_created ON stream_updates(created_at);
CREATE TABLE IF NOT EXISTS chunks (
id TEXT PRIMARY KEY,
sessionId TEXT NOT NULL,
conversationId TEXT NOT NULL,
sequence INTEGER NOT NULL,
type TEXT NOT NULL,
data BLOB NOT NULL,
created_at INTEGER NOT NULL,
FOREIGN KEY (sessionId) REFERENCES sessions(id),
FOREIGN KEY (conversationId) REFERENCES conversations(id)
);
CREATE INDEX IF NOT EXISTS idx_chunks_session ON chunks(sessionId, sequence);
CREATE INDEX IF NOT EXISTS idx_chunks_conversation ON chunks(conversationId, sequence);
CREATE UNIQUE INDEX IF NOT EXISTS idx_chunks_unique ON chunks(sessionId, sequence);
CREATE INDEX IF NOT EXISTS idx_chunks_conv_created ON chunks(conversationId, created_at);
CREATE INDEX IF NOT EXISTS idx_chunks_sess_created ON chunks(sessionId, created_at);
CREATE TABLE IF NOT EXISTS voice_cache (
id TEXT PRIMARY KEY,
conversationId TEXT NOT NULL,
text TEXT NOT NULL,
audioBlob BLOB,
byteSize INTEGER NOT NULL,
created_at INTEGER NOT NULL,
expires_at INTEGER NOT NULL,
FOREIGN KEY (conversationId) REFERENCES conversations(id)
);
CREATE INDEX IF NOT EXISTS idx_voice_cache_conv ON voice_cache(conversationId);
CREATE INDEX IF NOT EXISTS idx_voice_cache_expires ON voice_cache(expires_at);
CREATE TABLE IF NOT EXISTS tool_installations (
id TEXT PRIMARY KEY,
tool_id TEXT NOT NULL UNIQUE,
version TEXT,
installed_at INTEGER,
status TEXT NOT NULL DEFAULT 'not_installed',
last_check_at INTEGER,
error_message TEXT,
update_available INTEGER DEFAULT 0,
latest_version TEXT,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_tool_installations_status ON tool_installations(status);
CREATE INDEX IF NOT EXISTS idx_tool_installations_last_check ON tool_installations(last_check_at);
CREATE TABLE IF NOT EXISTS tool_install_history (
id TEXT PRIMARY KEY,
tool_id TEXT NOT NULL,
action TEXT NOT NULL,
started_at INTEGER NOT NULL,
completed_at INTEGER,
status TEXT NOT NULL,
error_message TEXT,
created_at INTEGER NOT NULL,
FOREIGN KEY (tool_id) REFERENCES tool_installations(tool_id)
);
CREATE INDEX IF NOT EXISTS idx_tool_install_history_tool ON tool_install_history(tool_id);
CREATE INDEX IF NOT EXISTS idx_tool_install_history_completed ON tool_install_history(completed_at);
CREATE TABLE IF NOT EXISTS workflow_runs (
id TEXT PRIMARY KEY,
workflowName TEXT NOT NULL,
workflowId TEXT,
runId TEXT,
sha TEXT,
branch TEXT,
status TEXT,
conclusion TEXT,
htmlUrl TEXT,
triggeredAt INTEGER NOT NULL,
completedAt INTEGER,
created_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_workflow_runs_name ON workflow_runs(workflowName);
CREATE INDEX IF NOT EXISTS idx_workflow_runs_sha ON workflow_runs(sha);
CREATE INDEX IF NOT EXISTS idx_workflow_runs_completed ON workflow_runs(completedAt);
CREATE TABLE IF NOT EXISTS oauth_tokens (
id TEXT PRIMARY KEY,
provider TEXT NOT NULL,
token TEXT NOT NULL,
email TEXT,
expires_at INTEGER,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_oauth_tokens_provider ON oauth_tokens(provider);
`);
}