diff --git a/packages/opencode/src/storage/db.ts b/packages/opencode/src/storage/db.ts index 2c0076452e1c..fa2a8f0c72a2 100644 --- a/packages/opencode/src/storage/db.ts +++ b/packages/opencode/src/storage/db.ts @@ -93,6 +93,14 @@ export const Client = lazy(() => { db.run("PRAGMA foreign_keys = ON") db.run("PRAGMA wal_checkpoint(PASSIVE)") + // One-time auto-vacuum migration: switch from none (0) to incremental (2) + const autoVacuum = db.$client.prepare("PRAGMA auto_vacuum").get() as { auto_vacuum: number } | undefined + if (autoVacuum?.auto_vacuum === 0) { + log.info("enabling incremental auto_vacuum") + db.run("PRAGMA auto_vacuum = 2") + db.run("VACUUM") + } + // Apply schema migrations const entries = typeof OPENCODE_MIGRATIONS !== "undefined" @@ -170,3 +178,11 @@ export function transaction( throw err } } + +export function checkpoint() { + Client().$client.run("PRAGMA wal_checkpoint(TRUNCATE)") +} + +export function vacuum() { + Client().$client.run("PRAGMA incremental_vacuum") +}