The database and migrations

All state lives in one SQLite file, comfyui-desktop.db in the data folder, opened by main with better-sqlite3 (src/main/database.ts). The window never opens it.

Tables

TableHolds
settingsOne row: the non-secret settings (provider, model, addresses, language, motion) and preferences_json, the validated preferences.
secret_recordsSaved keys and tokens, encrypted by the system password store.
projectsProjects and the version each one shows (current_revision_id).
graph_revisionsEvery version of every graph: nodes, links, the ComfyUI document, components, title and notes, and who made it.
applied_commandsEvery command applied: its actionId, actor, run, payload and result.
runsThe assistant's runs and their state.
proposalsThe assistant's drafts.
explanationsExplanations of node types, models, links and objects of a graph, with their source.
chat_messagesThe chat, while Keep chat history in the project is on.
node_catalog, node_packs, model_catalogWhat was read from ComfyUI, with model metadata and web lookups.
sync_stateThe state of the sync as keys and values: the last sync, auto-sync and its interval.
schema_migrationsWhich schema versions were applied, and when.

Opening

openDatabase in src/main/database.ts:

  1. A file whose schema version is newer than this app knows is refused before anything is written ("Your data was saved by a newer version…").
  2. The journal is WAL; secure_delete is on, so a forgotten key is overwritten, not left in free pages.
  3. Before an upgrade, the file is copied to comfyui-desktop.db.before-v<N>.bak (only the newest copy is kept) (src/main/settings/databaseSafety.ts).
  4. migrate brings the schema to SCHEMA_VERSION (src/main/settings/migrate.ts).
  5. A failure is classified (damaged, newer, read-only, full, busy) and shown in words; a damaged file can be renamed to comfyui-desktop.db.damaged-<date> and the app starts with empty data.

Adding a migration

  1. Raise SCHEMA_VERSION in src/main/settings/migrate.ts and describe the new version in the comment above it, in one sentence: what it adds and why.
  2. Write applyVersionN(db). Make it safe to run on any database of the previous version: check with columnNames / tableNames before ALTER TABLE, use CREATE … IF NOT EXISTS, give new columns a default.
  3. Add the step to migrate, in its own transaction that also writes the schema_migrations row, like the steps before it.
  4. Never change an older applyVersion…: databases out there already went through it.
  5. Test it in tests/unit/settingsMigration.test.ts: a database at the previous version with real rows upgrades, keeps its rows, and a failure before the version stamp leaves it as it was.

A newer database is never opened by an older app, so plan a change that people can live with when they go back: the app refuses and says so; their data stays untouched.

See also

This page is imported from the application repository's wiki (docs/wiki/dev/Database.md, revision b8e3f71). The same guide is built into the app: Help ▸ User guide.

To refresh it, run npm run import and then npm run build in the website folder.