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