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