20221109000000_test_schema.sql

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