Files
Termix/src/backend/database/db/schema.ts
T

575 lines
18 KiB
TypeScript
Raw Normal View History

2025-09-12 14:42:00 -05:00
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
import { sql } from "drizzle-orm";
2025-08-07 02:20:27 -05:00
2025-09-12 14:42:00 -05:00
export const users = sqliteTable("users", {
id: text("id").primaryKey(),
username: text("username").notNull(),
+5
2026-03-08 18:02:14 -05:00
passwordHash: text("password_hash").notNull(),
isAdmin: integer("is_admin", { mode: "boolean" }).notNull().default(false),
2025-08-07 02:20:27 -05:00
+5
2026-03-08 18:02:14 -05:00
isOidc: integer("is_oidc", { mode: "boolean" }).notNull().default(false),
oidcIdentifier: text("oidc_identifier"),
clientId: text("client_id"),
clientSecret: text("client_secret"),
issuerUrl: text("issuer_url"),
authorizationUrl: text("authorization_url"),
tokenUrl: text("token_url"),
identifierPath: text("identifier_path"),
namePath: text("name_path"),
2025-09-12 14:42:00 -05:00
scopes: text().default("openid email profile"),
+5
2026-03-08 18:02:14 -05:00
totpSecret: text("totp_secret"),
totpEnabled: integer("totp_enabled", { mode: "boolean" })
2025-09-12 14:42:00 -05:00
.notNull()
.default(false),
+5
2026-03-08 18:02:14 -05:00
totpBackupCodes: text("totp_backup_codes"),
2025-08-07 02:20:27 -05:00
});
2025-09-12 14:42:00 -05:00
export const settings = sqliteTable("settings", {
key: text("key").primaryKey(),
value: text("value").notNull(),
2025-08-07 02:20:27 -05:00
});
+7
2025-11-05 10:36:16 -06:00
export const sessions = sqliteTable("sessions", {
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
2025-11-17 09:46:05 -06:00
.references(() => users.id, { onDelete: "cascade" }),
+7
2025-11-05 10:36:16 -06:00
jwtToken: text("jwt_token").notNull(),
deviceType: text("device_type").notNull(),
deviceInfo: text("device_info").notNull(),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
expiresAt: text("expires_at").notNull(),
lastActiveAt: text("last_active_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
+5
2026-03-08 18:02:14 -05:00
export const trustedDevices = sqliteTable("trusted_devices", {
id: text("id").primaryKey(),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
deviceFingerprint: text("device_fingerprint").notNull(),
deviceType: text("device_type").notNull(),
deviceInfo: text("device_info").notNull(),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
expiresAt: text("expires_at").notNull(),
lastUsedAt: text("last_used_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
2026-03-14 20:05:05 -05:00
export const hosts = sqliteTable("ssh_data", {
2025-09-12 14:42:00 -05:00
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
2025-11-17 09:46:05 -06:00
.references(() => users.id, { onDelete: "cascade" }),
2026-03-14 20:05:05 -05:00
connectionType: text("connection_type").notNull().default("ssh"),
2025-09-12 14:42:00 -05:00
name: text("name"),
ip: text("ip").notNull(),
port: integer("port").notNull(),
username: text("username").notNull(),
folder: text("folder"),
tags: text("tags"),
pin: integer("pin", { mode: "boolean" }).notNull().default(false),
authType: text("auth_type").notNull(),
+7
2025-11-05 10:36:16 -06:00
forceKeyboardInteractive: text("force_keyboard_interactive"),
2025-09-12 14:42:00 -05:00
password: text("password"),
key: text("key", { length: 8192 }),
+5
2026-03-08 18:02:14 -05:00
keyPassword: text("key_password"),
2025-09-12 14:42:00 -05:00
keyType: text("key_type"),
+1
2025-12-31 22:20:12 -06:00
sudoPassword: text("sudo_password"),
2025-09-12 14:42:00 -05:00
2025-10-01 15:40:10 -05:00
autostartPassword: text("autostart_password"),
autostartKey: text("autostart_key", { length: 8192 }),
autostartKeyPassword: text("autostart_key_password"),
2025-11-17 09:46:05 -06:00
credentialId: integer("credential_id").references(() => sshCredentials.id, { onDelete: "set null" }),
overrideCredentialUsername: integer("override_credential_username", {
mode: "boolean",
}),
2025-09-12 14:42:00 -05:00
enableTerminal: integer("enable_terminal", { mode: "boolean" })
.notNull()
.default(true),
enableTunnel: integer("enable_tunnel", { mode: "boolean" })
.notNull()
.default(true),
tunnelConnections: text("tunnel_connections"),
2025-11-17 09:46:05 -06:00
jumpHosts: text("jump_hosts"),
2025-09-12 14:42:00 -05:00
enableFileManager: integer("enable_file_manager", { mode: "boolean" })
.notNull()
.default(true),
+1
2025-12-31 22:20:12 -06:00
enableDocker: integer("enable_docker", { mode: "boolean" })
.notNull()
.default(false),
2026-01-24 19:49:42 -06:00
showTerminalInSidebar: integer("show_terminal_in_sidebar", { mode: "boolean" })
.notNull()
.default(true),
showFileManagerInSidebar: integer("show_file_manager_in_sidebar", { mode: "boolean" })
.notNull()
.default(false),
showTunnelInSidebar: integer("show_tunnel_in_sidebar", { mode: "boolean" })
.notNull()
.default(false),
showDockerInSidebar: integer("show_docker_in_sidebar", { mode: "boolean" })
.notNull()
.default(false),
showServerStatsInSidebar: integer("show_server_stats_in_sidebar", { mode: "boolean" })
.notNull()
.default(false),
2025-09-12 14:42:00 -05:00
defaultPath: text("default_path"),
+7
2025-11-05 10:36:16 -06:00
statsConfig: text("stats_config"),
2026-03-14 20:05:05 -05:00
dockerConfig: text("docker_config"),
+7
2025-11-05 10:36:16 -06:00
terminalConfig: text("terminal_config"),
2025-11-17 09:46:05 -06:00
quickActions: text("quick_actions"),
+1
2025-12-31 22:20:12 -06:00
notes: text("notes"),
2026-03-14 20:05:05 -05:00
domain: text("domain"),
security: text("security"),
ignoreCert: integer("ignore_cert", { mode: "boolean" }).default(false),
guacamoleConfig: text("guacamole_config"),
+1
2025-12-31 22:20:12 -06:00
useSocks5: integer("use_socks5", { mode: "boolean" }),
socks5Host: text("socks5_host"),
socks5Port: integer("socks5_port"),
socks5Username: text("socks5_username"),
socks5Password: text("socks5_password"),
socks5ProxyChain: text("socks5_proxy_chain"),
+9
2026-04-22 16:55:23 -05:00
macAddress: text("mac_address"),
portKnockSequence: text("port_knock_sequence"),
+4
2026-02-12 22:28:13 -06:00
hostKeyFingerprint: text("host_key_fingerprint"),
hostKeyType: text("host_key_type"),
hostKeyAlgorithm: text("host_key_algorithm").default("sha256"),
hostKeyFirstSeen: text("host_key_first_seen"),
hostKeyLastVerified: text("host_key_last_verified"),
hostKeyChangedCount: integer("host_key_changed_count").default(0),
2025-09-12 14:42:00 -05:00
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updatedAt: text("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
2025-08-07 02:20:27 -05:00
});
2025-09-12 14:42:00 -05:00
export const fileManagerRecent = sqliteTable("file_manager_recent", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
2025-11-17 09:46:05 -06:00
.references(() => users.id, { onDelete: "cascade" }),
2025-09-12 14:42:00 -05:00
hostId: integer("host_id")
.notNull()
2026-03-14 20:05:05 -05:00
.references(() => hosts.id, { onDelete: "cascade" }),
2025-09-12 14:42:00 -05:00
name: text("name").notNull(),
path: text("path").notNull(),
lastOpened: text("last_opened")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
2025-08-07 02:20:27 -05:00
});
2025-09-12 14:42:00 -05:00
export const fileManagerPinned = sqliteTable("file_manager_pinned", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
2025-11-17 09:46:05 -06:00
.references(() => users.id, { onDelete: "cascade" }),
2025-09-12 14:42:00 -05:00
hostId: integer("host_id")
.notNull()
2026-03-14 20:05:05 -05:00
.references(() => hosts.id, { onDelete: "cascade" }),
2025-09-12 14:42:00 -05:00
name: text("name").notNull(),
path: text("path").notNull(),
pinnedAt: text("pinned_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
2025-08-07 02:20:27 -05:00
});
2025-09-12 14:42:00 -05:00
export const fileManagerShortcuts = sqliteTable("file_manager_shortcuts", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
2025-11-17 09:46:05 -06:00
.references(() => users.id, { onDelete: "cascade" }),
2025-09-12 14:42:00 -05:00
hostId: integer("host_id")
.notNull()
2026-03-14 20:05:05 -05:00
.references(() => hosts.id, { onDelete: "cascade" }),
2025-09-12 14:42:00 -05:00
name: text("name").notNull(),
path: text("path").notNull(),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
2025-09-12 14:42:00 -05:00
export const dismissedAlerts = sqliteTable("dismissed_alerts", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
2025-11-17 09:46:05 -06:00
.references(() => users.id, { onDelete: "cascade" }),
2025-09-12 14:42:00 -05:00
alertId: text("alert_id").notNull(),
dismissedAt: text("dismissed_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
export const sshCredentials = sqliteTable("ssh_credentials", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
2025-11-17 09:46:05 -06:00
.references(() => users.id, { onDelete: "cascade" }),
2025-09-12 14:42:00 -05:00
name: text("name").notNull(),
description: text("description"),
folder: text("folder"),
tags: text("tags"),
authType: text("auth_type").notNull(),
+4
2026-02-12 22:28:13 -06:00
username: text("username"),
2025-09-12 14:42:00 -05:00
password: text("password"),
key: text("key", { length: 16384 }),
+5
2026-03-08 18:02:14 -05:00
privateKey: text("private_key", { length: 16384 }),
publicKey: text("public_key", { length: 4096 }),
keyPassword: text("key_password"),
2025-09-12 14:42:00 -05:00
keyType: text("key_type"),
2025-10-01 15:40:10 -05:00
detectedKeyType: text("detected_key_type"),
+1
2025-12-31 22:20:12 -06:00
systemPassword: text("system_password"),
systemKey: text("system_key", { length: 16384 }),
systemKeyPassword: text("system_key_password"),
2025-09-12 14:42:00 -05:00
usageCount: integer("usage_count").notNull().default(0),
lastUsed: text("last_used"),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updatedAt: text("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
export const sshCredentialUsage = sqliteTable("ssh_credential_usage", {
id: integer("id").primaryKey({ autoIncrement: true }),
credentialId: integer("credential_id")
.notNull()
2025-11-17 09:46:05 -06:00
.references(() => sshCredentials.id, { onDelete: "cascade" }),
2025-09-12 14:42:00 -05:00
hostId: integer("host_id")
.notNull()
2026-03-14 20:05:05 -05:00
.references(() => hosts.id, { onDelete: "cascade" }),
2025-09-12 14:42:00 -05:00
userId: text("user_id")
.notNull()
2025-11-17 09:46:05 -06:00
.references(() => users.id, { onDelete: "cascade" }),
2025-09-12 14:42:00 -05:00
usedAt: text("used_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
+7
2025-11-05 10:36:16 -06:00
export const snippets = sqliteTable("snippets", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
2025-11-17 09:46:05 -06:00
.references(() => users.id, { onDelete: "cascade" }),
+7
2025-11-05 10:36:16 -06:00
name: text("name").notNull(),
content: text("content").notNull(),
description: text("description"),
2025-11-17 09:46:05 -06:00
folder: text("folder"),
order: integer("order").notNull().default(0),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updatedAt: text("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
export const snippetFolders = sqliteTable("snippet_folders", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
name: text("name").notNull(),
color: text("color"),
icon: text("icon"),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updatedAt: text("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
+9
2026-04-22 16:55:23 -05:00
export const snippetAccess = sqliteTable("snippet_access", {
id: integer("id").primaryKey({ autoIncrement: true }),
snippetId: integer("snippet_id")
.notNull()
.references(() => snippets.id, { onDelete: "cascade" }),
userId: text("user_id").references(() => users.id, { onDelete: "cascade" }),
roleId: integer("role_id").references(() => roles.id, {
onDelete: "cascade",
}),
grantedBy: text("granted_by")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
permissionLevel: text("permission_level").notNull().default("view"),
expiresAt: text("expires_at"),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
2025-11-17 09:46:05 -06:00
export const sshFolders = sqliteTable("ssh_folders", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
name: text("name").notNull(),
color: text("color"),
icon: text("icon"),
+7
2025-11-05 10:36:16 -06:00
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updatedAt: text("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
export const recentActivity = sqliteTable("recent_activity", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
2025-11-17 09:46:05 -06:00
.references(() => users.id, { onDelete: "cascade" }),
+7
2025-11-05 10:36:16 -06:00
type: text("type").notNull(),
hostId: integer("host_id")
.notNull()
2026-03-14 20:05:05 -05:00
.references(() => hosts.id, { onDelete: "cascade" }),
2025-11-17 09:46:05 -06:00
hostName: text("host_name"),
+7
2025-11-05 10:36:16 -06:00
timestamp: text("timestamp")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
2025-11-17 09:46:05 -06:00
export const commandHistory = sqliteTable("command_history", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
hostId: integer("host_id")
.notNull()
2026-03-14 20:05:05 -05:00
.references(() => hosts.id, { onDelete: "cascade" }),
2025-11-17 09:46:05 -06:00
command: text("command").notNull(),
executedAt: text("executed_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
+1
2025-12-31 22:20:12 -06:00
2026-01-24 19:49:42 -06:00
export const networkTopology = sqliteTable("network_topology", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
topology: text("topology"),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updatedAt: text("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
export const dashboardPreferences = sqliteTable("dashboard_preferences", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
.unique()
.references(() => users.id, { onDelete: "cascade" }),
layout: text("layout").notNull(),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updatedAt: text("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
+1
2025-12-31 22:20:12 -06:00
export const hostAccess = sqliteTable("host_access", {
id: integer("id").primaryKey({ autoIncrement: true }),
hostId: integer("host_id")
.notNull()
2026-03-14 20:05:05 -05:00
.references(() => hosts.id, { onDelete: "cascade" }),
+1
2025-12-31 22:20:12 -06:00
userId: text("user_id")
.references(() => users.id, { onDelete: "cascade" }),
roleId: integer("role_id")
.references(() => roles.id, { onDelete: "cascade" }),
grantedBy: text("granted_by")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
permissionLevel: text("permission_level")
.notNull()
.default("view"),
expiresAt: text("expires_at"),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
lastAccessedAt: text("last_accessed_at"),
accessCount: integer("access_count").notNull().default(0),
});
export const sharedCredentials = sqliteTable("shared_credentials", {
id: integer("id").primaryKey({ autoIncrement: true }),
hostAccessId: integer("host_access_id")
.notNull()
.references(() => hostAccess.id, { onDelete: "cascade" }),
originalCredentialId: integer("original_credential_id")
.notNull()
.references(() => sshCredentials.id, { onDelete: "cascade" }),
targetUserId: text("target_user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
encryptedUsername: text("encrypted_username").notNull(),
encryptedAuthType: text("encrypted_auth_type").notNull(),
encryptedPassword: text("encrypted_password"),
encryptedKey: text("encrypted_key", { length: 16384 }),
encryptedKeyPassword: text("encrypted_key_password"),
encryptedKeyType: text("encrypted_key_type"),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updatedAt: text("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
needsReEncryption: integer("needs_re_encryption", { mode: "boolean" })
.notNull()
.default(false),
});
export const roles = sqliteTable("roles", {
id: integer("id").primaryKey({ autoIncrement: true }),
name: text("name").notNull().unique(),
displayName: text("display_name").notNull(),
description: text("description"),
isSystem: integer("is_system", { mode: "boolean" })
.notNull()
.default(false),
permissions: text("permissions"),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updatedAt: text("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
export const userRoles = sqliteTable("user_roles", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
roleId: integer("role_id")
.notNull()
.references(() => roles.id, { onDelete: "cascade" }),
grantedBy: text("granted_by").references(() => users.id, {
onDelete: "set null",
}),
grantedAt: text("granted_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
export const auditLogs = sqliteTable("audit_logs", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
username: text("username").notNull(),
action: text("action").notNull(),
resourceType: text("resource_type").notNull(),
resourceId: text("resource_id"),
resourceName: text("resource_name"),
details: text("details"),
ipAddress: text("ip_address"),
userAgent: text("user_agent"),
success: integer("success", { mode: "boolean" }).notNull(),
errorMessage: text("error_message"),
timestamp: text("timestamp")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
});
export const sessionRecordings = sqliteTable("session_recordings", {
id: integer("id").primaryKey({ autoIncrement: true }),
hostId: integer("host_id")
.notNull()
2026-03-14 20:05:05 -05:00
.references(() => hosts.id, { onDelete: "cascade" }),
+1
2025-12-31 22:20:12 -06:00
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
accessId: integer("access_id").references(() => hostAccess.id, {
onDelete: "set null",
}),
startedAt: text("started_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
endedAt: text("ended_at"),
duration: integer("duration"),
commands: text("commands"),
dangerousActions: text("dangerous_actions"),
recordingPath: text("recording_path"),
terminatedByOwner: integer("terminated_by_owner", { mode: "boolean" })
.default(false),
terminationReason: text("termination_reason"),
});
+4
2026-02-12 22:28:13 -06:00
export const opksshTokens = sqliteTable("opkssh_tokens", {
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id")
.notNull()
.references(() => users.id, { onDelete: "cascade" }),
hostId: integer("host_id")
.notNull()
2026-03-14 20:05:05 -05:00
.references(() => hosts.id, { onDelete: "cascade" }),
+4
2026-02-12 22:28:13 -06:00
sshCert: text("ssh_cert", { length: 8192 }).notNull(),
privateKey: text("private_key", { length: 8192 }).notNull(),
email: text("email"),
sub: text("sub"),
issuer: text("issuer"),
audience: text("audience"),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
expiresAt: text("expires_at").notNull(),
lastUsed: text("last_used"),
});