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 "invite_code" VARCHAR(64),
8 "invite_count" INTEGER NOT NULL DEFAULT 0,
9 "inviter_id" INTEGER REFERENCES users (id),
10 "connected_once" BOOLEAN NOT NULL DEFAULT false,
11 "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
12 "metrics_id" TEXT,
13 "github_user_id" INTEGER NOT NULL,
14 "accepted_tos_at" TIMESTAMP WITHOUT TIME ZONE,
15 "github_user_created_at" TIMESTAMP WITHOUT TIME ZONE,
16 "custom_llm_monthly_allowance_in_cents" INTEGER
17);
18
19CREATE UNIQUE INDEX "index_users_github_login" ON "users" ("github_login");
20
21CREATE UNIQUE INDEX "index_invite_code_users" ON "users" ("invite_code");
22
23CREATE INDEX "index_users_on_email_address" ON "users" ("email_address");
24
25CREATE UNIQUE INDEX "index_users_on_github_user_id" ON "users" ("github_user_id");
26
27CREATE TABLE "access_tokens" (
28 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
29 "user_id" INTEGER REFERENCES users (id) ON DELETE CASCADE,
30 "impersonated_user_id" INTEGER REFERENCES users (id),
31 "hash" VARCHAR(128)
32);
33
34CREATE INDEX "index_access_tokens_user_id" ON "access_tokens" ("user_id");
35
36CREATE TABLE "contacts" (
37 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
38 "user_id_a" INTEGER REFERENCES users (id) NOT NULL,
39 "user_id_b" INTEGER REFERENCES users (id) NOT NULL,
40 "a_to_b" BOOLEAN NOT NULL,
41 "should_notify" BOOLEAN NOT NULL,
42 "accepted" BOOLEAN NOT NULL
43);
44
45CREATE UNIQUE INDEX "index_contacts_user_ids" ON "contacts" ("user_id_a", "user_id_b");
46
47CREATE INDEX "index_contacts_user_id_b" ON "contacts" ("user_id_b");
48
49CREATE TABLE "rooms" (
50 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
51 "live_kit_room" VARCHAR NOT NULL,
52 "environment" VARCHAR,
53 "channel_id" INTEGER REFERENCES channels (id) ON DELETE CASCADE
54);
55
56CREATE UNIQUE INDEX "index_rooms_on_channel_id" ON "rooms" ("channel_id");
57
58CREATE TABLE "projects" (
59 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
60 "room_id" INTEGER REFERENCES rooms (id) ON DELETE CASCADE,
61 "host_user_id" INTEGER REFERENCES users (id),
62 "host_connection_id" INTEGER,
63 "host_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE CASCADE,
64 "unregistered" BOOLEAN NOT NULL DEFAULT FALSE
65);
66
67CREATE INDEX "index_projects_on_host_connection_server_id" ON "projects" ("host_connection_server_id");
68
69CREATE INDEX "index_projects_on_host_connection_id_and_host_connection_server_id" ON "projects" ("host_connection_id", "host_connection_server_id");
70
71CREATE TABLE "worktrees" (
72 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
73 "id" INTEGER NOT NULL,
74 "root_name" VARCHAR NOT NULL,
75 "abs_path" VARCHAR NOT NULL,
76 "visible" BOOL NOT NULL,
77 "scan_id" INTEGER NOT NULL,
78 "is_complete" BOOL NOT NULL DEFAULT FALSE,
79 "completed_scan_id" INTEGER NOT NULL,
80 PRIMARY KEY (project_id, id)
81);
82
83CREATE INDEX "index_worktrees_on_project_id" ON "worktrees" ("project_id");
84
85CREATE TABLE "worktree_entries" (
86 "project_id" INTEGER NOT NULL,
87 "worktree_id" INTEGER NOT NULL,
88 "scan_id" INTEGER NOT NULL,
89 "id" INTEGER NOT NULL,
90 "is_dir" BOOL NOT NULL,
91 "path" VARCHAR NOT NULL,
92 "canonical_path" TEXT,
93 "inode" INTEGER NOT NULL,
94 "mtime_seconds" INTEGER NOT NULL,
95 "mtime_nanos" INTEGER NOT NULL,
96 "is_external" BOOL NOT NULL,
97 "is_ignored" BOOL NOT NULL,
98 "is_deleted" BOOL NOT NULL,
99 "git_status" INTEGER,
100 "is_fifo" BOOL NOT NULL,
101 PRIMARY KEY (project_id, worktree_id, id),
102 FOREIGN KEY (project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
103);
104
105CREATE INDEX "index_worktree_entries_on_project_id" ON "worktree_entries" ("project_id");
106
107CREATE INDEX "index_worktree_entries_on_project_id_and_worktree_id" ON "worktree_entries" ("project_id", "worktree_id");
108
109CREATE TABLE "project_repositories" (
110 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
111 "abs_path" VARCHAR,
112 "id" INTEGER NOT NULL,
113 "entry_ids" VARCHAR,
114 "legacy_worktree_id" INTEGER,
115 "branch" VARCHAR,
116 "scan_id" INTEGER NOT NULL,
117 "is_deleted" BOOL NOT NULL,
118 "current_merge_conflicts" VARCHAR,
119 "branch_summary" VARCHAR,
120 "head_commit_details" VARCHAR,
121 PRIMARY KEY (project_id, id)
122);
123
124CREATE INDEX "index_project_repositories_on_project_id" ON "project_repositories" ("project_id");
125
126CREATE TABLE "project_repository_statuses" (
127 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
128 "repository_id" INTEGER NOT NULL,
129 "repo_path" VARCHAR NOT NULL,
130 "status" INT8 NOT NULL,
131 "status_kind" INT4 NOT NULL,
132 "first_status" INT4 NULL,
133 "second_status" INT4 NULL,
134 "scan_id" INT8 NOT NULL,
135 "is_deleted" BOOL NOT NULL,
136 PRIMARY KEY (project_id, repository_id, repo_path)
137);
138
139CREATE INDEX "index_project_repos_statuses_on_project_id" ON "project_repository_statuses" ("project_id");
140
141CREATE INDEX "index_project_repos_statuses_on_project_id_and_repo_id" ON "project_repository_statuses" ("project_id", "repository_id");
142
143CREATE TABLE "worktree_settings_files" (
144 "project_id" INTEGER NOT NULL,
145 "worktree_id" INTEGER NOT NULL,
146 "path" VARCHAR NOT NULL,
147 "content" TEXT,
148 "kind" VARCHAR,
149 PRIMARY KEY (project_id, worktree_id, path),
150 FOREIGN KEY (project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
151);
152
153CREATE INDEX "index_worktree_settings_files_on_project_id" ON "worktree_settings_files" ("project_id");
154
155CREATE INDEX "index_worktree_settings_files_on_project_id_and_worktree_id" ON "worktree_settings_files" ("project_id", "worktree_id");
156
157CREATE TABLE "worktree_diagnostic_summaries" (
158 "project_id" INTEGER NOT NULL,
159 "worktree_id" INTEGER NOT NULL,
160 "path" VARCHAR NOT NULL,
161 "language_server_id" INTEGER NOT NULL,
162 "error_count" INTEGER NOT NULL,
163 "warning_count" INTEGER NOT NULL,
164 PRIMARY KEY (project_id, worktree_id, path),
165 FOREIGN KEY (project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
166);
167
168CREATE INDEX "index_worktree_diagnostic_summaries_on_project_id" ON "worktree_diagnostic_summaries" ("project_id");
169
170CREATE INDEX "index_worktree_diagnostic_summaries_on_project_id_and_worktree_id" ON "worktree_diagnostic_summaries" ("project_id", "worktree_id");
171
172CREATE TABLE "language_servers" (
173 "id" INTEGER NOT NULL,
174 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
175 "name" VARCHAR NOT NULL,
176 PRIMARY KEY (project_id, id)
177);
178
179CREATE INDEX "index_language_servers_on_project_id" ON "language_servers" ("project_id");
180
181CREATE TABLE "project_collaborators" (
182 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
183 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
184 "connection_id" INTEGER NOT NULL,
185 "connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
186 "user_id" INTEGER NOT NULL,
187 "replica_id" INTEGER NOT NULL,
188 "is_host" BOOLEAN NOT NULL,
189 "committer_name" VARCHAR,
190 "committer_email" VARCHAR
191);
192
193CREATE INDEX "index_project_collaborators_on_project_id" ON "project_collaborators" ("project_id");
194
195CREATE UNIQUE INDEX "index_project_collaborators_on_project_id_and_replica_id" ON "project_collaborators" ("project_id", "replica_id");
196
197CREATE INDEX "index_project_collaborators_on_connection_server_id" ON "project_collaborators" ("connection_server_id");
198
199CREATE INDEX "index_project_collaborators_on_connection_id" ON "project_collaborators" ("connection_id");
200
201CREATE UNIQUE INDEX "index_project_collaborators_on_project_id_connection_id_and_server_id" ON "project_collaborators" (
202 "project_id",
203 "connection_id",
204 "connection_server_id"
205);
206
207CREATE TABLE "room_participants" (
208 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
209 "room_id" INTEGER NOT NULL REFERENCES rooms (id),
210 "user_id" INTEGER NOT NULL REFERENCES users (id),
211 "answering_connection_id" INTEGER,
212 "answering_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE CASCADE,
213 "answering_connection_lost" BOOLEAN NOT NULL,
214 "location_kind" INTEGER,
215 "location_project_id" INTEGER,
216 "initial_project_id" INTEGER,
217 "calling_user_id" INTEGER NOT NULL REFERENCES users (id),
218 "calling_connection_id" INTEGER NOT NULL,
219 "calling_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE SET NULL,
220 "participant_index" INTEGER,
221 "role" TEXT,
222 "in_call" BOOLEAN NOT NULL DEFAULT FALSE
223);
224
225CREATE UNIQUE INDEX "index_room_participants_on_user_id" ON "room_participants" ("user_id");
226
227CREATE INDEX "index_room_participants_on_room_id" ON "room_participants" ("room_id");
228
229CREATE INDEX "index_room_participants_on_answering_connection_server_id" ON "room_participants" ("answering_connection_server_id");
230
231CREATE INDEX "index_room_participants_on_calling_connection_server_id" ON "room_participants" ("calling_connection_server_id");
232
233CREATE INDEX "index_room_participants_on_answering_connection_id" ON "room_participants" ("answering_connection_id");
234
235CREATE UNIQUE INDEX "index_room_participants_on_answering_connection_id_and_answering_connection_server_id" ON "room_participants" (
236 "answering_connection_id",
237 "answering_connection_server_id"
238);
239
240CREATE TABLE "servers" (
241 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
242 "environment" VARCHAR NOT NULL
243);
244
245CREATE TABLE "followers" (
246 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
247 "room_id" INTEGER NOT NULL REFERENCES rooms (id) ON DELETE CASCADE,
248 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
249 "leader_connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
250 "leader_connection_id" INTEGER NOT NULL,
251 "follower_connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
252 "follower_connection_id" INTEGER NOT NULL
253);
254
255CREATE 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" (
256 "project_id",
257 "leader_connection_server_id",
258 "leader_connection_id",
259 "follower_connection_server_id",
260 "follower_connection_id"
261);
262
263CREATE INDEX "index_followers_on_room_id" ON "followers" ("room_id");
264
265CREATE TABLE "channels" (
266 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
267 "name" VARCHAR NOT NULL,
268 "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
269 "visibility" VARCHAR NOT NULL,
270 "parent_path" TEXT NOT NULL,
271 "requires_zed_cla" BOOLEAN NOT NULL DEFAULT FALSE,
272 "channel_order" INTEGER NOT NULL DEFAULT 1
273);
274
275CREATE INDEX "index_channels_on_parent_path" ON "channels" ("parent_path");
276
277CREATE INDEX "index_channels_on_parent_path_and_order" ON "channels" ("parent_path", "channel_order");
278
279CREATE TABLE IF NOT EXISTS "channel_chat_participants" (
280 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
281 "user_id" INTEGER NOT NULL REFERENCES users (id),
282 "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
283 "connection_id" INTEGER NOT NULL,
284 "connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE
285);
286
287CREATE INDEX "index_channel_chat_participants_on_channel_id" ON "channel_chat_participants" ("channel_id");
288
289CREATE TABLE IF NOT EXISTS "channel_messages" (
290 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
291 "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
292 "sender_id" INTEGER NOT NULL REFERENCES users (id),
293 "body" TEXT NOT NULL,
294 "sent_at" TIMESTAMP,
295 "edited_at" TIMESTAMP,
296 "nonce" BLOB NOT NULL,
297 "reply_to_message_id" INTEGER DEFAULT NULL
298);
299
300CREATE INDEX "index_channel_messages_on_channel_id" ON "channel_messages" ("channel_id");
301
302CREATE UNIQUE INDEX "index_channel_messages_on_sender_id_nonce" ON "channel_messages" ("sender_id", "nonce");
303
304CREATE TABLE "channel_message_mentions" (
305 "message_id" INTEGER NOT NULL REFERENCES channel_messages (id) ON DELETE CASCADE,
306 "start_offset" INTEGER NOT NULL,
307 "end_offset" INTEGER NOT NULL,
308 "user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
309 PRIMARY KEY (message_id, start_offset)
310);
311
312CREATE TABLE "channel_members" (
313 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
314 "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
315 "user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
316 "role" VARCHAR NOT NULL,
317 "accepted" BOOLEAN NOT NULL DEFAULT false,
318 "updated_at" TIMESTAMP NOT NULL DEFAULT now
319);
320
321CREATE UNIQUE INDEX "index_channel_members_on_channel_id_and_user_id" ON "channel_members" ("channel_id", "user_id");
322
323CREATE TABLE "buffers" (
324 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
325 "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
326 "epoch" INTEGER NOT NULL DEFAULT 0,
327 "latest_operation_epoch" INTEGER,
328 "latest_operation_replica_id" INTEGER,
329 "latest_operation_lamport_timestamp" INTEGER
330);
331
332CREATE INDEX "index_buffers_on_channel_id" ON "buffers" ("channel_id");
333
334CREATE TABLE "buffer_operations" (
335 "buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
336 "epoch" INTEGER NOT NULL,
337 "replica_id" INTEGER NOT NULL,
338 "lamport_timestamp" INTEGER NOT NULL,
339 "value" BLOB NOT NULL,
340 PRIMARY KEY (buffer_id, epoch, lamport_timestamp, replica_id)
341);
342
343CREATE TABLE "buffer_snapshots" (
344 "buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
345 "epoch" INTEGER NOT NULL,
346 "text" TEXT NOT NULL,
347 "operation_serialization_version" INTEGER NOT NULL,
348 PRIMARY KEY (buffer_id, epoch)
349);
350
351CREATE TABLE "channel_buffer_collaborators" (
352 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
353 "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
354 "connection_id" INTEGER NOT NULL,
355 "connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
356 "connection_lost" BOOLEAN NOT NULL DEFAULT false,
357 "user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
358 "replica_id" INTEGER NOT NULL
359);
360
361CREATE INDEX "index_channel_buffer_collaborators_on_channel_id" ON "channel_buffer_collaborators" ("channel_id");
362
363CREATE UNIQUE INDEX "index_channel_buffer_collaborators_on_channel_id_and_replica_id" ON "channel_buffer_collaborators" ("channel_id", "replica_id");
364
365CREATE INDEX "index_channel_buffer_collaborators_on_connection_server_id" ON "channel_buffer_collaborators" ("connection_server_id");
366
367CREATE INDEX "index_channel_buffer_collaborators_on_connection_id" ON "channel_buffer_collaborators" ("connection_id");
368
369CREATE UNIQUE INDEX "index_channel_buffer_collaborators_on_channel_id_connection_id_and_server_id" ON "channel_buffer_collaborators" (
370 "channel_id",
371 "connection_id",
372 "connection_server_id"
373);
374
375CREATE TABLE "feature_flags" (
376 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
377 "flag" TEXT NOT NULL UNIQUE,
378 "enabled_for_all" BOOLEAN NOT NULL DEFAULT false
379);
380
381CREATE INDEX "index_feature_flags" ON "feature_flags" ("id");
382
383CREATE TABLE "user_features" (
384 "user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
385 "feature_id" INTEGER NOT NULL REFERENCES feature_flags (id) ON DELETE CASCADE,
386 PRIMARY KEY (user_id, feature_id)
387);
388
389CREATE UNIQUE INDEX "index_user_features_user_id_and_feature_id" ON "user_features" ("user_id", "feature_id");
390
391CREATE INDEX "index_user_features_on_user_id" ON "user_features" ("user_id");
392
393CREATE INDEX "index_user_features_on_feature_id" ON "user_features" ("feature_id");
394
395CREATE TABLE "observed_buffer_edits" (
396 "user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
397 "buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
398 "epoch" INTEGER NOT NULL,
399 "lamport_timestamp" INTEGER NOT NULL,
400 "replica_id" INTEGER NOT NULL,
401 PRIMARY KEY (user_id, buffer_id)
402);
403
404CREATE UNIQUE INDEX "index_observed_buffers_user_and_buffer_id" ON "observed_buffer_edits" ("user_id", "buffer_id");
405
406CREATE TABLE IF NOT EXISTS "observed_channel_messages" (
407 "user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
408 "channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
409 "channel_message_id" INTEGER NOT NULL,
410 PRIMARY KEY (user_id, channel_id)
411);
412
413CREATE UNIQUE INDEX "index_observed_channel_messages_user_and_channel_id" ON "observed_channel_messages" ("user_id", "channel_id");
414
415CREATE TABLE "notification_kinds" (
416 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
417 "name" VARCHAR NOT NULL
418);
419
420CREATE UNIQUE INDEX "index_notification_kinds_on_name" ON "notification_kinds" ("name");
421
422CREATE TABLE "notifications" (
423 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
424 "created_at" TIMESTAMP NOT NULL default CURRENT_TIMESTAMP,
425 "recipient_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
426 "kind" INTEGER NOT NULL REFERENCES notification_kinds (id),
427 "entity_id" INTEGER,
428 "content" TEXT,
429 "is_read" BOOLEAN NOT NULL DEFAULT FALSE,
430 "response" BOOLEAN
431);
432
433CREATE INDEX "index_notifications_on_recipient_id_is_read_kind_entity_id" ON "notifications" ("recipient_id", "is_read", "kind", "entity_id");
434
435CREATE TABLE contributors (
436 user_id INTEGER REFERENCES users (id),
437 signed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
438 PRIMARY KEY (user_id)
439);
440
441CREATE TABLE extensions (
442 id INTEGER PRIMARY KEY AUTOINCREMENT,
443 external_id TEXT NOT NULL,
444 name TEXT NOT NULL,
445 latest_version TEXT NOT NULL,
446 total_download_count INTEGER NOT NULL DEFAULT 0
447);
448
449CREATE TABLE extension_versions (
450 extension_id INTEGER REFERENCES extensions (id),
451 version TEXT NOT NULL,
452 published_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
453 authors TEXT NOT NULL,
454 repository TEXT NOT NULL,
455 description TEXT NOT NULL,
456 schema_version INTEGER NOT NULL DEFAULT 0,
457 wasm_api_version TEXT,
458 download_count INTEGER NOT NULL DEFAULT 0,
459 provides_themes BOOLEAN NOT NULL DEFAULT FALSE,
460 provides_icon_themes BOOLEAN NOT NULL DEFAULT FALSE,
461 provides_languages BOOLEAN NOT NULL DEFAULT FALSE,
462 provides_grammars BOOLEAN NOT NULL DEFAULT FALSE,
463 provides_language_servers BOOLEAN NOT NULL DEFAULT FALSE,
464 provides_context_servers BOOLEAN NOT NULL DEFAULT FALSE,
465 provides_slash_commands BOOLEAN NOT NULL DEFAULT FALSE,
466 provides_indexed_docs_providers BOOLEAN NOT NULL DEFAULT FALSE,
467 provides_snippets BOOLEAN NOT NULL DEFAULT FALSE,
468 provides_debug_adapters BOOLEAN NOT NULL DEFAULT FALSE,
469 PRIMARY KEY (extension_id, version)
470);
471
472CREATE UNIQUE INDEX "index_extensions_external_id" ON "extensions" ("external_id");
473
474CREATE INDEX "index_extensions_total_download_count" ON "extensions" ("total_download_count");
475
476CREATE TABLE rate_buckets (
477 user_id INT NOT NULL,
478 rate_limit_name VARCHAR(255) NOT NULL,
479 token_count INT NOT NULL,
480 last_refill TIMESTAMP WITHOUT TIME ZONE NOT NULL,
481 PRIMARY KEY (user_id, rate_limit_name),
482 FOREIGN KEY (user_id) REFERENCES users (id)
483);
484
485CREATE INDEX idx_user_id_rate_limit ON rate_buckets (user_id, rate_limit_name);
486
487CREATE TABLE IF NOT EXISTS billing_preferences (
488 id INTEGER PRIMARY KEY AUTOINCREMENT,
489 created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
490 user_id INTEGER NOT NULL REFERENCES users (id),
491 max_monthly_llm_usage_spending_in_cents INTEGER NOT NULL,
492 model_request_overages_enabled bool NOT NULL DEFAULT FALSE,
493 model_request_overages_spend_limit_in_cents integer NOT NULL DEFAULT 0
494);
495
496CREATE UNIQUE INDEX "uix_billing_preferences_on_user_id" ON billing_preferences (user_id);
497
498CREATE TABLE IF NOT EXISTS billing_customers (
499 id INTEGER PRIMARY KEY AUTOINCREMENT,
500 created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
501 user_id INTEGER NOT NULL REFERENCES users (id),
502 has_overdue_invoices BOOLEAN NOT NULL DEFAULT FALSE,
503 stripe_customer_id TEXT NOT NULL,
504 trial_started_at TIMESTAMP
505);
506
507CREATE UNIQUE INDEX "uix_billing_customers_on_user_id" ON billing_customers (user_id);
508
509CREATE UNIQUE INDEX "uix_billing_customers_on_stripe_customer_id" ON billing_customers (stripe_customer_id);
510
511CREATE TABLE IF NOT EXISTS billing_subscriptions (
512 id INTEGER PRIMARY KEY AUTOINCREMENT,
513 created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
514 billing_customer_id INTEGER NOT NULL REFERENCES billing_customers (id),
515 stripe_subscription_id TEXT NOT NULL,
516 stripe_subscription_status TEXT NOT NULL,
517 stripe_cancel_at TIMESTAMP,
518 stripe_cancellation_reason TEXT,
519 kind TEXT,
520 stripe_current_period_start BIGINT,
521 stripe_current_period_end BIGINT
522);
523
524CREATE INDEX "ix_billing_subscriptions_on_billing_customer_id" ON billing_subscriptions (billing_customer_id);
525
526CREATE UNIQUE INDEX "uix_billing_subscriptions_on_stripe_subscription_id" ON billing_subscriptions (stripe_subscription_id);
527
528CREATE TABLE IF NOT EXISTS processed_stripe_events (
529 stripe_event_id TEXT PRIMARY KEY,
530 stripe_event_type TEXT NOT NULL,
531 stripe_event_created_timestamp INTEGER NOT NULL,
532 processed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
533);
534
535CREATE INDEX "ix_processed_stripe_events_on_stripe_event_created_timestamp" ON processed_stripe_events (stripe_event_created_timestamp);
536
537CREATE TABLE IF NOT EXISTS "breakpoints" (
538 "id" INTEGER PRIMARY KEY AUTOINCREMENT,
539 "project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
540 "position" INTEGER NOT NULL,
541 "log_message" TEXT NULL,
542 "worktree_id" BIGINT NOT NULL,
543 "path" TEXT NOT NULL,
544 "kind" VARCHAR NOT NULL
545);
546
547CREATE INDEX "index_breakpoints_on_project_id" ON "breakpoints" ("project_id");