2022-11-11 12:41:44 +03:00
|
|
|
CREATE TABLE "users" (
|
2022-11-10 22:03:52 +03:00
|
|
|
"id" INTEGER PRIMARY KEY,
|
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,
|
|
|
|
"metrics_id" VARCHAR(255),
|
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-11-10 22:03:52 +03:00
|
|
|
"id" INTEGER PRIMARY KEY,
|
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-11-10 22:03:52 +03:00
|
|
|
"id" INTEGER PRIMARY KEY,
|
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-11-10 22:03:52 +03:00
|
|
|
"id" INTEGER PRIMARY KEY,
|
2022-11-11 12:41:44 +03:00
|
|
|
"version" INTEGER NOT NULL,
|
|
|
|
"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" (
|
|
|
|
"id" INTEGER PRIMARY KEY,
|
|
|
|
"room_id" INTEGER REFERENCES rooms (id),
|
|
|
|
"host_user_id" INTEGER REFERENCES users (id) NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE "project_collaborators" (
|
|
|
|
"id" INTEGER PRIMARY KEY,
|
2022-11-11 18:59:54 +03:00
|
|
|
"project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
|
2022-11-11 12:41:44 +03:00
|
|
|
"connection_id" INTEGER NOT NULL,
|
|
|
|
"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 TABLE "worktrees" (
|
|
|
|
"id" INTEGER NOT NULL,
|
2022-11-11 18:59:54 +03:00
|
|
|
"project_id" INTEGER NOT NULL REFERENCES projects (id) ON DELETE CASCADE,
|
2022-11-11 12:41:44 +03:00
|
|
|
"root_name" VARCHAR NOT NULL,
|
|
|
|
PRIMARY KEY(project_id, id)
|
|
|
|
);
|
|
|
|
CREATE INDEX "index_worktrees_on_project_id" ON "worktrees" ("project_id");
|
|
|
|
|
|
|
|
CREATE TABLE "room_participants" (
|
|
|
|
"id" INTEGER PRIMARY KEY,
|
|
|
|
"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-11-11 12:41:44 +03:00
|
|
|
"location_kind" INTEGER,
|
2022-11-11 17:22:04 +03:00
|
|
|
"location_project_id" INTEGER REFERENCES projects (id),
|
|
|
|
"initial_project_id" INTEGER REFERENCES projects (id),
|
|
|
|
"calling_user_id" INTEGER NOT NULL REFERENCES users (id)
|
2022-11-11 21:36:20 +03:00
|
|
|
"calling_connection_id" INTEGER NOT 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");
|