20221109000000_test_schema.sql

 1CREATE TABLE IF NOT EXISTS "users" (
 2    "id" INTEGER PRIMARY KEY,
 3    "github_login" VARCHAR,
 4    "admin" BOOLEAN,
 5    "email_address" VARCHAR(255) DEFAULT NULL,
 6    "invite_code" VARCHAR(64),
 7    "invite_count" INTEGER NOT NULL DEFAULT 0,
 8    "inviter_id" INTEGER REFERENCES users (id),
 9    "connected_once" BOOLEAN NOT NULL DEFAULT false,
10    "created_at" TIMESTAMP NOT NULL DEFAULT now,
11    "metrics_id" VARCHAR(255),
12    "github_user_id" INTEGER
13);
14CREATE UNIQUE INDEX "index_users_github_login" ON "users" ("github_login");
15CREATE UNIQUE INDEX "index_invite_code_users" ON "users" ("invite_code");
16CREATE INDEX "index_users_on_email_address" ON "users" ("email_address");
17CREATE INDEX "index_users_on_github_user_id" ON "users" ("github_user_id");
18
19CREATE TABLE IF NOT EXISTS "access_tokens" (
20    "id" INTEGER PRIMARY KEY,
21    "user_id" INTEGER REFERENCES users (id),
22    "hash" VARCHAR(128)
23);
24CREATE INDEX "index_access_tokens_user_id" ON "access_tokens" ("user_id");
25
26CREATE TABLE IF NOT EXISTS "contacts" (
27    "id" INTEGER PRIMARY KEY,
28    "user_id_a" INTEGER REFERENCES users (id) NOT NULL,
29    "user_id_b" INTEGER REFERENCES users (id) NOT NULL,
30    "a_to_b" BOOLEAN NOT NULL,
31    "should_notify" BOOLEAN NOT NULL,
32    "accepted" BOOLEAN NOT NULL
33);
34CREATE UNIQUE INDEX "index_contacts_user_ids" ON "contacts" ("user_id_a", "user_id_b");
35CREATE INDEX "index_contacts_user_id_b" ON "contacts" ("user_id_b");
36
37CREATE TABLE IF NOT EXISTS "projects" (
38    "id" INTEGER PRIMARY KEY,
39    "host_user_id" INTEGER REFERENCES users (id) NOT NULL,
40    "unregistered" BOOLEAN NOT NULL DEFAULT false
41);