Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/opencode/src/storage/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -170,3 +178,11 @@ export function transaction<T>(
throw err
}
}

export function checkpoint() {
Client().$client.run("PRAGMA wal_checkpoint(TRUNCATE)")
}

export function vacuum() {
Client().$client.run("PRAGMA incremental_vacuum")
}
Loading