feat: finish the fleets plugin, add ctx.hosts and host-commands SDK (B4)

This commit is contained in:
LukeGus committed 2026-09-23 13:10:18 -05:00
1 parent 37c015a760
commit c381955ed0
43 files changed
+835 -1999

No files matched your search

-54
View File
@@ -846,20 +846,6 @@ async function initializeCompleteDatabase(): Promise<void> {
CREATE UNIQUE INDEX IF NOT EXISTS idx_host_metrics_prefs_user_host
ON host_metrics_preferences (user_id, host_id);
CREATE TABLE IF NOT EXISTS proxmox_stats_preferences (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id TEXT NOT NULL,
host_id INTEGER NOT NULL,
layout TEXT NOT NULL,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE,
FOREIGN KEY (host_id) REFERENCES ssh_data (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_proxmox_stats_prefs_user_host
ON proxmox_stats_preferences (user_id, host_id);
CREATE TABLE IF NOT EXISTS host_sidebar_preferences (
user_id TEXT PRIMARY KEY,
data TEXT NOT NULL,
@@ -1342,18 +1328,6 @@ const migrateSchema = () => {
"INTEGER NOT NULL DEFAULT 0",
);
addColumnIfNotExists("ssh_data", "web_ui_config", "TEXT");
addColumnIfNotExists(
"ssh_data",
"enable_proxmox",
"INTEGER NOT NULL DEFAULT 0",
);
addColumnIfNotExists("ssh_data", "proxmox_config", "TEXT");
addColumnIfNotExists(
"ssh_data",
"enable_proxmox_stats",
"INTEGER NOT NULL DEFAULT 0",
);
addColumnIfNotExists("ssh_data", "proxmox_stats_config", "TEXT");
addColumnIfNotExists(
"ssh_data",
"enable_tmux_monitor",
@@ -2381,34 +2355,6 @@ const migrateSchema = () => {
}
// --- metrics-history end ---
// --- proxmox-node-history begin ---
try {
sqlite.prepare("SELECT id FROM proxmox_node_history LIMIT 1").get();
} catch {
try {
sqlite.exec(`
CREATE TABLE IF NOT EXISTS proxmox_node_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
host_id INTEGER NOT NULL REFERENCES ssh_data(id) ON DELETE CASCADE,
ts TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
cpu_percent REAL,
mem_percent REAL,
disk_percent REAL,
net_rx_bytes INTEGER,
net_tx_bytes INTEGER
);
CREATE INDEX IF NOT EXISTS idx_proxmox_node_history_host_ts
ON proxmox_node_history (host_id, ts DESC);
`);
} catch (createError) {
databaseLogger.warn("Failed to create proxmox_node_history table", {
operation: "schema_migration",
error: createError,
});
}
}
// --- proxmox-node-history end ---
// --- alerts begin ---
// alert_rules, alert_rule_channels and alert_firings were only ever created
// here, never declared in schema.ts, so they never existed on Postgres or
-46
View File
@@ -298,14 +298,6 @@ export const hosts = mysqlTable(
statsConfig: text("stats_config"),
dockerConfig: text("docker_config"),
webUiConfig: text("web_ui_config"),
enableProxmox: boolean("enable_proxmox")
.notNull()
.default(false),
proxmoxConfig: text("proxmox_config"),
enableProxmoxStats: boolean("enable_proxmox_stats")
.notNull()
.default(false),
proxmoxStatsConfig: text("proxmox_stats_config"),
terminalConfig: text("terminal_config"),
quickActions: text("quick_actions"),
notes: text("notes"),
@@ -1161,27 +1153,6 @@ export const hostMetricsPreferences = mysqlTable(
],
);
export const proxmoxStatsPreferences = mysqlTable(
"proxmox_stats_preferences",
{
id: int("id").autoincrement().primaryKey(),
userId: varchar("user_id", { length: 255 }).notNull().references(() => users.id, { onDelete: "cascade" }),
hostId: int("host_id").notNull().references(() => hosts.id, { onDelete: "cascade" }),
// JSON-encoded ProxmoxStatsLayout. Layout has no secrets, so it is stored as
// plain JSON (no field-level encryption), same convention as hostMetricsPreferences.layout.
layout: text("layout").notNull(),
createdAt: varchar("created_at", { length: 255 })
.notNull()
.default(sql`(CURRENT_TIMESTAMP)`),
updatedAt: varchar("updated_at", { length: 255 })
.notNull()
.default(sql`(CURRENT_TIMESTAMP)`),
},
(table) => [
uniqueIndex("idx_proxmox_stats_prefs_user_host").on(table.userId, table.hostId),
],
);
export const hostSidebarPreferences = mysqlTable("host_sidebar_preferences", {
userId: varchar("user_id", { length: 255 })
.primaryKey()
@@ -1387,23 +1358,6 @@ export const hostMetricsHistory = mysqlTable("host_metrics_history", {
});
// --- metrics-history end ---
// --- proxmox-node-history begin ---
export const proxmoxNodeHistory = mysqlTable("proxmox_node_history", {
id: int("id").autoincrement().primaryKey(),
hostId: int("host_id")
.notNull()
.references(() => hosts.id, { onDelete: "cascade" }),
ts: text("ts")
.notNull()
.default(sql`(CURRENT_TIMESTAMP)`),
cpuPercent: double("cpu_percent"),
memPercent: double("mem_percent"),
diskPercent: double("disk_percent"),
netRxBytes: int("net_rx_bytes"),
netTxBytes: int("net_tx_bytes"),
});
// --- proxmox-node-history end ---
// --- alerts begin ---
export const notificationChannels = mysqlTable("notification_channels", {
id: int("id").autoincrement().primaryKey(),
-46
View File
@@ -299,14 +299,6 @@ export const hosts = pgTable(
statsConfig: text("stats_config"),
dockerConfig: text("docker_config"),
webUiConfig: text("web_ui_config"),
enableProxmox: boolean("enable_proxmox")
.notNull()
.default(false),
proxmoxConfig: text("proxmox_config"),
enableProxmoxStats: boolean("enable_proxmox_stats")
.notNull()
.default(false),
proxmoxStatsConfig: text("proxmox_stats_config"),
terminalConfig: text("terminal_config"),
quickActions: text("quick_actions"),
notes: text("notes"),
@@ -1162,27 +1154,6 @@ export const hostMetricsPreferences = pgTable(
],
);
export const proxmoxStatsPreferences = pgTable(
"proxmox_stats_preferences",
{
id: serial("id").primaryKey(),
userId: varchar("user_id", { length: 255 }).notNull().references(() => users.id, { onDelete: "cascade" }),
hostId: integer("host_id").notNull().references(() => hosts.id, { onDelete: "cascade" }),
// JSON-encoded ProxmoxStatsLayout. Layout has no secrets, so it is stored as
// plain JSON (no field-level encryption), same convention as hostMetricsPreferences.layout.
layout: text("layout").notNull(),
createdAt: varchar("created_at", { length: 255 })
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updatedAt: varchar("updated_at", { length: 255 })
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
},
(table) => [
uniqueIndex("idx_proxmox_stats_prefs_user_host").on(table.userId, table.hostId),
],
);
export const hostSidebarPreferences = pgTable("host_sidebar_preferences", {
userId: varchar("user_id", { length: 255 })
.primaryKey()
@@ -1388,23 +1359,6 @@ export const hostMetricsHistory = pgTable("host_metrics_history", {
});
// --- metrics-history end ---
// --- proxmox-node-history begin ---
export const proxmoxNodeHistory = pgTable("proxmox_node_history", {
id: serial("id").primaryKey(),
hostId: integer("host_id")
.notNull()
.references(() => hosts.id, { onDelete: "cascade" }),
ts: text("ts")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
cpuPercent: doublePrecision("cpu_percent"),
memPercent: doublePrecision("mem_percent"),
diskPercent: doublePrecision("disk_percent"),
netRxBytes: integer("net_rx_bytes"),
netTxBytes: integer("net_tx_bytes"),
});
// --- proxmox-node-history end ---
// --- alerts begin ---
export const notificationChannels = pgTable("notification_channels", {
id: serial("id").primaryKey(),
-46
View File
@@ -291,14 +291,6 @@ export const hosts = sqliteTable(
statsConfig: text("stats_config"),
dockerConfig: text("docker_config"),
webUiConfig: text("web_ui_config"),
enableProxmox: integer("enable_proxmox", { mode: "boolean" })
.notNull()
.default(false),
proxmoxConfig: text("proxmox_config"),
enableProxmoxStats: integer("enable_proxmox_stats", { mode: "boolean" })
.notNull()
.default(false),
proxmoxStatsConfig: text("proxmox_stats_config"),
terminalConfig: text("terminal_config"),
quickActions: text("quick_actions"),
notes: text("notes"),
@@ -1160,27 +1152,6 @@ export const hostMetricsPreferences = sqliteTable(
],
);
export const proxmoxStatsPreferences = sqliteTable(
"proxmox_stats_preferences",
{
id: integer("id").primaryKey({ autoIncrement: true }),
userId: text("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),
hostId: integer("host_id").notNull().references(() => hosts.id, { onDelete: "cascade" }),
// JSON-encoded ProxmoxStatsLayout. Layout has no secrets, so it is stored as
// plain JSON (no field-level encryption), same convention as hostMetricsPreferences.layout.
layout: text("layout").notNull(),
createdAt: text("created_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
updatedAt: text("updated_at")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
},
(table) => [
uniqueIndex("idx_proxmox_stats_prefs_user_host").on(table.userId, table.hostId),
],
);
export const hostSidebarPreferences = sqliteTable("host_sidebar_preferences", {
userId: text("user_id")
.primaryKey()
@@ -1386,23 +1357,6 @@ export const hostMetricsHistory = sqliteTable("host_metrics_history", {
});
// --- metrics-history end ---
// --- proxmox-node-history begin ---
export const proxmoxNodeHistory = sqliteTable("proxmox_node_history", {
id: integer("id").primaryKey({ autoIncrement: true }),
hostId: integer("host_id")
.notNull()
.references(() => hosts.id, { onDelete: "cascade" }),
ts: text("ts")
.notNull()
.default(sql`CURRENT_TIMESTAMP`),
cpuPercent: real("cpu_percent"),
memPercent: real("mem_percent"),
diskPercent: real("disk_percent"),
netRxBytes: integer("net_rx_bytes"),
netTxBytes: integer("net_tx_bytes"),
});
// --- proxmox-node-history end ---
// --- alerts begin ---
export const notificationChannels = sqliteTable("notification_channels", {
id: integer("id").primaryKey({ autoIncrement: true }),