···11-import { and, isNull, lt } from "drizzle-orm";
11+import { and, inArray, isNull, lt } from "drizzle-orm";
22import { getConnection } from "./drizzle.ts";
33import sandboxes from "./schema/sandboxes.ts";
44+import sandboxPorts from "./schema/sandbox-ports.ts";
45import consola from "consola";
56import chalk from "chalk";
67import { workers } from "./workers.ts";
···6970 "Failed to stop some uninitialized sandboxes on workers. They may have already been stopped or deleted.",
7071 );
7172 });
7373+7474+ const staleIds = stale.map(({ id }) => id);
7575+7676+ await db
7777+ .delete(sandboxPorts)
7878+ .where(inArray(sandboxPorts.sandboxId, staleIds))
7979+ .execute();
72807381 const deleted = await db
7482 .delete(sandboxes)