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