Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Database: a data folder that ran the old PR #15 branch gets main's migrations 23 and 24

Claude814794ae0f16
diff --git a/docs/HANDOFF.md b/docs/HANDOFF.md
index 8feedbb2..5b89fb0e 100644
--- a/docs/HANDOFF.md
+++ b/docs/HANDOFF.md
@@ -272,6 +272,7 @@ Only cut a PR when the owner asks for one. The steps that worked for PRs #12 to
Never install packs or restart ComfyUI from a package agent. Say what's needed instead.
- **The pre-flight index:** PR #15 put its graphs into `workflows/comfyui/requirements.json` (158 workflows, with ComfyUI-DBS in `packs.json`) and gave Split soundtrack, Fly path and Turnaround rows in `STUDIO_ROWS` (`src/server/gpu/tools.ts`). A package that adds a graph or a studio does the same; `node scripts/comfy/build-requirements.mjs` rewrites the index.
+- **Data folders that ran the old integration branch:** migrations are known by their place in `MIGRATIONS`, and on `claude/fuobe-parity-4` up to `f7c6d8e` places 23 and 24 were acc-1's identity tables and acc-2's audit-log trigger. On main they are the GPU pre-flight's tables and `assets.account_id`. `open()` in `src/server/db.ts` forgets either place when main's work is missing and the dropped package's is there, so main's migration runs (`tests/dropped-branch-migrations.test.ts`). The dropped tables stay, unused. Never reuse a place in that list: only append.
- **Public sign-up** is off by default, and verify.sh's servers run without it. `tests/public-signup.test.ts`, `tests/public-signup-tools.test.ts` and `tests/account-*.test.ts` pin the guest and account answers. Accounts are refused for space while the data disk has less than 20 GB free (`FUOBE_ACCOUNT_DISK_FREE_GB`), so on a small disk run Vitest with `FUOBE_ACCOUNT_DISK_FREE_GB=1`, or `tests/gpu-api.test.ts` answers 503 where it expects 409.
- **What none of the checks cover:** no GPU and no paid key have been used. Every Original is checked in demo mode, on the CPU ComfyUI (graphs accepted, no weights run) and by unit tests, but not for image quality or real bills.
- **The owner's workflow JSONs and downloaded repos:** never commit them, never run them.
diff --git a/src/server/db.ts b/src/server/db.ts
index c79c27bd..07c452d3 100644
--- a/src/server/db.ts
+++ b/src/server/db.ts
@@ -611,12 +611,31 @@ declare global {
var __fuobeDb: Database.Database | undefined;
}
+/**
+ * A data folder that ran PR #15's branch before the owner dropped the old accounts packages on 10-30
+ * (`claude/fuobe-parity-4` up to f7c6d8e, `claude/fuobe-r5-batch-7` up to c9cd489) has places 23 and 24 marked done for
+ * that branch's own migrations: acc-1's identity tables and acc-2's audit-log trigger. In this list those places are
+ * the GPU pre-flight's tables and `assets.account_id`, so such a folder would skip both without a word. A place is
+ * forgotten when this list's work is missing and the dropped package's is there, so the loop below runs it. The dropped
+ * tables stay: nothing reads them, and nothing anyone made is deleted.
+ */
+function forgetDroppedBranchMigrations(db: Database.Database): void {
+ const done = (id: number) => !!db.prepare("SELECT 1 FROM _migrations WHERE id = ?").get(id);
+ const has = (type: "table" | "trigger", name: string) => !!db.prepare("SELECT 1 FROM sqlite_master WHERE type = ? AND name = ?").get(type, name);
+ const hasColumn = (table: string, column: string) =>
+ (db.prepare(`PRAGMA table_info(${table})`).all() as { name: string }[]).some((c) => c.name === column);
+ const forget = (id: number) => db.prepare("DELETE FROM _migrations WHERE id = ?").run(id);
+ if (done(23) && !has("table", "gpu_snapshots") && hasColumn("users", "auth_user_id")) forget(23);
+ if (done(24) && !hasColumn("assets", "account_id") && has("trigger", "audit_log_no_delete")) forget(24);
+}
+
function open(): Database.Database {
fs.mkdirSync(DATA_DIR, { recursive: true });
const db = new Database(path.join(DATA_DIR, "fuobe.db"));
db.pragma("journal_mode = WAL");
db.pragma("busy_timeout = 5000");
db.exec(`CREATE TABLE IF NOT EXISTS _migrations (id INTEGER PRIMARY KEY)`);
+ forgetDroppedBranchMigrations(db);
const done = new Set(
(db.prepare("SELECT id FROM _migrations").all() as { id: number }[]).map((r) => r.id),
);
diff --git a/tests/dropped-branch-migrations.test.ts b/tests/dropped-branch-migrations.test.ts
new file mode 100644
index 00000000..596776fb
--- /dev/null
+++ b/tests/dropped-branch-migrations.test.ts
@@ -0,0 +1,117 @@
+import fs from "node:fs";
+import os from "node:os";
+import path from "node:path";
+import Database from "better-sqlite3";
+import { afterAll, afterEach, describe, expect, it } from "vitest";
+
+const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-dropped-migrations-"));
+process.env.FUOBE_DATA_DIR = dir;
+const file = path.join(dir, "fuobe.db");
+
+const { db, MIGRATIONS } = await import("@/server/db");
+
+afterEach(() => {
+ globalThis.__fuobeDb?.close();
+ globalThis.__fuobeDb = undefined;
+ for (const f of [file, `${file}-wal`, `${file}-shm`]) fs.rmSync(f, { force: true });
+});
+afterAll(() => fs.rmSync(dir, { recursive: true, force: true }));
+
+// The dropped branch's own places 23 and 24 (claude/fuobe-r5-batch-7 at c9cd489), cut to what they made that matters
+// here: acc-1's people table linked to Better Auth and its append-only audit log, and acc-2's DELETE trigger.
+const ACC1 = `CREATE TABLE IF NOT EXISTS users (
+ id TEXT PRIMARY KEY,
+ auth_user_id TEXT UNIQUE,
+ role TEXT NOT NULL,
+ status TEXT NOT NULL DEFAULT 'active',
+ personal_workspace_id TEXT,
+ source TEXT NOT NULL DEFAULT 'unknown',
+ created_at INTEGER NOT NULL,
+ updated_at INTEGER NOT NULL
+ );
+ CREATE TABLE IF NOT EXISTS audit_log (
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
+ at INTEGER NOT NULL,
+ actor_id TEXT,
+ action TEXT NOT NULL,
+ meta_json TEXT NOT NULL DEFAULT '{}',
+ prev_hash TEXT NOT NULL,
+ hash TEXT NOT NULL
+ );
+ CREATE TRIGGER IF NOT EXISTS audit_log_append_only BEFORE UPDATE ON audit_log
+ BEGIN SELECT RAISE(ABORT, 'audit_log is append-only'); END;
+ INSERT OR IGNORE INTO users (id, role, status, personal_workspace_id, source, created_at, updated_at) VALUES
+ ('u_owner', 'owner', 'active', 'w_owner', 'setup', 1, 1);
+ create table "auth_user" ("id" text not null primary key, "name" text not null, "email" text not null unique, "emailVerified" integer not null, "image" text, "createdAt" date not null, "updatedAt" date not null);`;
+const ACC2 = `CREATE TRIGGER IF NOT EXISTS audit_log_no_delete BEFORE DELETE ON audit_log
+ BEGIN SELECT RAISE(ABORT, 'audit_log is append-only'); END;`;
+
+/** A data folder made by another build: its migrations run the way open() runs them, each known by its place. */
+function ranBefore(list: string[], extra?: (d: Database.Database) => void) {
+ const d = new Database(file);
+ d.exec("CREATE TABLE IF NOT EXISTS _migrations (id INTEGER PRIMARY KEY)");
+ list.forEach((sql, i) => {
+ d.exec(sql);
+ d.prepare("INSERT INTO _migrations (id) VALUES (?)").run(i);
+ });
+ extra?.(d);
+ d.close();
+}
+
+const shared = () => MIGRATIONS.slice(0, 23);
+const tables = (d: Database.Database) => new Set((d.prepare("SELECT name FROM sqlite_master WHERE type = 'table'").all() as { name: string }[]).map((r) => r.name));
+const columns = (d: Database.Database, t: string) => (d.prepare(`PRAGMA table_info(${t})`).all() as { name: string }[]).map((c) => c.name);
+const marked = (d: Database.Database) => (d.prepare("SELECT id FROM _migrations ORDER BY id").all() as { id: number }[]).map((r) => r.id);
+
+describe("a data folder that ran PR #15's branch before acc-1 and acc-2 were dropped", () => {
+ it("has the places this test assumes: 23 the GPU pre-flight, 24 assets.account_id", () => {
+ expect(MIGRATIONS[23]).toContain("CREATE TABLE IF NOT EXISTS gpu_snapshots");
+ expect(MIGRATIONS[23]).toContain("ALTER TABLE generations ADD COLUMN fix_json");
+ expect(MIGRATIONS[24]).toContain("ALTER TABLE assets ADD COLUMN account_id");
+ });
+
+ it("gets the GPU pre-flight's tables and assets.account_id after acc-1 and acc-2 took places 23 and 24", () => {
+ ranBefore([...shared(), ACC1, ACC2], (d) => {
+ d.prepare("INSERT INTO assets (id, kind, name, rel_path, content_type, size, source, created_at) VALUES ('a1', 'image', 'x.png', 'x.png', 'image/png', 1, 'upload', 1)").run();
+ });
+ const d = db();
+ expect(tables(d)).toContain("gpu_snapshots");
+ expect(tables(d)).toContain("gpu_audit");
+ expect(columns(d, "generations")).toContain("fix_json");
+ expect(columns(d, "assets")).toContain("account_id");
+ expect(marked(d)).toEqual(MIGRATIONS.map((_, i) => i));
+ // Nothing anyone made goes: the owner's file and the dropped tables stay.
+ expect(d.prepare("SELECT id, account_id FROM assets").all()).toEqual([{ id: "a1", account_id: null }]);
+ expect(tables(d)).toContain("users");
+ expect(tables(d)).toContain("audit_log");
+ });
+
+ it("gets both after acc-1 alone took place 23", () => {
+ ranBefore([...shared(), ACC1]);
+ const d = db();
+ expect(tables(d)).toContain("gpu_snapshots");
+ expect(columns(d, "assets")).toContain("account_id");
+ expect(marked(d)).toEqual(MIGRATIONS.map((_, i) => i));
+ });
+
+ it("leaves a folder that already ran this list alone, and opens it again", () => {
+ ranBefore(MIGRATIONS);
+ let d = db();
+ expect(marked(d)).toEqual(MIGRATIONS.map((_, i) => i));
+ d.close();
+ globalThis.__fuobeDb = undefined;
+ // Places 23 and 24 can't run twice (ALTER TABLE … ADD COLUMN): opening again must not try.
+ d = db();
+ expect(columns(d, "generations").filter((c) => c === "fix_json")).toHaveLength(1);
+ expect(marked(d)).toEqual(MIGRATIONS.map((_, i) => i));
+ });
+
+ it("forgets only a place whose own work is missing", () => {
+ // Place 23 already holds this list's GPU pre-flight; place 24 was acc-2's trigger.
+ ranBefore([...MIGRATIONS.slice(0, 24), ACC2.replace("ON audit_log", "ON gpu_audit")], (d) => d.exec("CREATE TABLE users (id TEXT, auth_user_id TEXT)"));
+ const d = db();
+ expect(columns(d, "generations").filter((c) => c === "fix_json")).toHaveLength(1);
+ expect(columns(d, "assets")).toContain("account_id");
+ expect(marked(d)).toEqual(MIGRATIONS.map((_, i) => i));
+ });
+});