2022-11-11 12:41:44 +03:00
|
|
|
CREATE TABLE "users" (
|
2022-12-09 13:20:22 +03:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-10 06:15:05 +03:00
|
|
|
"github_login" VARCHAR,
|
|
|
|
"admin" BOOLEAN,
|
2022-11-10 22:03:52 +03: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,
|
|
|
|
"created_at" TIMESTAMP NOT NULL DEFAULT now,
|
2022-11-30 14:06:25 +03:00
|
|
|
"metrics_id" TEXT,
|
2022-11-10 06:15:05 +03: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 12:41:44 +03:00
|
|
|
CREATE TABLE "access_tokens" (
|
2022-12-09 13:20:22 +03:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-10 06:15:05 +03:00
|
|
|
"user_id" INTEGER REFERENCES users (id),
|
|
|
|
"hash" VARCHAR(128)
|
|
|
|
);
|
|
|
|
CREATE INDEX "index_access_tokens_user_id" ON "access_tokens" ("user_id");
|
|
|
|
|
2022-11-11 12:41:44 +03:00
|
|
|
CREATE TABLE "contacts" (
|
2022-12-09 13:20:22 +03:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-10 06:15:05 +03: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 12:41:44 +03:00
|
|
|
CREATE TABLE "rooms" (
|
2022-12-09 13:20:22 +03:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-11 12:41:44 +03:00
|
|
|
"live_kit_room" VARCHAR NOT NULL
|
2022-11-10 06:15:05 +03:00
|
|
|
);
|
2022-11-11 12:41:44 +03:00
|
|
|
|
|
|
|
CREATE TABLE "projects" (
|
2022-12-09 13:20:22 +03:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-29 18:49:04 +03:00
|
|
|
"room_id" INTEGER REFERENCES rooms (id) NOT NULL,
|
2022-11-14 12:13:36 +03:00
|
|
|
"host_user_id" INTEGER REFERENCES users (id) NOT NULL,
|
2022-12-15 13:27:44 +03:00
|
|
|
"host_connection_id" INTEGER,
|
|
|
|
"host_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE CASCADE,
|
2022-12-09 10:11:18 +03:00
|
|
|
"unregistered" BOOLEAN NOT NULL DEFAULT FALSE
|
2022-11-11 12:41:44 +03:00
|
|
|
);
|
2022-12-15 13:27:44 +03: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 12:41:44 +03:00
|
|
|
|
|
|
|
CREATE TABLE "worktrees" (
|
2022-11-16 12:41:36 +03:00
|
|
|
"project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
|
2022-11-16 17:48:26 +03:00
|
|
|
"id" INTEGER NOT NULL,
|
2022-11-11 12:41:44 +03:00
|
|
|
"root_name" VARCHAR NOT NULL,
|
2022-11-15 18:37:32 +03:00
|
|
|
"abs_path" VARCHAR NOT NULL,
|
2022-11-15 13:44:26 +03:00
|
|
|
"visible" BOOL NOT NULL,
|
|
|
|
"scan_id" INTEGER NOT NULL,
|
2023-01-12 00:25:02 +03:00
|
|
|
"is_complete" BOOL NOT NULL DEFAULT FALSE,
|
2023-01-04 04:26:57 +03:00
|
|
|
"completed_scan_id" INTEGER NOT NULL,
|
2022-11-11 12:41:44 +03:00
|
|
|
PRIMARY KEY(project_id, id)
|
|
|
|
);
|
|
|
|
CREATE INDEX "index_worktrees_on_project_id" ON "worktrees" ("project_id");
|
|
|
|
|
2022-11-15 18:37:32 +03:00
|
|
|
CREATE TABLE "worktree_entries" (
|
2022-11-15 19:18:28 +03:00
|
|
|
"project_id" INTEGER NOT NULL,
|
|
|
|
"worktree_id" INTEGER NOT NULL,
|
2022-12-21 02:02:26 +03:00
|
|
|
"scan_id" INTEGER NOT NULL,
|
2022-11-16 17:48:26 +03:00
|
|
|
"id" INTEGER NOT NULL,
|
2022-11-15 18:37:32 +03: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-17 00:19:48 +03:00
|
|
|
"is_external" BOOL NOT NULL,
|
2022-11-15 18:37:32 +03:00
|
|
|
"is_ignored" BOOL NOT NULL,
|
2022-12-21 02:02:26 +03:00
|
|
|
"is_deleted" BOOL NOT NULL,
|
2023-06-05 22:06:23 +03:00
|
|
|
"git_status" INTEGER,
|
2022-11-15 20:02:07 +03:00
|
|
|
PRIMARY KEY(project_id, worktree_id, id),
|
2022-11-16 12:41:36 +03:00
|
|
|
FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
|
2022-11-15 18:37:32 +03:00
|
|
|
);
|
2022-12-02 15:58:23 +03:00
|
|
|
CREATE INDEX "index_worktree_entries_on_project_id" ON "worktree_entries" ("project_id");
|
2022-11-15 18:37:32 +03:00
|
|
|
CREATE INDEX "index_worktree_entries_on_project_id_and_worktree_id" ON "worktree_entries" ("project_id", "worktree_id");
|
|
|
|
|
2023-05-05 02:26:37 +03:00
|
|
|
CREATE TABLE "worktree_repositories" (
|
|
|
|
"project_id" INTEGER NOT NULL,
|
|
|
|
"worktree_id" INTEGER NOT NULL,
|
2023-05-06 00:43:46 +03:00
|
|
|
"work_directory_id" INTEGER NOT NULL,
|
2023-05-05 02:26:37 +03:00
|
|
|
"branch" VARCHAR,
|
2023-05-11 03:36:16 +03:00
|
|
|
"scan_id" INTEGER NOT NULL,
|
2023-05-05 02:26:37 +03:00
|
|
|
"is_deleted" BOOL NOT NULL,
|
2023-05-06 00:43:46 +03:00
|
|
|
PRIMARY KEY(project_id, worktree_id, work_directory_id),
|
2023-05-05 02:26:37 +03:00
|
|
|
FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE,
|
2023-05-06 00:43:46 +03:00
|
|
|
FOREIGN KEY(project_id, worktree_id, work_directory_id) REFERENCES worktree_entries (project_id, worktree_id, id) ON DELETE CASCADE
|
2023-05-05 02:26:37 +03: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 21:05:08 +03: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 03:36:16 +03:00
|
|
|
|
2022-11-15 18:37:32 +03:00
|
|
|
CREATE TABLE "worktree_diagnostic_summaries" (
|
2022-11-15 19:18:28 +03:00
|
|
|
"project_id" INTEGER NOT NULL,
|
|
|
|
"worktree_id" INTEGER NOT NULL,
|
2022-11-16 17:48:26 +03:00
|
|
|
"path" VARCHAR NOT NULL,
|
2022-11-15 18:37:32 +03:00
|
|
|
"language_server_id" INTEGER NOT NULL,
|
|
|
|
"error_count" INTEGER NOT NULL,
|
|
|
|
"warning_count" INTEGER NOT NULL,
|
2022-11-15 19:18:28 +03:00
|
|
|
PRIMARY KEY(project_id, worktree_id, path),
|
2022-11-16 12:41:36 +03:00
|
|
|
FOREIGN KEY(project_id, worktree_id) REFERENCES worktrees (project_id, id) ON DELETE CASCADE
|
2022-11-15 18:37:32 +03:00
|
|
|
);
|
2022-12-02 15:58:23 +03:00
|
|
|
CREATE INDEX "index_worktree_diagnostic_summaries_on_project_id" ON "worktree_diagnostic_summaries" ("project_id");
|
2022-11-15 18:37:32 +03: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 12:41:36 +03:00
|
|
|
"project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
|
2022-11-15 18:37:32 +03: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 13:20:22 +03:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-16 12:41:36 +03:00
|
|
|
"project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
|
2022-11-15 18:37:32 +03:00
|
|
|
"connection_id" INTEGER NOT NULL,
|
2022-12-15 04:34:24 +03:00
|
|
|
"connection_server_id" INTEGER NOT NULL REFERENCES servers (id) ON DELETE CASCADE,
|
2022-11-15 18:37:32 +03: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 11:58:25 +03:00
|
|
|
CREATE INDEX "index_project_collaborators_on_connection_server_id" ON "project_collaborators" ("connection_server_id");
|
2022-12-12 13:16:27 +03:00
|
|
|
CREATE INDEX "index_project_collaborators_on_connection_id" ON "project_collaborators" ("connection_id");
|
2022-12-15 11:58:25 +03: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 18:37:32 +03:00
|
|
|
|
2022-11-11 12:41:44 +03:00
|
|
|
CREATE TABLE "room_participants" (
|
2022-12-09 13:20:22 +03:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-11-11 12:41:44 +03:00
|
|
|
"room_id" INTEGER NOT NULL REFERENCES rooms (id),
|
|
|
|
"user_id" INTEGER NOT NULL REFERENCES users (id),
|
2022-11-11 21:36:20 +03:00
|
|
|
"answering_connection_id" INTEGER,
|
2022-12-15 04:34:24 +03:00
|
|
|
"answering_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE CASCADE,
|
2022-12-09 16:08:40 +03:00
|
|
|
"answering_connection_lost" BOOLEAN NOT NULL,
|
2022-11-11 12:41:44 +03:00
|
|
|
"location_kind" INTEGER,
|
2022-12-05 17:16:06 +03:00
|
|
|
"location_project_id" INTEGER,
|
|
|
|
"initial_project_id" INTEGER,
|
2022-11-14 12:13:36 +03:00
|
|
|
"calling_user_id" INTEGER NOT NULL REFERENCES users (id),
|
2022-12-02 18:30:00 +03:00
|
|
|
"calling_connection_id" INTEGER NOT NULL,
|
2022-12-15 04:34:24 +03:00
|
|
|
"calling_connection_server_id" INTEGER REFERENCES servers (id) ON DELETE SET NULL
|
2022-11-11 12:41:44 +03:00
|
|
|
);
|
2022-11-11 17:22:04 +03:00
|
|
|
CREATE UNIQUE INDEX "index_room_participants_on_user_id" ON "room_participants" ("user_id");
|
2022-12-13 15:57:41 +03:00
|
|
|
CREATE INDEX "index_room_participants_on_room_id" ON "room_participants" ("room_id");
|
2022-12-15 11:58:25 +03: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 13:16:27 +03:00
|
|
|
CREATE INDEX "index_room_participants_on_answering_connection_id" ON "room_participants" ("answering_connection_id");
|
2022-12-15 11:58:25 +03: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 20:02:39 +03:00
|
|
|
|
|
|
|
CREATE TABLE "servers" (
|
2022-12-15 04:34:24 +03:00
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
2022-12-14 20:02:39 +03:00
|
|
|
"environment" VARCHAR NOT NULL
|
|
|
|
);
|
2023-02-10 17:15:36 +03:00
|
|
|
|
|
|
|
CREATE TABLE "followers" (
|
|
|
|
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"room_id" INTEGER NOT NULL REFERENCES rooms (id) ON DELETE CASCADE,
|
|
|
|
"project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
|
|
|
|
"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-05 02:26:37 +03:00
|
|
|
CREATE UNIQUE INDEX
|
2023-02-10 17:15:36 +03: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");
|