2022-11-11 09:41:44 +00:00
|
|
|
CREATE TABLE "users" (
|
2022-12-09 10:20:22 +00:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-10 03:15:05 +00:00
|
|
|
"github_login" VARCHAR,
|
|
|
|
"admin" BOOLEAN,
|
2022-11-10 19:03:52 +00:00
|
|
|
"email_address" VARCHAR(255) DEFAULT NULL,
|
|
|
|
"invite_code" VARCHAR(64),
|
|
|
|
"invite_count" INTEGER NOT NULL DEFAULT 0,
|
|
|
|
"inviter_id" INTEGER REFERENCES users (id),
|
|
|
|
"connected_once" BOOLEAN NOT NULL DEFAULT false,
|
2024-01-23 19:36:35 +00:00
|
|
|
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2022-11-30 11:06:25 +00:00
|
|
|
"metrics_id" TEXT,
|
2022-11-10 03:15:05 +00:00
|
|
|
"github_user_id" INTEGER
|
|
|
|
);
|
|
|
|
CREATE UNIQUE INDEX "index_users_github_login" ON "users" ("github_login");
|
|
|
|
CREATE UNIQUE INDEX "index_invite_code_users" ON "users" ("invite_code");
|
|
|
|
CREATE INDEX "index_users_on_email_address" ON "users" ("email_address");
|
|
|
|
CREATE INDEX "index_users_on_github_user_id" ON "users" ("github_user_id");
|
|
|
|
|
2022-11-11 09:41:44 +00:00
|
|
|
CREATE TABLE "access_tokens" (
|
2022-12-09 10:20:22 +00:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-10 03:15:05 +00:00
|
|
|
"user_id" INTEGER REFERENCES users (id),
|
2024-01-18 01:58:59 +00:00
|
|
|
"impersonated_user_id" INTEGER REFERENCES users (id),
|
2022-11-10 03:15:05 +00:00
|
|
|
"hash" VARCHAR(128)
|
|
|
|
);
|
|
|
|
CREATE INDEX "index_access_tokens_user_id" ON "access_tokens" ("user_id");
|
|
|
|
|
2022-11-11 09:41:44 +00:00
|
|
|
CREATE TABLE "contacts" (
|
2022-12-09 10:20:22 +00:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-10 03:15:05 +00:00
|
|
|
"user_id_a" INTEGER REFERENCES users (id) NOT NULL,
|
|
|
|
"user_id_b" INTEGER REFERENCES users (id) NOT NULL,
|
|
|
|
"a_to_b" BOOLEAN NOT NULL,
|
|
|
|
"should_notify" BOOLEAN NOT NULL,
|
|
|
|
"accepted" BOOLEAN NOT NULL
|
|
|
|
);
|
|
|
|
CREATE UNIQUE INDEX "index_contacts_user_ids" ON "contacts" ("user_id_a", "user_id_b");
|
|
|
|
CREATE INDEX "index_contacts_user_id_b" ON "contacts" ("user_id_b");
|
|
|
|
|
2022-11-11 09:41:44 +00:00
|
|
|
CREATE TABLE "rooms" (
|
2022-12-09 10:20:22 +00:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2023-07-31 22:27:10 +00:00
|
|
|
"live_kit_room" VARCHAR NOT NULL,
|
2024-01-11 06:57:58 +00:00
|
|
|
"environment" VARCHAR,
|
2023-07-31 22:27:10 +00:00
|
|
|
"channel_id" INTEGER REFERENCES channels (id) ON DELETE CASCADE
|
2022-11-10 03:15:05 +00:00
|
|
|
);
|
2023-10-10 19:38:20 +00:00
|
|
|
CREATE UNIQUE INDEX "index_rooms_on_channel_id" ON "rooms" ("channel_id");
|
2022-11-11 09:41:44 +00:00
|
|
|
|
|
|
|
CREATE TABLE "projects" (
|
2022-12-09 10:20:22 +00:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2024-04-11 21:36:35 +00:00
|
|
|
"room_id" INTEGER REFERENCES rooms (id) ON DELETE CASCADE,
|
2024-03-05 02:17:40 +00:00
|
|
|
"host_user_id" INTEGER REFERENCES users (id),
|
2022-12-15 10:27:44 +00:00
|
|
|
"host_connection_id" INTEGER,
|
|
|
|
"host_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE CASCADE,
|
2024-03-05 02:17:40 +00:00
|
|
|
"unregistered" BOOLEAN NOT NULL DEFAULT FALSE,
|
2024-04-11 21:36:35 +00:00
|
|
|
"hosted_project_id" INTEGER REFERENCES hosted_projects (id),
|
2024-05-02 17:00:08 +00:00
|
|
|
"dev_server_project_id" INTEGER REFERENCES dev_server_projects(id)
|
2022-11-11 09:41:44 +00:00
|
|
|
);
|
2022-12-15 10:27:44 +00:00
|
|
|
CREATE INDEX "index_projects_on_host_connection_server_id" ON "projects" ("host_connection_server_id");
|
|
|
|
CREATE INDEX "index_projects_on_host_connection_id_and_host_connection_server_id" ON "projects" ("host_connection_id", "host_connection_server_id");
|
2022-11-11 09:41:44 +00:00
|
|
|
|
|
|
|
CREATE TABLE "worktrees" (
|
2022-11-16 09:41:36 +00:00
|
|
|
"project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
|
2022-11-16 14:48:26 +00:00
|
|
|
"id" INTEGER NOT NULL,
|
2022-11-11 09:41:44 +00:00
|
|
|
"root_name" VARCHAR NOT NULL,
|
2022-11-15 15:37:32 +00:00
|
|
|
"abs_path" VARCHAR NOT NULL,
|
2022-11-15 10:44:26 +00:00
|
|
|
"visible" BOOL NOT NULL,
|
|
|
|
"scan_id" INTEGER NOT NULL,
|
2023-01-11 21:25:02 +00:00
|
|
|
"is_complete" BOOL NOT NULL DEFAULT FALSE,
|
2023-01-04 01:26:57 +00:00
|
|
|
"completed_scan_id" INTEGER NOT NULL,
|
2022-11-11 09:41:44 +00:00
|
|
|
PRIMARY KEY(project_id, id)
|
|
|
|
);
|
|
|
|
CREATE INDEX "index_worktrees_on_project_id" ON "worktrees" ("project_id");
|
|
|
|
|
2022-11-15 15:37:32 +00:00
|
|
|
CREATE TABLE "worktree_entries" (
|
2022-11-15 16:18:28 +00:00
|
|
|
"project_id" INTEGER NOT NULL,
|
|
|
|
"worktree_id" INTEGER NOT NULL,
|
2022-12-20 23:02:26 +00:00
|
|
|
"scan_id" INTEGER NOT NULL,
|
2022-11-16 14:48:26 +00:00
|
|
|
"id" INTEGER NOT NULL,
|
2022-11-15 15:37:32 +00:00
|
|
|
"is_dir" BOOL NOT NULL,
|
|
|
|
"path" VARCHAR NOT NULL,
|
|
|
|
"inode" INTEGER NOT NULL,
|
|
|
|
"mtime_seconds" INTEGER NOT NULL,
|
|
|
|
"mtime_nanos" INTEGER NOT NULL,
|
|
|
|
"is_symlink" BOOL NOT NULL,
|
2023-06-16 21:19:48 +00:00
|
|
|
"is_external" BOOL NOT NULL,
|
2022-11-15 15:37:32 +00:00
|
|
|
"is_ignored" BOOL NOT NULL,
|
2022-12-20 23:02:26 +00:00
|
|
|
"is_deleted" BOOL NOT NULL,
|
2023-06-05 19:06:23 +00:00
|
|
|
"git_status" INTEGER,
|
2022-11-15 17:02:07 +00:00
|
|
|
PRIMARY KEY(project_id, worktree_id, id),
|
2022-11-16 09:41:36 +00:00
|
|
|
FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
|
2022-11-15 15:37:32 +00:00
|
|
|
);
|
2022-12-02 12:58:23 +00:00
|
|
|
CREATE INDEX "index_worktree_entries_on_project_id" ON "worktree_entries" ("project_id");
|
2022-11-15 15:37:32 +00:00
|
|
|
CREATE INDEX "index_worktree_entries_on_project_id_and_worktree_id" ON "worktree_entries" ("project_id", "worktree_id");
|
|
|
|
|
2023-05-04 23:26:37 +00:00
|
|
|
CREATE TABLE "worktree_repositories" (
|
|
|
|
"project_id" INTEGER NOT NULL,
|
|
|
|
"worktree_id" INTEGER NOT NULL,
|
2023-05-05 21:43:46 +00:00
|
|
|
"work_directory_id" INTEGER NOT NULL,
|
2023-05-04 23:26:37 +00:00
|
|
|
"branch" VARCHAR,
|
2023-05-11 00:36:16 +00:00
|
|
|
"scan_id" INTEGER NOT NULL,
|
2023-05-04 23:26:37 +00:00
|
|
|
"is_deleted" BOOL NOT NULL,
|
2023-05-05 21:43:46 +00:00
|
|
|
PRIMARY KEY(project_id, worktree_id, work_directory_id),
|
2023-05-04 23:26:37 +00:00
|
|
|
FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE,
|
2023-05-05 21:43:46 +00:00
|
|
|
FOREIGN KEY(project_id, worktree_id, work_directory_id) REFERENCES worktree_entries (project_id, worktree_id, id) ON DELETE CASCADE
|
2023-05-04 23:26:37 +00:00
|
|
|
);
|
|
|
|
CREATE INDEX "index_worktree_repositories_on_project_id" ON "worktree_repositories" ("project_id");
|
|
|
|
CREATE INDEX "index_worktree_repositories_on_project_id_and_worktree_id" ON "worktree_repositories" ("project_id", "worktree_id");
|
|
|
|
|
2023-05-30 18:05:08 +00:00
|
|
|
CREATE TABLE "worktree_settings_files" (
|
|
|
|
"project_id" INTEGER NOT NULL,
|
|
|
|
"worktree_id" INTEGER NOT NULL,
|
|
|
|
"path" VARCHAR NOT NULL,
|
|
|
|
"content" TEXT,
|
|
|
|
PRIMARY KEY(project_id, worktree_id, path),
|
|
|
|
FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
CREATE INDEX "index_worktree_settings_files_on_project_id" ON "worktree_settings_files" ("project_id");
|
|
|
|
CREATE INDEX "index_worktree_settings_files_on_project_id_and_worktree_id" ON "worktree_settings_files" ("project_id", "worktree_id");
|
2023-05-11 00:36:16 +00:00
|
|
|
|
2022-11-15 15:37:32 +00:00
|
|
|
CREATE TABLE "worktree_diagnostic_summaries" (
|
2022-11-15 16:18:28 +00:00
|
|
|
"project_id" INTEGER NOT NULL,
|
|
|
|
"worktree_id" INTEGER NOT NULL,
|
2022-11-16 14:48:26 +00:00
|
|
|
"path" VARCHAR NOT NULL,
|
2022-11-15 15:37:32 +00:00
|
|
|
"language_server_id" INTEGER NOT NULL,
|
|
|
|
"error_count" INTEGER NOT NULL,
|
|
|
|
"warning_count" INTEGER NOT NULL,
|
2022-11-15 16:18:28 +00:00
|
|
|
PRIMARY KEY(project_id, worktree_id, path),
|
2022-11-16 09:41:36 +00:00
|
|
|
FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
|
2022-11-15 15:37:32 +00:00
|
|
|
);
|
2022-12-02 12:58:23 +00:00
|
|
|
CREATE INDEX "index_worktree_diagnostic_summaries_on_project_id" ON "worktree_diagnostic_summaries" ("project_id");
|
2022-11-15 15:37:32 +00:00
|
|
|
CREATE INDEX "index_worktree_diagnostic_summaries_on_project_id_and_worktree_id" ON "worktree_diagnostic_summaries" ("project_id", "worktree_id");
|
|
|
|
|
|
|
|
CREATE TABLE "language_servers" (
|
|
|
|
"id" INTEGER NOT NULL,
|
2022-11-16 09:41:36 +00:00
|
|
|
"project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
|
2022-11-15 15:37:32 +00:00
|
|
|
"name" VARCHAR NOT NULL,
|
|
|
|
PRIMARY KEY(project_id, id)
|
|
|
|
);
|
|
|
|
CREATE INDEX "index_language_servers_on_project_id" ON "language_servers" ("project_id");
|
|
|
|
|
|
|
|
CREATE TABLE "project_collaborators" (
|
2022-12-09 10:20:22 +00:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-16 09:41:36 +00:00
|
|
|
"project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
|
2022-11-15 15:37:32 +00:00
|
|
|
"connection_id" INTEGER NOT NULL,
|
2022-12-15 01:34:24 +00:00
|
|
|
"connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
|
2022-11-15 15:37:32 +00:00
|
|
|
"user_id" INTEGER NOT NULL,
|
|
|
|
"replica_id" INTEGER NOT NULL,
|
|
|
|
"is_host" BOOLEAN NOT NULL
|
|
|
|
);
|
|
|
|
CREATE INDEX "index_project_collaborators_on_project_id" ON "project_collaborators" ("project_id");
|
|
|
|
CREATE UNIQUE INDEX "index_project_collaborators_on_project_id_and_replica_id" ON "project_collaborators" ("project_id", "replica_id");
|
2022-12-15 08:58:25 +00:00
|
|
|
CREATE INDEX "index_project_collaborators_on_connection_server_id" ON "project_collaborators" ("connection_server_id");
|
2022-12-12 10:16:27 +00:00
|
|
|
CREATE INDEX "index_project_collaborators_on_connection_id" ON "project_collaborators" ("connection_id");
|
2022-12-15 08:58:25 +00:00
|
|
|
CREATE UNIQUE INDEX "index_project_collaborators_on_project_id_connection_id_and_server_id" ON "project_collaborators" ("project_id", "connection_id", "connection_server_id");
|
2022-11-15 15:37:32 +00:00
|
|
|
|
2022-11-11 09:41:44 +00:00
|
|
|
CREATE TABLE "room_participants" (
|
2022-12-09 10:20:22 +00:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-11 09:41:44 +00:00
|
|
|
"room_id" INTEGER NOT NULL REFERENCES rooms (id),
|
|
|
|
"user_id" INTEGER NOT NULL REFERENCES users (id),
|
2022-11-11 18:36:20 +00:00
|
|
|
"answering_connection_id" INTEGER,
|
2022-12-15 01:34:24 +00:00
|
|
|
"answering_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE CASCADE,
|
2022-12-09 13:08:40 +00:00
|
|
|
"answering_connection_lost" BOOLEAN NOT NULL,
|
2022-11-11 09:41:44 +00:00
|
|
|
"location_kind" INTEGER,
|
2022-12-05 14:16:06 +00:00
|
|
|
"location_project_id" INTEGER,
|
|
|
|
"initial_project_id" INTEGER,
|
2022-11-14 09:13:36 +00:00
|
|
|
"calling_user_id" INTEGER NOT NULL REFERENCES users (id),
|
2022-12-02 15:30:00 +00:00
|
|
|
"calling_connection_id" INTEGER NOT NULL,
|
2023-09-26 21:19:38 +00:00
|
|
|
"calling_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE SET NULL,
|
2024-01-03 03:14:30 +00:00
|
|
|
"participant_index" INTEGER,
|
2024-02-09 21:18:27 +00:00
|
|
|
"role" TEXT,
|
|
|
|
"in_call" BOOLEAN NOT NULL DEFAULT FALSE
|
2022-11-11 09:41:44 +00:00
|
|
|
);
|
2022-11-11 14:22:04 +00:00
|
|
|
CREATE UNIQUE INDEX "index_room_participants_on_user_id" ON "room_participants" ("user_id");
|
2022-12-13 12:57:41 +00:00
|
|
|
CREATE INDEX "index_room_participants_on_room_id" ON "room_participants" ("room_id");
|
2022-12-15 08:58:25 +00:00
|
|
|
CREATE INDEX "index_room_participants_on_answering_connection_server_id" ON "room_participants" ("answering_connection_server_id");
|
|
|
|
CREATE INDEX "index_room_participants_on_calling_connection_server_id" ON "room_participants" ("calling_connection_server_id");
|
2022-12-12 10:16:27 +00:00
|
|
|
CREATE INDEX "index_room_participants_on_answering_connection_id" ON "room_participants" ("answering_connection_id");
|
2022-12-15 08:58:25 +00:00
|
|
|
CREATE UNIQUE INDEX "index_room_participants_on_answering_connection_id_and_answering_connection_server_id" ON "room_participants" ("answering_connection_id", "answering_connection_server_id");
|
2022-12-14 17:02:39 +00:00
|
|
|
|
|
|
|
CREATE TABLE "servers" (
|
2022-12-15 01:34:24 +00:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-12-14 17:02:39 +00:00
|
|
|
"environment" VARCHAR NOT NULL
|
|
|
|
);
|
2023-02-10 14:15:36 +00:00
|
|
|
|
|
|
|
CREATE TABLE "followers" (
|
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"room_id" INTEGER NOT NULL REFERENCES rooms (id) ON DELETE CASCADE,
|
2023-09-28 21:21:44 +00:00
|
|
|
"project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
|
2023-02-10 14:15:36 +00:00
|
|
|
"leader_connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
|
|
|
|
"leader_connection_id" INTEGER NOT NULL,
|
|
|
|
"follower_connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
|
|
|
|
"follower_connection_id" INTEGER NOT NULL
|
|
|
|
);
|
2023-05-04 23:26:37 +00:00
|
|
|
CREATE UNIQUE INDEX
|
2023-02-10 14:15:36 +00:00
|
|
|
"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" ("project_id", "leader_connection_server_id", "leader_connection_id", "follower_connection_server_id", "follower_connection_id");
|
|
|
|
CREATE INDEX "index_followers_on_room_id" ON "followers" ("room_id");
|
2023-07-27 00:20:43 +00:00
|
|
|
|
|
|
|
CREATE TABLE "channels" (
|
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"name" VARCHAR NOT NULL,
|
2023-10-19 00:20:04 +00:00
|
|
|
"created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
2023-10-24 15:28:03 +00:00
|
|
|
"visibility" VARCHAR NOT NULL,
|
2024-03-15 19:04:48 +00:00
|
|
|
"parent_path" TEXT NOT NULL,
|
2024-01-23 00:38:54 +00:00
|
|
|
"requires_zed_cla" BOOLEAN NOT NULL DEFAULT FALSE
|
2023-07-27 17:47:45 +00:00
|
|
|
);
|
2023-07-27 00:20:43 +00:00
|
|
|
|
2023-10-24 15:28:03 +00:00
|
|
|
CREATE INDEX "index_channels_on_parent_path" ON "channels" ("parent_path");
|
|
|
|
|
2023-09-07 19:24:25 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS "channel_chat_participants" (
|
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"user_id" INTEGER NOT NULL REFERENCES users (id),
|
|
|
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
|
|
|
"connection_id" INTEGER NOT NULL,
|
|
|
|
"connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE
|
|
|
|
);
|
|
|
|
CREATE INDEX "index_channel_chat_participants_on_channel_id" ON "channel_chat_participants" ("channel_id");
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS "channel_messages" (
|
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
|
|
|
"sender_id" INTEGER NOT NULL REFERENCES users (id),
|
|
|
|
"body" TEXT NOT NULL,
|
|
|
|
"sent_at" TIMESTAMP,
|
2024-03-20 01:49:04 +00:00
|
|
|
"edited_at" TIMESTAMP,
|
2024-02-06 20:22:54 +00:00
|
|
|
"nonce" BLOB NOT NULL,
|
|
|
|
"reply_to_message_id" INTEGER DEFAULT NULL
|
2023-09-07 19:24:25 +00:00
|
|
|
);
|
|
|
|
CREATE INDEX "index_channel_messages_on_channel_id" ON "channel_messages" ("channel_id");
|
2023-10-19 01:04:54 +00:00
|
|
|
CREATE UNIQUE INDEX "index_channel_messages_on_sender_id_nonce" ON "channel_messages" ("sender_id", "nonce");
|
2023-09-07 19:24:25 +00:00
|
|
|
|
2023-10-18 23:56:03 +00:00
|
|
|
CREATE TABLE "channel_message_mentions" (
|
|
|
|
"message_id" INTEGER NOT NULL REFERENCES channel_messages (id) ON DELETE CASCADE,
|
|
|
|
"start_offset" INTEGER NOT NULL,
|
|
|
|
"end_offset" INTEGER NOT NULL,
|
|
|
|
"user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
|
|
|
PRIMARY KEY(message_id, start_offset)
|
|
|
|
);
|
|
|
|
|
2023-07-27 00:20:43 +00:00
|
|
|
CREATE TABLE "channel_members" (
|
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
|
|
|
"user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
2024-03-15 19:04:48 +00:00
|
|
|
"role" VARCHAR NOT NULL,
|
2023-07-29 00:05:56 +00:00
|
|
|
"accepted" BOOLEAN NOT NULL DEFAULT false,
|
2023-07-27 00:20:43 +00:00
|
|
|
"updated_at" TIMESTAMP NOT NULL DEFAULT now
|
2023-07-27 17:47:45 +00:00
|
|
|
);
|
2023-07-27 00:20:43 +00:00
|
|
|
|
|
|
|
CREATE UNIQUE INDEX "index_channel_members_on_channel_id_and_user_id" ON "channel_members" ("channel_id", "user_id");
|
2023-08-21 19:00:43 +00:00
|
|
|
|
|
|
|
CREATE TABLE "buffers" (
|
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2023-08-22 00:53:37 +00:00
|
|
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
2024-03-07 18:35:47 +00:00
|
|
|
"epoch" INTEGER NOT NULL DEFAULT 0,
|
|
|
|
"latest_operation_epoch" INTEGER,
|
|
|
|
"latest_operation_replica_id" INTEGER,
|
|
|
|
"latest_operation_lamport_timestamp" INTEGER
|
2023-08-21 19:00:43 +00:00
|
|
|
);
|
|
|
|
|
2023-08-22 00:53:37 +00:00
|
|
|
CREATE INDEX "index_buffers_on_channel_id" ON "buffers" ("channel_id");
|
|
|
|
|
2023-08-21 19:00:43 +00:00
|
|
|
CREATE TABLE "buffer_operations" (
|
|
|
|
"buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
|
|
|
|
"epoch" INTEGER NOT NULL,
|
|
|
|
"replica_id" INTEGER NOT NULL,
|
|
|
|
"lamport_timestamp" INTEGER NOT NULL,
|
|
|
|
"value" BLOB NOT NULL,
|
|
|
|
PRIMARY KEY(buffer_id, epoch, lamport_timestamp, replica_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "buffer_snapshots" (
|
|
|
|
"buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
|
|
|
|
"epoch" INTEGER NOT NULL,
|
|
|
|
"text" TEXT NOT NULL,
|
2023-08-22 22:33:37 +00:00
|
|
|
"operation_serialization_version" INTEGER NOT NULL,
|
2023-08-21 19:00:43 +00:00
|
|
|
PRIMARY KEY(buffer_id, epoch)
|
|
|
|
);
|
2023-08-22 00:53:37 +00:00
|
|
|
|
|
|
|
CREATE TABLE "channel_buffer_collaborators" (
|
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2023-08-22 18:02:13 +00:00
|
|
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
2023-08-22 00:53:37 +00:00
|
|
|
"connection_id" INTEGER NOT NULL,
|
|
|
|
"connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
|
2023-08-22 18:02:13 +00:00
|
|
|
"connection_lost" BOOLEAN NOT NULL DEFAULT false,
|
2023-08-22 00:53:37 +00:00
|
|
|
"user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
|
|
|
"replica_id" INTEGER NOT NULL
|
|
|
|
);
|
|
|
|
|
2023-08-22 18:02:13 +00:00
|
|
|
CREATE INDEX "index_channel_buffer_collaborators_on_channel_id" ON "channel_buffer_collaborators" ("channel_id");
|
|
|
|
CREATE UNIQUE INDEX "index_channel_buffer_collaborators_on_channel_id_and_replica_id" ON "channel_buffer_collaborators" ("channel_id", "replica_id");
|
2023-08-22 00:53:37 +00:00
|
|
|
CREATE INDEX "index_channel_buffer_collaborators_on_connection_server_id" ON "channel_buffer_collaborators" ("connection_server_id");
|
|
|
|
CREATE INDEX "index_channel_buffer_collaborators_on_connection_id" ON "channel_buffer_collaborators" ("connection_id");
|
2023-08-22 18:02:13 +00:00
|
|
|
CREATE UNIQUE INDEX "index_channel_buffer_collaborators_on_channel_id_connection_id_and_server_id" ON "channel_buffer_collaborators" ("channel_id", "connection_id", "connection_server_id");
|
2023-08-25 21:34:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE "feature_flags" (
|
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"flag" TEXT NOT NULL UNIQUE
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE INDEX "index_feature_flags" ON "feature_flags" ("id");
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE "user_features" (
|
|
|
|
"user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
|
|
|
"feature_id" INTEGER NOT NULL REFERENCES feature_flags (id) ON DELETE CASCADE,
|
|
|
|
PRIMARY KEY (user_id, feature_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE UNIQUE INDEX "index_user_features_user_id_and_feature_id" ON "user_features" ("user_id", "feature_id");
|
|
|
|
CREATE INDEX "index_user_features_on_user_id" ON "user_features" ("user_id");
|
|
|
|
CREATE INDEX "index_user_features_on_feature_id" ON "user_features" ("feature_id");
|
2023-09-26 20:29:23 +00:00
|
|
|
|
|
|
|
|
2023-10-01 05:30:36 +00:00
|
|
|
CREATE TABLE "observed_buffer_edits" (
|
2023-09-26 20:29:23 +00:00
|
|
|
"user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
2023-10-01 05:30:36 +00:00
|
|
|
"buffer_id" INTEGER NOT NULL REFERENCES buffers (id) ON DELETE CASCADE,
|
2023-09-26 20:29:23 +00:00
|
|
|
"epoch" INTEGER NOT NULL,
|
|
|
|
"lamport_timestamp" INTEGER NOT NULL,
|
2023-10-02 22:58:34 +00:00
|
|
|
"replica_id" INTEGER NOT NULL,
|
2023-10-01 05:30:36 +00:00
|
|
|
PRIMARY KEY (user_id, buffer_id)
|
2023-09-26 20:29:23 +00:00
|
|
|
);
|
|
|
|
|
2023-10-01 05:30:36 +00:00
|
|
|
CREATE UNIQUE INDEX "index_observed_buffers_user_and_buffer_id" ON "observed_buffer_edits" ("user_id", "buffer_id");
|
2023-10-02 04:31:36 +00:00
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS "observed_channel_messages" (
|
|
|
|
"user_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
|
|
|
"channel_id" INTEGER NOT NULL REFERENCES channels (id) ON DELETE CASCADE,
|
|
|
|
"channel_message_id" INTEGER NOT NULL,
|
|
|
|
PRIMARY KEY (user_id, channel_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE UNIQUE INDEX "index_observed_channel_messages_user_and_channel_id" ON "observed_channel_messages" ("user_id", "channel_id");
|
2023-10-04 21:16:32 +00:00
|
|
|
|
|
|
|
CREATE TABLE "notification_kinds" (
|
2023-10-13 00:17:45 +00:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2023-10-12 21:43:36 +00:00
|
|
|
"name" VARCHAR NOT NULL
|
2023-10-04 21:16:32 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE UNIQUE INDEX "index_notification_kinds_on_name" ON "notification_kinds" ("name");
|
|
|
|
|
|
|
|
CREATE TABLE "notifications" (
|
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2023-10-12 21:43:36 +00:00
|
|
|
"created_at" TIMESTAMP NOT NULL default CURRENT_TIMESTAMP,
|
|
|
|
"recipient_id" INTEGER NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
2023-10-04 21:16:32 +00:00
|
|
|
"kind" INTEGER NOT NULL REFERENCES notification_kinds (id),
|
2023-10-17 17:34:50 +00:00
|
|
|
"entity_id" INTEGER,
|
2023-10-17 16:12:55 +00:00
|
|
|
"content" TEXT,
|
|
|
|
"is_read" BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
"response" BOOLEAN
|
2023-10-04 21:16:32 +00:00
|
|
|
);
|
|
|
|
|
2023-10-19 20:00:07 +00:00
|
|
|
CREATE INDEX
|
|
|
|
"index_notifications_on_recipient_id_is_read_kind_entity_id"
|
|
|
|
ON "notifications"
|
|
|
|
("recipient_id", "is_read", "kind", "entity_id");
|
2024-01-22 18:48:33 +00:00
|
|
|
|
|
|
|
CREATE TABLE contributors (
|
|
|
|
user_id INTEGER REFERENCES users(id),
|
|
|
|
signed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
PRIMARY KEY (user_id)
|
|
|
|
);
|
2024-02-15 20:53:57 +00:00
|
|
|
|
|
|
|
CREATE TABLE extensions (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
external_id TEXT NOT NULL,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
latest_version TEXT NOT NULL,
|
|
|
|
total_download_count INTEGER NOT NULL DEFAULT 0
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE extension_versions (
|
|
|
|
extension_id INTEGER REFERENCES extensions(id),
|
|
|
|
version TEXT NOT NULL,
|
|
|
|
published_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
authors TEXT NOT NULL,
|
|
|
|
repository TEXT NOT NULL,
|
|
|
|
description TEXT NOT NULL,
|
2024-03-20 21:33:26 +00:00
|
|
|
schema_version INTEGER NOT NULL DEFAULT 0,
|
2024-03-25 21:30:48 +00:00
|
|
|
wasm_api_version TEXT,
|
2024-02-15 20:53:57 +00:00
|
|
|
download_count INTEGER NOT NULL DEFAULT 0,
|
|
|
|
PRIMARY KEY (extension_id, version)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE UNIQUE INDEX "index_extensions_external_id" ON "extensions" ("external_id");
|
|
|
|
CREATE INDEX "index_extensions_total_download_count" ON "extensions" ("total_download_count");
|
2024-02-27 05:15:11 +00:00
|
|
|
|
2024-03-19 18:22:26 +00:00
|
|
|
CREATE TABLE rate_buckets (
|
|
|
|
user_id INT NOT NULL,
|
|
|
|
rate_limit_name VARCHAR(255) NOT NULL,
|
|
|
|
token_count INT NOT NULL,
|
|
|
|
last_refill TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
|
|
|
PRIMARY KEY (user_id, rate_limit_name),
|
|
|
|
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
|
|
);
|
|
|
|
CREATE INDEX idx_user_id_rate_limit ON rate_buckets (user_id, rate_limit_name);
|
|
|
|
|
2024-02-27 05:15:11 +00:00
|
|
|
CREATE TABLE hosted_projects (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
channel_id INTEGER NOT NULL REFERENCES channels(id),
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
visibility TEXT NOT NULL,
|
2024-04-23 21:33:09 +00:00
|
|
|
deleted_at TIMESTAMP NULL
|
2024-02-27 05:15:11 +00:00
|
|
|
);
|
|
|
|
CREATE INDEX idx_hosted_projects_on_channel_id ON hosted_projects (channel_id);
|
|
|
|
CREATE UNIQUE INDEX uix_hosted_projects_on_channel_id_and_name ON hosted_projects (channel_id, name) WHERE (deleted_at IS NULL);
|
2024-03-22 14:44:56 +00:00
|
|
|
|
|
|
|
CREATE TABLE dev_servers (
|
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
2024-04-23 21:33:09 +00:00
|
|
|
user_id INTEGER NOT NULL REFERENCES users(id),
|
2024-03-22 14:44:56 +00:00
|
|
|
name TEXT NOT NULL,
|
2024-05-17 14:48:07 +00:00
|
|
|
ssh_connection_string TEXT,
|
2024-03-22 14:44:56 +00:00
|
|
|
hashed_token TEXT NOT NULL
|
|
|
|
);
|
2024-04-11 21:36:35 +00:00
|
|
|
|
2024-05-02 17:00:08 +00:00
|
|
|
CREATE TABLE dev_server_projects (
|
2024-04-11 21:36:35 +00:00
|
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
dev_server_id INTEGER NOT NULL REFERENCES dev_servers(id),
|
2024-07-16 18:01:59 +00:00
|
|
|
paths TEXT NOT NULL
|
2024-04-11 21:36:35 +00:00
|
|
|
);
|