fosrl.pangolin/server/db/schema.ts

420 lines
15 KiB
TypeScript
Raw Normal View History

2024-10-28 23:34:04 -04:00
import { InferSelectModel } from "drizzle-orm";
2024-12-15 17:47:07 -05:00
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
2024-09-28 11:51:21 -04:00
2024-09-28 13:31:22 -04:00
export const orgs = sqliteTable("orgs", {
2024-10-14 15:11:18 -04:00
orgId: text("orgId").primaryKey(),
2024-09-28 15:21:13 -04:00
name: text("name").notNull(),
2024-12-15 17:47:07 -05:00
domain: text("domain").notNull()
2024-09-28 11:51:21 -04:00
});
export const sites = sqliteTable("sites", {
2024-09-28 15:21:13 -04:00
siteId: integer("siteId").primaryKey({ autoIncrement: true }),
orgId: text("orgId")
.references(() => orgs.orgId, {
2024-12-15 17:47:07 -05:00
onDelete: "cascade"
})
.notNull(),
2024-10-14 23:50:58 -04:00
niceId: text("niceId").notNull(),
exitNodeId: integer("exitNode").references(() => exitNodes.exitNodeId, {
2024-12-15 17:47:07 -05:00
onDelete: "set null"
2024-10-01 20:48:03 -04:00
}),
2024-09-28 15:21:13 -04:00
name: text("name").notNull(),
2024-11-15 21:53:58 -05:00
pubKey: text("pubKey"),
subnet: text("subnet").notNull(),
megabytesIn: integer("bytesIn"),
2024-10-01 20:48:03 -04:00
megabytesOut: integer("bytesOut"),
2024-12-19 21:27:40 -05:00
lastBandwidthUpdate: text("lastBandwidthUpdate"),
type: text("type").notNull(), // "newt" or "wireguard"
online: integer("online", { mode: "boolean" }).notNull().default(false)
2024-09-28 11:51:21 -04:00
});
export const resources = sqliteTable("resources", {
resourceId: integer("resourceId").primaryKey({ autoIncrement: true }),
siteId: integer("siteId")
.references(() => sites.siteId, {
2024-12-15 17:47:07 -05:00
onDelete: "cascade"
})
.notNull(),
orgId: text("orgId")
.references(() => orgs.orgId, {
2024-12-15 17:47:07 -05:00
onDelete: "cascade"
})
.notNull(),
2024-09-28 15:21:13 -04:00
name: text("name").notNull(),
Squashed commit of the following: commit c276d2193da5dbe7af5197bdf7e2bcce6f87b0cf Author: Owen Schwartz <owen@txv.io> Date: Tue Jan 28 22:06:04 2025 -0500 Okay actually now commit 9afdc0aadc3f4fb4e811930bacff70a9e17eab9f Author: Owen Schwartz <owen@txv.io> Date: Tue Jan 28 21:58:44 2025 -0500 Migrations working finally commit a7336b3b2466fe74d650b9c253ecadbe1eff749d Merge: e7c7203 fdb1ab4 Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 22:19:15 2025 -0500 Merge branch 'dev' into tcp-udp-traffic commit e7c7203330b1b08e570048b10ef314b55068e466 Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 22:18:09 2025 -0500 Working on migration commit a4704dfd44b10647257c7c7054c0dae806d315bb Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 21:40:52 2025 -0500 Add flag to allow raw resources commit d74f7a57ed11e2a6bf1a7e0c28c29fb07eb573a0 Merge: 6817788 d791b9b Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 21:28:50 2025 -0500 Merge branch 'tcp-udp-traffic' of https://github.com/fosrl/pangolin into tcp-udp-traffic commit 68177882781b54ef30b62cca7dee8bbed7c5a2fa Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 21:28:32 2025 -0500 Get everything working commit d791b9b47f9f6ca050d6edfd1d674438f8562d99 Author: Milo Schwartz <mschwartz10612@gmail.com> Date: Mon Jan 27 17:46:19 2025 -0500 fix orgId check in verifyAdmin commit 6ac30afd7a449a126190d311bd98d7f1048f73a4 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 23:19:33 2025 -0500 Trying to figure out traefik... commit 9886b42272882f8bb6baff2efdbe26cee7cac2b6 Merge: 786e67e 85e9129 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 21:53:32 2025 -0500 Merge branch 'tcp-udp-traffic' of https://github.com/fosrl/pangolin into tcp-udp-traffic commit 786e67eadd6df1ee8df24e77aed20c1f1fc9ca67 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 21:51:37 2025 -0500 Bug fixing commit 85e9129ae313b2e4a460a8bc53a0af9f9fbbafb2 Author: Milo Schwartz <mschwartz10612@gmail.com> Date: Sun Jan 26 18:35:24 2025 -0500 rethrow errors in migration and remove permanent redirect commit bd82699505fc7510c27f72cd80ea0ce815d8c5ef Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:49:12 2025 -0500 Fix merge issue commit 933dbf3a02b1f19fd1f627410b2407fdf05cd9bf Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:46:13 2025 -0500 Add sql to update resources and targets commit f19437bad847c8dbf57fddd2c48cd17bab20ddb0 Merge: 58980eb 9f1f291 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:19:51 2025 -0500 Merge branch 'dev' into tcp-udp-traffic commit 58980ebb64d1040b4d224c76beb38c2254f3c5d9 Merge: 1de682a d284d36 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:10:09 2025 -0500 Merge branch 'dev' into tcp-udp-traffic commit 1de682a9f6039f40e05c8901c7381a94b0d018ed Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:08:29 2025 -0500 Working on migrations commit dc853d2bc02b11997be5c3c7ea789402716fb4c2 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 16:56:49 2025 -0500 Finish config of resource pages commit 37c681c08d7ab73d2cad41e7ef1dbe3a8852e1f2 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 16:07:25 2025 -0500 Finish up table commit 461c6650bbea0d7439cc042971ec13fdb52a7431 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 15:54:46 2025 -0500 Working toward having dual resource types commit f0894663627375e16ce6994370cb30b298efc2dc Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 22:31:25 2025 -0500 Add qutoes commit edc535b79b94c2e65b290cd90a69fe17d27245e9 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 22:28:45 2025 -0500 Add readTimeout to allow long file uploads commit 194892fa14b505bd7c2b31873dc13d4b8996c0e1 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 20:37:34 2025 -0500 Rework traefik config generation commit ad3f896b5333e4706d610c3198f29dcd67610365 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 13:01:47 2025 -0500 Add proxy port to api commit ca6013b2ffda0924a696ec3141825a54a4e5297d Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 12:58:01 2025 -0500 Add migration commit 2258d76cb3a49d3db7f05f76d8b8a9f1c248b5e4 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 12:55:02 2025 -0500 Add new proxy port
2025-01-28 22:26:45 -05:00
subdomain: text("subdomain"),
fullDomain: text("fullDomain"),
2024-10-28 23:34:04 -04:00
ssl: integer("ssl", { mode: "boolean" }).notNull().default(false),
blockAccess: integer("blockAccess", { mode: "boolean" })
.notNull()
.default(false),
sso: integer("sso", { mode: "boolean" }).notNull().default(true),
Squashed commit of the following: commit c276d2193da5dbe7af5197bdf7e2bcce6f87b0cf Author: Owen Schwartz <owen@txv.io> Date: Tue Jan 28 22:06:04 2025 -0500 Okay actually now commit 9afdc0aadc3f4fb4e811930bacff70a9e17eab9f Author: Owen Schwartz <owen@txv.io> Date: Tue Jan 28 21:58:44 2025 -0500 Migrations working finally commit a7336b3b2466fe74d650b9c253ecadbe1eff749d Merge: e7c7203 fdb1ab4 Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 22:19:15 2025 -0500 Merge branch 'dev' into tcp-udp-traffic commit e7c7203330b1b08e570048b10ef314b55068e466 Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 22:18:09 2025 -0500 Working on migration commit a4704dfd44b10647257c7c7054c0dae806d315bb Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 21:40:52 2025 -0500 Add flag to allow raw resources commit d74f7a57ed11e2a6bf1a7e0c28c29fb07eb573a0 Merge: 6817788 d791b9b Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 21:28:50 2025 -0500 Merge branch 'tcp-udp-traffic' of https://github.com/fosrl/pangolin into tcp-udp-traffic commit 68177882781b54ef30b62cca7dee8bbed7c5a2fa Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 21:28:32 2025 -0500 Get everything working commit d791b9b47f9f6ca050d6edfd1d674438f8562d99 Author: Milo Schwartz <mschwartz10612@gmail.com> Date: Mon Jan 27 17:46:19 2025 -0500 fix orgId check in verifyAdmin commit 6ac30afd7a449a126190d311bd98d7f1048f73a4 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 23:19:33 2025 -0500 Trying to figure out traefik... commit 9886b42272882f8bb6baff2efdbe26cee7cac2b6 Merge: 786e67e 85e9129 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 21:53:32 2025 -0500 Merge branch 'tcp-udp-traffic' of https://github.com/fosrl/pangolin into tcp-udp-traffic commit 786e67eadd6df1ee8df24e77aed20c1f1fc9ca67 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 21:51:37 2025 -0500 Bug fixing commit 85e9129ae313b2e4a460a8bc53a0af9f9fbbafb2 Author: Milo Schwartz <mschwartz10612@gmail.com> Date: Sun Jan 26 18:35:24 2025 -0500 rethrow errors in migration and remove permanent redirect commit bd82699505fc7510c27f72cd80ea0ce815d8c5ef Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:49:12 2025 -0500 Fix merge issue commit 933dbf3a02b1f19fd1f627410b2407fdf05cd9bf Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:46:13 2025 -0500 Add sql to update resources and targets commit f19437bad847c8dbf57fddd2c48cd17bab20ddb0 Merge: 58980eb 9f1f291 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:19:51 2025 -0500 Merge branch 'dev' into tcp-udp-traffic commit 58980ebb64d1040b4d224c76beb38c2254f3c5d9 Merge: 1de682a d284d36 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:10:09 2025 -0500 Merge branch 'dev' into tcp-udp-traffic commit 1de682a9f6039f40e05c8901c7381a94b0d018ed Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:08:29 2025 -0500 Working on migrations commit dc853d2bc02b11997be5c3c7ea789402716fb4c2 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 16:56:49 2025 -0500 Finish config of resource pages commit 37c681c08d7ab73d2cad41e7ef1dbe3a8852e1f2 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 16:07:25 2025 -0500 Finish up table commit 461c6650bbea0d7439cc042971ec13fdb52a7431 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 15:54:46 2025 -0500 Working toward having dual resource types commit f0894663627375e16ce6994370cb30b298efc2dc Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 22:31:25 2025 -0500 Add qutoes commit edc535b79b94c2e65b290cd90a69fe17d27245e9 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 22:28:45 2025 -0500 Add readTimeout to allow long file uploads commit 194892fa14b505bd7c2b31873dc13d4b8996c0e1 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 20:37:34 2025 -0500 Rework traefik config generation commit ad3f896b5333e4706d610c3198f29dcd67610365 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 13:01:47 2025 -0500 Add proxy port to api commit ca6013b2ffda0924a696ec3141825a54a4e5297d Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 12:58:01 2025 -0500 Add migration commit 2258d76cb3a49d3db7f05f76d8b8a9f1c248b5e4 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 12:55:02 2025 -0500 Add new proxy port
2025-01-28 22:26:45 -05:00
http: integer("http", { mode: "boolean" }).notNull().default(true),
protocol: text("protocol").notNull(),
proxyPort: integer("proxyPort"),
2024-12-16 22:40:42 -05:00
emailWhitelistEnabled: integer("emailWhitelistEnabled", { mode: "boolean" })
.notNull()
.default(false),
2025-02-06 21:19:55 -05:00
isBaseDomain: integer("isBaseDomain", { mode: "boolean" }),
applyRules: integer("applyRules", { mode: "boolean" }).notNull().default(false)
2024-09-28 11:51:21 -04:00
});
2024-09-28 17:10:03 -04:00
export const targets = sqliteTable("targets", {
targetId: integer("targetId").primaryKey({ autoIncrement: true }),
resourceId: integer("resourceId")
.references(() => resources.resourceId, {
2024-12-15 17:47:07 -05:00
onDelete: "cascade"
})
.notNull(),
2024-09-28 17:10:03 -04:00
ip: text("ip").notNull(),
Squashed commit of the following: commit c276d2193da5dbe7af5197bdf7e2bcce6f87b0cf Author: Owen Schwartz <owen@txv.io> Date: Tue Jan 28 22:06:04 2025 -0500 Okay actually now commit 9afdc0aadc3f4fb4e811930bacff70a9e17eab9f Author: Owen Schwartz <owen@txv.io> Date: Tue Jan 28 21:58:44 2025 -0500 Migrations working finally commit a7336b3b2466fe74d650b9c253ecadbe1eff749d Merge: e7c7203 fdb1ab4 Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 22:19:15 2025 -0500 Merge branch 'dev' into tcp-udp-traffic commit e7c7203330b1b08e570048b10ef314b55068e466 Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 22:18:09 2025 -0500 Working on migration commit a4704dfd44b10647257c7c7054c0dae806d315bb Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 21:40:52 2025 -0500 Add flag to allow raw resources commit d74f7a57ed11e2a6bf1a7e0c28c29fb07eb573a0 Merge: 6817788 d791b9b Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 21:28:50 2025 -0500 Merge branch 'tcp-udp-traffic' of https://github.com/fosrl/pangolin into tcp-udp-traffic commit 68177882781b54ef30b62cca7dee8bbed7c5a2fa Author: Owen Schwartz <owen@txv.io> Date: Mon Jan 27 21:28:32 2025 -0500 Get everything working commit d791b9b47f9f6ca050d6edfd1d674438f8562d99 Author: Milo Schwartz <mschwartz10612@gmail.com> Date: Mon Jan 27 17:46:19 2025 -0500 fix orgId check in verifyAdmin commit 6ac30afd7a449a126190d311bd98d7f1048f73a4 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 23:19:33 2025 -0500 Trying to figure out traefik... commit 9886b42272882f8bb6baff2efdbe26cee7cac2b6 Merge: 786e67e 85e9129 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 21:53:32 2025 -0500 Merge branch 'tcp-udp-traffic' of https://github.com/fosrl/pangolin into tcp-udp-traffic commit 786e67eadd6df1ee8df24e77aed20c1f1fc9ca67 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 21:51:37 2025 -0500 Bug fixing commit 85e9129ae313b2e4a460a8bc53a0af9f9fbbafb2 Author: Milo Schwartz <mschwartz10612@gmail.com> Date: Sun Jan 26 18:35:24 2025 -0500 rethrow errors in migration and remove permanent redirect commit bd82699505fc7510c27f72cd80ea0ce815d8c5ef Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:49:12 2025 -0500 Fix merge issue commit 933dbf3a02b1f19fd1f627410b2407fdf05cd9bf Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:46:13 2025 -0500 Add sql to update resources and targets commit f19437bad847c8dbf57fddd2c48cd17bab20ddb0 Merge: 58980eb 9f1f291 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:19:51 2025 -0500 Merge branch 'dev' into tcp-udp-traffic commit 58980ebb64d1040b4d224c76beb38c2254f3c5d9 Merge: 1de682a d284d36 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:10:09 2025 -0500 Merge branch 'dev' into tcp-udp-traffic commit 1de682a9f6039f40e05c8901c7381a94b0d018ed Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 17:08:29 2025 -0500 Working on migrations commit dc853d2bc02b11997be5c3c7ea789402716fb4c2 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 16:56:49 2025 -0500 Finish config of resource pages commit 37c681c08d7ab73d2cad41e7ef1dbe3a8852e1f2 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 16:07:25 2025 -0500 Finish up table commit 461c6650bbea0d7439cc042971ec13fdb52a7431 Author: Owen Schwartz <owen@txv.io> Date: Sun Jan 26 15:54:46 2025 -0500 Working toward having dual resource types commit f0894663627375e16ce6994370cb30b298efc2dc Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 22:31:25 2025 -0500 Add qutoes commit edc535b79b94c2e65b290cd90a69fe17d27245e9 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 22:28:45 2025 -0500 Add readTimeout to allow long file uploads commit 194892fa14b505bd7c2b31873dc13d4b8996c0e1 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 20:37:34 2025 -0500 Rework traefik config generation commit ad3f896b5333e4706d610c3198f29dcd67610365 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 13:01:47 2025 -0500 Add proxy port to api commit ca6013b2ffda0924a696ec3141825a54a4e5297d Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 12:58:01 2025 -0500 Add migration commit 2258d76cb3a49d3db7f05f76d8b8a9f1c248b5e4 Author: Owen Schwartz <owen@txv.io> Date: Sat Jan 25 12:55:02 2025 -0500 Add new proxy port
2025-01-28 22:26:45 -05:00
method: text("method"),
2024-09-28 22:50:10 -04:00
port: integer("port").notNull(),
internalPort: integer("internalPort"),
2024-12-15 17:47:07 -05:00
enabled: integer("enabled", { mode: "boolean" }).notNull().default(true)
2024-09-28 17:10:03 -04:00
});
2024-09-28 11:51:21 -04:00
export const exitNodes = sqliteTable("exitNodes", {
2024-09-28 15:21:13 -04:00
exitNodeId: integer("exitNodeId").primaryKey({ autoIncrement: true }),
name: text("name").notNull(),
address: text("address").notNull(), // this is the address of the wireguard interface in gerbil
endpoint: text("endpoint").notNull(), // this is how to reach gerbil externally - gets put into the wireguard config
2024-10-26 12:02:21 -04:00
publicKey: text("pubicKey").notNull(),
listenPort: integer("listenPort").notNull(),
2024-12-15 17:47:07 -05:00
reachableAt: text("reachableAt") // this is the internal address of the gerbil http server for command control
2024-09-28 13:31:22 -04:00
});
2024-10-01 20:48:03 -04:00
export const users = sqliteTable("user", {
2024-10-13 17:13:47 -04:00
userId: text("id").primaryKey(),
2024-10-01 20:48:03 -04:00
email: text("email").notNull().unique(),
passwordHash: text("passwordHash").notNull(),
2024-10-02 20:19:48 -04:00
twoFactorEnabled: integer("twoFactorEnabled", { mode: "boolean" })
.notNull()
.default(false),
twoFactorSecret: text("twoFactorSecret"),
2024-10-04 23:14:40 -04:00
emailVerified: integer("emailVerified", { mode: "boolean" })
.notNull()
.default(false),
2024-12-25 15:54:32 -05:00
dateCreated: text("dateCreated").notNull(),
serverAdmin: integer("serverAdmin", { mode: "boolean" })
.notNull()
.default(false)
2024-10-01 20:48:03 -04:00
});
2024-11-10 17:08:11 -05:00
export const newts = sqliteTable("newt", {
newtId: text("id").primaryKey(),
secretHash: text("secretHash").notNull(),
dateCreated: text("dateCreated").notNull(),
siteId: integer("siteId").references(() => sites.siteId, {
onDelete: "cascade"
})
2024-11-10 17:08:11 -05:00
});
2024-10-05 15:31:28 -04:00
export const twoFactorBackupCodes = sqliteTable("twoFactorBackupCodes", {
2024-10-13 17:13:47 -04:00
codeId: integer("id").primaryKey({ autoIncrement: true }),
2024-10-05 15:31:28 -04:00
userId: text("userId")
.notNull()
2024-10-13 17:13:47 -04:00
.references(() => users.userId, { onDelete: "cascade" }),
2024-12-15 17:47:07 -05:00
codeHash: text("codeHash").notNull()
2024-10-05 15:31:28 -04:00
});
2024-10-01 20:48:03 -04:00
export const sessions = sqliteTable("session", {
2024-10-13 17:13:47 -04:00
sessionId: text("id").primaryKey(),
2024-10-01 20:48:03 -04:00
userId: text("userId")
.notNull()
2024-10-13 17:13:47 -04:00
.references(() => users.userId, { onDelete: "cascade" }),
2024-12-15 17:47:07 -05:00
expiresAt: integer("expiresAt").notNull()
2024-10-01 20:48:03 -04:00
});
2024-11-10 17:08:11 -05:00
export const newtSessions = sqliteTable("newtSession", {
sessionId: text("id").primaryKey(),
newtId: text("newtId")
.notNull()
.references(() => newts.newtId, { onDelete: "cascade" }),
2024-12-15 17:47:07 -05:00
expiresAt: integer("expiresAt").notNull()
2024-11-10 17:08:11 -05:00
});
2024-10-03 22:31:20 -04:00
export const userOrgs = sqliteTable("userOrgs", {
userId: text("userId")
.notNull()
.references(() => users.userId, { onDelete: "cascade" }),
2024-10-14 15:11:18 -04:00
orgId: text("orgId")
2024-12-24 12:24:34 -05:00
.references(() => orgs.orgId, {
onDelete: "cascade"
})
.notNull(),
2024-10-07 23:31:23 -04:00
roleId: integer("roleId")
.notNull()
.references(() => roles.roleId),
2024-12-15 17:47:07 -05:00
isOwner: integer("isOwner", { mode: "boolean" }).notNull().default(false)
2024-10-03 22:31:20 -04:00
});
2024-10-04 23:14:40 -04:00
export const emailVerificationCodes = sqliteTable("emailVerificationCodes", {
2024-10-13 17:13:47 -04:00
codeId: integer("id").primaryKey({ autoIncrement: true }),
2024-10-04 23:14:40 -04:00
userId: text("userId")
.notNull()
2024-10-13 17:13:47 -04:00
.references(() => users.userId, { onDelete: "cascade" }),
2024-10-04 23:14:40 -04:00
email: text("email").notNull(),
code: text("code").notNull(),
2024-12-15 17:47:07 -05:00
expiresAt: integer("expiresAt").notNull()
2024-10-04 23:14:40 -04:00
});
2024-10-05 17:01:49 -04:00
export const passwordResetTokens = sqliteTable("passwordResetTokens", {
2024-10-13 17:13:47 -04:00
tokenId: integer("id").primaryKey({ autoIncrement: true }),
2024-12-22 16:59:30 -05:00
email: text("email").notNull(),
2024-10-05 17:01:49 -04:00
userId: text("userId")
.notNull()
2024-10-13 17:13:47 -04:00
.references(() => users.userId, { onDelete: "cascade" }),
2024-10-05 17:01:49 -04:00
tokenHash: text("tokenHash").notNull(),
2024-12-15 17:47:07 -05:00
expiresAt: integer("expiresAt").notNull()
2024-10-05 17:01:49 -04:00
});
2024-10-05 22:45:35 -04:00
export const actions = sqliteTable("actions", {
2024-10-06 18:05:20 -04:00
actionId: text("actionId").primaryKey(),
2024-10-06 18:12:27 -04:00
name: text("name"),
2024-12-15 17:47:07 -05:00
description: text("description")
2024-10-05 22:45:35 -04:00
});
export const roles = sqliteTable("roles", {
roleId: integer("roleId").primaryKey({ autoIncrement: true }),
orgId: text("orgId")
.references(() => orgs.orgId, {
2024-12-15 17:47:07 -05:00
onDelete: "cascade"
})
.notNull(),
isAdmin: integer("isAdmin", { mode: "boolean" }),
2024-10-05 22:45:35 -04:00
name: text("name").notNull(),
2024-12-15 17:47:07 -05:00
description: text("description")
2024-10-05 22:45:35 -04:00
});
export const roleActions = sqliteTable("roleActions", {
roleId: integer("roleId")
.notNull()
.references(() => roles.roleId, { onDelete: "cascade" }),
2024-10-06 18:05:20 -04:00
actionId: text("actionId")
2024-10-05 22:45:35 -04:00
.notNull()
.references(() => actions.actionId, { onDelete: "cascade" }),
2024-10-14 15:11:18 -04:00
orgId: text("orgId")
.notNull()
2024-12-15 17:47:07 -05:00
.references(() => orgs.orgId, { onDelete: "cascade" })
2024-10-05 22:45:35 -04:00
});
export const userActions = sqliteTable("userActions", {
userId: text("userId")
.notNull()
2024-10-13 17:13:47 -04:00
.references(() => users.userId, { onDelete: "cascade" }),
2024-10-06 18:05:20 -04:00
actionId: text("actionId")
2024-10-05 22:45:35 -04:00
.notNull()
.references(() => actions.actionId, { onDelete: "cascade" }),
2024-10-14 15:11:18 -04:00
orgId: text("orgId")
.notNull()
2024-12-15 17:47:07 -05:00
.references(() => orgs.orgId, { onDelete: "cascade" })
2024-10-05 22:45:35 -04:00
});
export const roleSites = sqliteTable("roleSites", {
roleId: integer("roleId")
2024-10-05 22:45:35 -04:00
.notNull()
.references(() => roles.roleId, { onDelete: "cascade" }),
siteId: integer("siteId")
.notNull()
2024-12-15 17:47:07 -05:00
.references(() => sites.siteId, { onDelete: "cascade" })
2024-10-05 22:45:35 -04:00
});
export const userSites = sqliteTable("userSites", {
userId: text("userId")
2024-10-05 22:45:35 -04:00
.notNull()
2024-10-13 17:13:47 -04:00
.references(() => users.userId, { onDelete: "cascade" }),
2024-10-05 22:45:35 -04:00
siteId: integer("siteId")
.notNull()
2024-12-15 17:47:07 -05:00
.references(() => sites.siteId, { onDelete: "cascade" })
2024-10-05 22:45:35 -04:00
});
export const roleResources = sqliteTable("roleResources", {
roleId: integer("roleId")
2024-10-05 22:45:35 -04:00
.notNull()
.references(() => roles.roleId, { onDelete: "cascade" }),
2024-10-26 12:15:03 -04:00
resourceId: integer("resourceId")
2024-10-05 22:45:35 -04:00
.notNull()
2024-12-15 17:47:07 -05:00
.references(() => resources.resourceId, { onDelete: "cascade" })
2024-10-05 22:45:35 -04:00
});
export const userResources = sqliteTable("userResources", {
userId: text("userId")
2024-10-05 22:45:35 -04:00
.notNull()
2024-10-13 17:13:47 -04:00
.references(() => users.userId, { onDelete: "cascade" }),
2024-10-26 12:15:03 -04:00
resourceId: integer("resourceId")
2024-10-05 22:45:35 -04:00
.notNull()
2024-12-15 17:47:07 -05:00
.references(() => resources.resourceId, { onDelete: "cascade" })
2024-10-05 22:45:35 -04:00
});
2024-10-06 17:42:28 -04:00
export const limitsTable = sqliteTable("limits", {
limitId: integer("limitId").primaryKey({ autoIncrement: true }),
orgId: text("orgId")
.references(() => orgs.orgId, {
2024-12-15 17:47:07 -05:00
onDelete: "cascade"
})
.notNull(),
2024-10-06 17:42:28 -04:00
name: text("name").notNull(),
value: integer("value").notNull(),
2024-12-15 17:47:07 -05:00
description: text("description")
2024-10-06 17:42:28 -04:00
});
export const userInvites = sqliteTable("userInvites", {
inviteId: text("inviteId").primaryKey(),
orgId: text("orgId")
.notNull()
2024-11-02 23:46:08 -04:00
.references(() => orgs.orgId, { onDelete: "cascade" }),
email: text("email").notNull(),
expiresAt: integer("expiresAt").notNull(),
tokenHash: text("token").notNull(),
roleId: integer("roleId")
.notNull()
2024-12-15 17:47:07 -05:00
.references(() => roles.roleId, { onDelete: "cascade" })
});
export const resourcePincode = sqliteTable("resourcePincode", {
pincodeId: integer("pincodeId").primaryKey({
2024-12-15 17:47:07 -05:00
autoIncrement: true
}),
resourceId: integer("resourceId")
.notNull()
.references(() => resources.resourceId, { onDelete: "cascade" }),
pincodeHash: text("pincodeHash").notNull(),
2024-12-15 17:47:07 -05:00
digitLength: integer("digitLength").notNull()
});
export const resourcePassword = sqliteTable("resourcePassword", {
passwordId: integer("passwordId").primaryKey({
2024-12-15 17:47:07 -05:00
autoIncrement: true
}),
resourceId: integer("resourceId")
.notNull()
.references(() => resources.resourceId, { onDelete: "cascade" }),
2024-12-15 17:47:07 -05:00
passwordHash: text("passwordHash").notNull()
});
export const resourceAccessToken = sqliteTable("resourceAccessToken", {
accessTokenId: text("accessTokenId").primaryKey(),
orgId: text("orgId")
.notNull()
.references(() => orgs.orgId, { onDelete: "cascade" }),
resourceId: integer("resourceId")
.notNull()
.references(() => resources.resourceId, { onDelete: "cascade" }),
tokenHash: text("tokenHash").notNull(),
sessionLength: integer("sessionLength").notNull(),
expiresAt: integer("expiresAt"),
2024-12-20 22:24:44 -05:00
title: text("title"),
description: text("description"),
createdAt: integer("createdAt").notNull()
});
export const resourceSessions = sqliteTable("resourceSessions", {
sessionId: text("id").primaryKey(),
resourceId: integer("resourceId")
.notNull()
.references(() => resources.resourceId, { onDelete: "cascade" }),
expiresAt: integer("expiresAt").notNull(),
sessionLength: integer("sessionLength").notNull(),
doNotExtend: integer("doNotExtend", { mode: "boolean" })
.notNull()
.default(false),
isRequestToken: integer("isRequestToken", { mode: "boolean" }),
userSessionId: text("userSessionId").references(() => sessions.sessionId, {
onDelete: "cascade"
}),
passwordId: integer("passwordId").references(
() => resourcePassword.passwordId,
{
2024-12-15 17:47:07 -05:00
onDelete: "cascade"
}
),
pincodeId: integer("pincodeId").references(
() => resourcePincode.pincodeId,
{
2024-12-15 17:47:07 -05:00
onDelete: "cascade"
}
),
2024-12-15 17:47:07 -05:00
whitelistId: integer("whitelistId").references(
2024-12-16 22:40:42 -05:00
() => resourceWhitelist.whitelistId,
2024-12-15 17:47:07 -05:00
{
onDelete: "cascade"
}
),
accessTokenId: text("accessTokenId").references(
() => resourceAccessToken.accessTokenId,
{
onDelete: "cascade"
}
2024-12-15 17:47:07 -05:00
)
});
2024-12-16 22:40:42 -05:00
export const resourceWhitelist = sqliteTable("resourceWhitelist", {
whitelistId: integer("id").primaryKey({ autoIncrement: true }),
email: text("email").notNull(),
resourceId: integer("resourceId")
.notNull()
.references(() => resources.resourceId, { onDelete: "cascade" })
});
2024-12-15 17:47:07 -05:00
2024-11-30 23:51:22 -05:00
export const resourceOtp = sqliteTable("resourceOtp", {
otpId: integer("otpId").primaryKey({
2024-12-15 17:47:07 -05:00
autoIncrement: true
2024-11-30 23:51:22 -05:00
}),
resourceId: integer("resourceId")
.notNull()
.references(() => resources.resourceId, { onDelete: "cascade" }),
email: text("email").notNull(),
otpHash: text("otpHash").notNull(),
2024-12-15 17:47:07 -05:00
expiresAt: integer("expiresAt").notNull()
2024-11-30 23:51:22 -05:00
});
2024-12-25 15:49:35 -05:00
export const versionMigrations = sqliteTable("versionMigrations", {
version: text("version").primaryKey(),
executedAt: integer("executedAt").notNull()
});
export const resourceRules = sqliteTable("resourceRules", {
2025-02-06 21:18:34 -05:00
ruleId: integer("ruleId").primaryKey({ autoIncrement: true }),
resourceId: integer("resourceId")
.notNull()
.references(() => resources.resourceId, { onDelete: "cascade" }),
enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
priority: integer("priority").notNull(),
2025-02-06 21:18:34 -05:00
action: text("action").notNull(), // ACCEPT, DROP
2025-02-10 21:06:37 -05:00
match: text("match").notNull(), // CIDR, PATH, IP
2025-02-06 21:18:34 -05:00
value: text("value").notNull()
});
2024-09-28 13:31:22 -04:00
export type Org = InferSelectModel<typeof orgs>;
2024-09-28 11:51:21 -04:00
export type User = InferSelectModel<typeof users>;
export type Site = InferSelectModel<typeof sites>;
export type Resource = InferSelectModel<typeof resources>;
export type ExitNode = InferSelectModel<typeof exitNodes>;
2024-09-28 22:50:10 -04:00
export type Target = InferSelectModel<typeof targets>;
2024-10-01 20:48:03 -04:00
export type Session = InferSelectModel<typeof sessions>;
2024-11-10 17:08:11 -05:00
export type Newt = InferSelectModel<typeof newts>;
export type NewtSession = InferSelectModel<typeof newtSessions>;
2024-10-04 23:14:40 -04:00
export type EmailVerificationCode = InferSelectModel<
typeof emailVerificationCodes
>;
2024-10-05 15:31:28 -04:00
export type TwoFactorBackupCode = InferSelectModel<typeof twoFactorBackupCodes>;
2024-10-05 17:01:49 -04:00
export type PasswordResetToken = InferSelectModel<typeof passwordResetTokens>;
2024-10-05 22:45:35 -04:00
export type Role = InferSelectModel<typeof roles>;
export type Action = InferSelectModel<typeof actions>;
export type RoleAction = InferSelectModel<typeof roleActions>;
export type UserAction = InferSelectModel<typeof userActions>;
export type RoleSite = InferSelectModel<typeof roleSites>;
export type UserSite = InferSelectModel<typeof userSites>;
export type RoleResource = InferSelectModel<typeof roleResources>;
2024-10-06 17:42:28 -04:00
export type UserResource = InferSelectModel<typeof userResources>;
2024-10-07 23:31:23 -04:00
export type Limit = InferSelectModel<typeof limitsTable>;
export type UserInvite = InferSelectModel<typeof userInvites>;
export type UserOrg = InferSelectModel<typeof userOrgs>;
export type ResourceSession = InferSelectModel<typeof resourceSessions>;
export type ResourcePincode = InferSelectModel<typeof resourcePincode>;
export type ResourcePassword = InferSelectModel<typeof resourcePassword>;
2024-11-30 23:51:22 -05:00
export type ResourceOtp = InferSelectModel<typeof resourceOtp>;
2024-12-20 22:24:44 -05:00
export type ResourceAccessToken = InferSelectModel<typeof resourceAccessToken>;
2024-12-25 16:40:39 -05:00
export type ResourceWhitelist = InferSelectModel<typeof resourceWhitelist>;
export type VersionMigration = InferSelectModel<typeof versionMigrations>;
export type ResourceRule = InferSelectModel<typeof resourceRules>;