From fb49fb8ddd226b912ebf3fc44e82b00b1850ee45 Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 20 Feb 2025 18:10:52 -0500 Subject: [PATCH] Initial schema --- server/db/schema.ts | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/server/db/schema.ts b/server/db/schema.ts index 3380cdbf..6671152a 100644 --- a/server/db/schema.ts +++ b/server/db/schema.ts @@ -25,7 +25,14 @@ export const sites = sqliteTable("sites", { megabytesOut: integer("bytesOut"), lastBandwidthUpdate: text("lastBandwidthUpdate"), type: text("type").notNull(), // "newt" or "wireguard" - online: integer("online", { mode: "boolean" }).notNull().default(false) + online: integer("online", { mode: "boolean" }).notNull().default(false), + + // exit node stuff that is how to connect to the site when it has a gerbil + address: text("address"), // this is the address of the wireguard interface in gerbil + endpoint: text("endpoint"), // this is how to reach gerbil externally - gets put into the wireguard config + publicKey: text("pubicKey"), + listenPort: integer("listenPort"), + reachableAt: text("reachableAt") // this is the internal address of the gerbil http server for command control }); export const resources = sqliteTable("resources", { @@ -108,6 +115,15 @@ export const newts = sqliteTable("newt", { }) }); +export const clients = sqliteTable("clients", { + clientId: text("id").primaryKey(), + secretHash: text("secretHash").notNull(), + dateCreated: text("dateCreated").notNull(), + siteId: integer("siteId").references(() => sites.siteId, { + onDelete: "cascade" + }) +}); + export const twoFactorBackupCodes = sqliteTable("twoFactorBackupCodes", { codeId: integer("id").primaryKey({ autoIncrement: true }), userId: text("userId") @@ -132,6 +148,14 @@ export const newtSessions = sqliteTable("newtSession", { expiresAt: integer("expiresAt").notNull() }); +export const clientSessions = sqliteTable("clientSession", { + sessionId: text("id").primaryKey(), + clientId: text("clientId") + .notNull() + .references(() => newts.newtId, { onDelete: "cascade" }), + expiresAt: integer("expiresAt").notNull() +}); + export const userOrgs = sqliteTable("userOrgs", { userId: text("userId") .notNull() @@ -393,6 +417,8 @@ export type Target = InferSelectModel; export type Session = InferSelectModel; export type Newt = InferSelectModel; export type NewtSession = InferSelectModel; +export type Client = InferSelectModel; +export type ClientSession = InferSelectModel; export type EmailVerificationCode = InferSelectModel< typeof emailVerificationCodes >;