1CREATE TABLE "users" (
2 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
3 "github_login" VARCHAR,
4 "admin" BOOLEAN,
5 "email_address" VARCHAR(255) DEFAULT NULL,
6 "name" TEXT,
7 "connected_once" BOOLEAN NOT NULL DEFAULT false,
8 "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
9 "metrics_id" TEXT,
10 "github_user_id" INTEGER NOT NULL,
11 "accepted_tos_at" TIMESTAMP WITHOUT TIME ZONE,
12 "github_user_created_at" TIMESTAMP WITHOUT TIME ZONE,
13 "custom_llm_monthly_allowance_in_cents" INTEGER
14);
15
16CREATE UNIQUE INDEX "index_users_github_login" ON "users" ("github_login");
17
18CREATE INDEX "index_users_on_email_address" ON "users" ("email_address");
19
20CREATE UNIQUE INDEX "index_users_on_github_user_id" ON "users" ("github_user_id");
21
22CREATE TABLE "contacts" (
23 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
24 "user_id_a" INTEGER REFERENCES users (id) NOT NULL,
25 "user_id_b" INTEGER REFERENCES users (id) NOT NULL,
26 "a_to_b" BOOLEAN NOT NULL,
27 "should_notify" BOOLEAN NOT NULL,
28 "accepted" BOOLEAN NOT NULL
29);
30
31CREATE UNIQUE INDEX "index_contacts_user_ids" ON "contacts" ("user_id_a", "user_id_b");
32
33CREATE INDEX "index_contacts_user_id_b" ON "contacts" ("user_id_b");
34
35CREATE TABLE "rooms" (
36 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
37 "live_kit_room" VARCHAR NOT NULL,
38 "environment" VARCHAR,
39 "channel_id" INTEGER REFERENCES channels (id) ON DELETE CASCADE
40);
41
42CREATE UNIQUE INDEX "index_rooms_on_channel_id" ON "rooms" ("channel_id");
43
44CREATE TABLE "projects" (
45 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
46 "room_id" INTEGER REFERENCES rooms (id) ON DELETE CASCADE,
47 "host_user_id" INTEGER REFERENCES users (id),
48 "host_connection_id" INTEGER,
49 "host_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE CASCADE,
50 "unregistered" BOOLEAN NOT NULL DEFAULT FALSE,
51 "windows_paths" BOOLEAN NOT NULL DEFAULT FALSE,
52 "features" TEXT NOT NULL DEFAULT ''
53);
54
55CREATE INDEX "index_projects_on_host_connection_server_id" ON "projects" ("host_connection_server_id");
56
57CREATE INDEX "index_projects_on_host_connection_id_and_host_connection_server_id" ON "projects" ("host_connection_id", "host_connection_server_id");
58
59CREATE TABLE "worktrees" (
60 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
61 "id" INTEGER NOT NULL,
62 "root_name" VARCHAR NOT NULL,
63 "abs_path" VARCHAR NOT NULL,
64 "visible" BOOL NOT NULL,
65 "scan_id" INTEGER NOT NULL,
66 "is_complete" BOOL NOT NULL DEFAULT FALSE,
67 "completed_scan_id" INTEGER NOT NULL,
68 "root_repo_common_dir" VARCHAR,
69 PRIMARY KEY (project_id, id)
70);
71
72CREATE INDEX "index_worktrees_on_project_id" ON "worktrees" ("project_id");
73
74CREATE TABLE "worktree_entries" (
75 "project_id" INTEGER NOT NULL,
76 "worktree_id" INTEGER NOT NULL,
77 "scan_id" INTEGER NOT NULL,
78 "id" INTEGER NOT NULL,
79 "is_dir" BOOL NOT NULL,
80 "path" VARCHAR NOT NULL,
81 "canonical_path" TEXT,
82 "inode" INTEGER NOT NULL,
83 "mtime_seconds" INTEGER NOT NULL,
84 "mtime_nanos" INTEGER NOT NULL,
85 "is_external" BOOL NOT NULL,
86 "is_ignored" BOOL NOT NULL,
87 "is_deleted" BOOL NOT NULL,
88 "is_hidden" BOOL NOT NULL,
89 "git_status" INTEGER,
90 "is_fifo" BOOL NOT NULL,
91 PRIMARY KEY (project_id, worktree_id, id),
92 FOREIGN KEY (project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
93);
94
95CREATE INDEX "index_worktree_entries_on_project_id" ON "worktree_entries" ("project_id");
96
97CREATE INDEX "index_worktree_entries_on_project_id_and_worktree_id" ON "worktree_entries" ("project_id", "worktree_id");
98
99CREATE TABLE "project_repositories" (
100 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
101 "abs_path" VARCHAR,
102 "id" INTEGER NOT NULL,
103 "entry_ids" VARCHAR,
104 "legacy_worktree_id" INTEGER,
105 "branch" VARCHAR,
106 "scan_id" INTEGER NOT NULL,
107 "is_deleted" BOOL NOT NULL,
108 "current_merge_conflicts" VARCHAR,
109 "merge_message" VARCHAR,
110 "branch_summary" VARCHAR,
111 "head_commit_details" VARCHAR,
112 "remote_upstream_url" VARCHAR,
113 "remote_origin_url" VARCHAR,
114 "linked_worktrees" VARCHAR,
115 PRIMARY KEY (project_id, id)
116);
117
118CREATE INDEX "index_project_repositories_on_project_id" ON "project_repositories" ("project_id");
119
120CREATE TABLE "project_repository_statuses" (
121 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
122 "repository_id" INTEGER NOT NULL,
123 "repo_path" VARCHAR NOT NULL,
124 "status" INT8 NOT NULL,
125 "status_kind" INT4 NOT NULL,
126 "first_status" INT4 NULL,
127 "second_status" INT4 NULL,
128 "lines_added" INT4 NULL,
129 "lines_deleted" INT4 NULL,
130 "scan_id" INT8 NOT NULL,
131 "is_deleted" BOOL NOT NULL,
132 PRIMARY KEY (project_id, repository_id, repo_path)
133);
134
135CREATE INDEX "index_project_repos_statuses_on_project_id" ON "project_repository_statuses" ("project_id");
136
137CREATE INDEX "index_project_repos_statuses_on_project_id_and_repo_id" ON "project_repository_statuses" ("project_id", "repository_id");
138
139CREATE TABLE "worktree_settings_files" (
140 "project_id" INTEGER NOT NULL,
141 "worktree_id" INTEGER NOT NULL,
142 "path" VARCHAR NOT NULL,
143 "content" TEXT,
144 "kind" VARCHAR,
145 "outside_worktree" BOOL NOT NULL DEFAULT FALSE,
146 PRIMARY KEY (project_id, worktree_id, path),
147 FOREIGN KEY (project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
148);
149
150CREATE INDEX "index_worktree_settings_files_on_project_id" ON "worktree_settings_files" ("project_id");
151
152CREATE INDEX "index_worktree_settings_files_on_project_id_and_worktree_id" ON "worktree_settings_files" ("project_id", "worktree_id");
153
154CREATE TABLE "worktree_diagnostic_summaries" (
155 "project_id" INTEGER NOT NULL,
156 "worktree_id" INTEGER NOT NULL,
157 "path" VARCHAR NOT NULL,
158 "language_server_id" INTEGER NOT NULL,
159 "error_count" INTEGER NOT NULL,
160 "warning_count" INTEGER NOT NULL,
161 PRIMARY KEY (project_id, worktree_id, path),
162 FOREIGN KEY (project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
163);
164
165CREATE INDEX "index_worktree_diagnostic_summaries_on_project_id" ON "worktree_diagnostic_summaries" ("project_id");
166
167CREATE INDEX "index_worktree_diagnostic_summaries_on_project_id_and_worktree_id" ON "worktree_diagnostic_summaries" ("project_id", "worktree_id");
168
169CREATE TABLE "language_servers" (
170 "id" INTEGER NOT NULL,
171 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
172 "name" VARCHAR NOT NULL,
173 "capabilities" TEXT NOT NULL,
174 "worktree_id" BIGINT,
175 PRIMARY KEY (project_id, id)
176);
177
178CREATE INDEX "index_language_servers_on_project_id" ON "language_servers" ("project_id");
179
180CREATE TABLE "project_collaborators" (
181 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
182 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
183 "connection_id" INTEGER NOT NULL,
184 "connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
185 "user_id" INTEGER NOT NULL,
186 "replica_id" INTEGER NOT NULL,
187 "is_host" BOOLEAN NOT NULL,
188 "committer_name" VARCHAR,
189 "committer_email" VARCHAR
190);
191
192CREATE INDEX "index_project_collaborators_on_project_id" ON "project_collaborators" ("project_id");
193
194CREATE UNIQUE INDEX "index_project_collaborators_on_project_id_and_replica_id" ON "project_collaborators" ("project_id", "replica_id");
195
196CREATE INDEX "index_project_collaborators_on_connection_server_id" ON "project_collaborators" ("connection_server_id");
197
198CREATE INDEX "index_project_collaborators_on_connection_id" ON "project_collaborators" ("connection_id");
199
200CREATE UNIQUE INDEX "index_project_collaborators_on_project_id_connection_id_and_server_id" ON "project_collaborators" (
201 "project_id",
202 "connection_id",
203 "connection_server_id"
204);
205
206CREATE TABLE "room_participants" (
207 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
208 "room_id" INTEGER NOT NULL REFERENCES rooms (id),
209 "user_id" INTEGER NOT NULL REFERENCES users (id),
210 "answering_connection_id" INTEGER,
211 "answering_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE CASCADE,
212 "answering_connection_lost" BOOLEAN NOT NULL,
213 "location_kind" INTEGER,
214 "location_project_id" INTEGER,
215 "initial_project_id" INTEGER,
216 "calling_user_id" INTEGER NOT NULL REFERENCES users (id),
217 "calling_connection_id" INTEGER NOT NULL,
218 "calling_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE SET NULL,
219 "participant_index" INTEGER,
220 "role" TEXT,
221 "in_call" BOOLEAN NOT NULL DEFAULT FALSE
222);
223
224CREATE UNIQUE INDEX "index_room_participants_on_user_id" ON "room_participants" ("user_id");
225
226CREATE INDEX "index_room_participants_on_room_id" ON "room_participants" ("room_id");
227
228CREATE INDEX "index_room_participants_on_answering_connection_server_id" ON "room_participants" ("answering_connection_server_id");
229
230CREATE INDEX "index_room_participants_on_calling_connection_server_id" ON "room_participants" ("calling_connection_server_id");
231
232CREATE INDEX "index_room_participants_on_answering_connection_id" ON "room_participants" ("answering_connection_id");
233
234CREATE UNIQUE INDEX "index_room_participants_on_answering_connection_id_and_answering_connection_server_id" ON "room_participants" (
235 "answering_connection_id",
236 "answering_connection_server_id"
237);
238
239CREATE TABLE "servers" (
240 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
241 "environment" VARCHAR NOT NULL
242);
243
244CREATE TABLE "followers" (
245 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
246 "room_id" INTEGER NOT NULL REFERENCES rooms (id) ON DELETE CASCADE,
247 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
248 "leader_connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
249 "leader_connection_id" INTEGER NOT NULL,
250 "follower_connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
251 "follower_connection_id" INTEGER NOT NULL
252);
253
254CREATE UNIQUE INDEX "index_followers_on_project_id_and_leader_connection_server_id_and_leader_connection_id_and_follower_connection_server_id_and_follower_connection_id" ON "followers" (
255 "project_id",
256 "leader_connection_server_id",
257 "leader_connection_id",
258 "follower_connection_server_id",
259 "follower_connection_id"
260);
261
262CREATE INDEX "index_followers_on_room_id" ON "followers" ("room_id");
263
264CREATE TABLE "channels" (
265 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
266 "name" VARCHAR NOT NULL,
267 "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
268 "visibility" VARCHAR NOT NULL,
269 "parent_path" TEXT NOT NULL,
270 "requires_zed_cla" BOOLEAN NOT NULL DEFAULT FALSE,
271 "channel_order" INTEGER NOT NULL DEFAULT 1
272);
273
274CREATE INDEX "index_channels_on_parent_path" ON "channels" ("parent_path");
275
276CREATE INDEX "index_channels_on_parent_path_and_order" ON "channels" ("parent_path", "channel_order");
277
278CREATE TABLE IF NOT EXISTS "channel_chat_participants" (
279 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
280 "user_id" INTEGER NOT NULL REFERENCES users (id),
281 "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
282 "connection_id" INTEGER NOT NULL,
283 "connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE
284);
285
286CREATE INDEX "index_channel_chat_participants_on_channel_id" ON "channel_chat_participants" ("channel_id");
287
288CREATE TABLE "channel_members" (
289 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
290 "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
291 "user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
292 "role" VARCHAR NOT NULL,
293 "accepted" BOOLEAN NOT NULL DEFAULT false,
294 "updated_at" TIMESTAMP NOT NULL DEFAULT now
295);
296
297CREATE UNIQUE INDEX "index_channel_members_on_channel_id_and_user_id" ON "channel_members" ("channel_id", "user_id");
298
299CREATE TABLE "buffers" (
300 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
301 "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
302 "epoch" INTEGER NOT NULL DEFAULT 0,
303 "latest_operation_epoch" INTEGER,
304 "latest_operation_replica_id" INTEGER,
305 "latest_operation_lamport_timestamp" INTEGER
306);
307
308CREATE INDEX "index_buffers_on_channel_id" ON "buffers" ("channel_id");
309
310CREATE TABLE "buffer_operations" (
311 "buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
312 "epoch" INTEGER NOT NULL,
313 "replica_id" INTEGER NOT NULL,
314 "lamport_timestamp" INTEGER NOT NULL,
315 "value" BLOB NOT NULL,
316 PRIMARY KEY (buffer_id, epoch, lamport_timestamp, replica_id)
317);
318
319CREATE TABLE "buffer_snapshots" (
320 "buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
321 "epoch" INTEGER NOT NULL,
322 "text" TEXT NOT NULL,
323 "operation_serialization_version" INTEGER NOT NULL,
324 PRIMARY KEY (buffer_id, epoch)
325);
326
327CREATE TABLE "channel_buffer_collaborators" (
328 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
329 "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
330 "connection_id" INTEGER NOT NULL,
331 "connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
332 "connection_lost" BOOLEAN NOT NULL DEFAULT false,
333 "user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
334 "replica_id" INTEGER NOT NULL
335);
336
337CREATE INDEX "index_channel_buffer_collaborators_on_channel_id" ON "channel_buffer_collaborators" ("channel_id");
338
339CREATE UNIQUE INDEX "index_channel_buffer_collaborators_on_channel_id_and_replica_id" ON "channel_buffer_collaborators" ("channel_id", "replica_id");
340
341CREATE INDEX "index_channel_buffer_collaborators_on_connection_server_id" ON "channel_buffer_collaborators" ("connection_server_id");
342
343CREATE INDEX "index_channel_buffer_collaborators_on_connection_id" ON "channel_buffer_collaborators" ("connection_id");
344
345CREATE UNIQUE INDEX "index_channel_buffer_collaborators_on_channel_id_connection_id_and_server_id" ON "channel_buffer_collaborators" (
346 "channel_id",
347 "connection_id",
348 "connection_server_id"
349);
350
351CREATE TABLE "observed_buffer_edits" (
352 "user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
353 "buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
354 "epoch" INTEGER NOT NULL,
355 "lamport_timestamp" INTEGER NOT NULL,
356 "replica_id" INTEGER NOT NULL,
357 PRIMARY KEY (user_id, buffer_id)
358);
359
360CREATE UNIQUE INDEX "index_observed_buffers_user_and_buffer_id" ON "observed_buffer_edits" ("user_id", "buffer_id");
361
362CREATE TABLE "notification_kinds" (
363 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
364 "name" VARCHAR NOT NULL
365);
366
367CREATE UNIQUE INDEX "index_notification_kinds_on_name" ON "notification_kinds" ("name");
368
369CREATE TABLE "notifications" (
370 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
371 "created_at" TIMESTAMP NOT NULL default CURRENT_TIMESTAMP,
372 "recipient_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
373 "kind" INTEGER NOT NULL REFERENCES notification_kinds (id),
374 "entity_id" INTEGER,
375 "content" TEXT,
376 "is_read" BOOLEAN NOT NULL DEFAULT FALSE,
377 "response" BOOLEAN
378);
379
380CREATE INDEX "index_notifications_on_recipient_id_is_read_kind_entity_id" ON "notifications" ("recipient_id", "is_read", "kind", "entity_id");
381
382CREATE TABLE contributors (
383 user_id INTEGER REFERENCES users (id),
384 signed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
385 PRIMARY KEY (user_id)
386);
387
388CREATE TABLE extensions (
389 id INTEGER PRIMARY KEY AUTOINCREMENT,
390 external_id TEXT NOT NULL,
391 name TEXT NOT NULL,
392 latest_version TEXT NOT NULL,
393 total_download_count INTEGER NOT NULL DEFAULT 0
394);
395
396CREATE TABLE extension_versions (
397 extension_id INTEGER REFERENCES extensions (id),
398 version TEXT NOT NULL,
399 published_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
400 authors TEXT NOT NULL,
401 repository TEXT NOT NULL,
402 description TEXT NOT NULL,
403 schema_version INTEGER NOT NULL DEFAULT 0,
404 wasm_api_version TEXT,
405 download_count INTEGER NOT NULL DEFAULT 0,
406 provides_themes BOOLEAN NOT NULL DEFAULT FALSE,
407 provides_icon_themes BOOLEAN NOT NULL DEFAULT FALSE,
408 provides_languages BOOLEAN NOT NULL DEFAULT FALSE,
409 provides_grammars BOOLEAN NOT NULL DEFAULT FALSE,
410 provides_language_servers BOOLEAN NOT NULL DEFAULT FALSE,
411 provides_context_servers BOOLEAN NOT NULL DEFAULT FALSE,
412 provides_agent_servers BOOLEAN NOT NULL DEFAULT FALSE,
413 provides_slash_commands BOOLEAN NOT NULL DEFAULT FALSE,
414 provides_indexed_docs_providers BOOLEAN NOT NULL DEFAULT FALSE,
415 provides_snippets BOOLEAN NOT NULL DEFAULT FALSE,
416 provides_debug_adapters BOOLEAN NOT NULL DEFAULT FALSE,
417 PRIMARY KEY (extension_id, version)
418);
419
420CREATE UNIQUE INDEX "index_extensions_external_id" ON "extensions" ("external_id");
421
422CREATE INDEX "index_extensions_total_download_count" ON "extensions" ("total_download_count");
423
424CREATE TABLE IF NOT EXISTS "breakpoints" (
425 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
426 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
427 "position" INTEGER NOT NULL,
428 "log_message" TEXT NULL,
429 "worktree_id" BIGINT NOT NULL,
430 "path" TEXT NOT NULL,
431 "kind" VARCHAR NOT NULL
432);
433
434CREATE INDEX "index_breakpoints_on_project_id" ON "breakpoints" ("project_id");
435
436CREATE TABLE IF NOT EXISTS "shared_threads" (
437 "id" TEXT PRIMARY KEY NOT NULL,
438 "user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
439 "title" VARCHAR(512) NOT NULL,
440 "data" BLOB NOT NULL,
441 "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
442 "updated_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
443);
444
445CREATE INDEX "index_shared_threads_user_id" ON "shared_threads" ("user_id");