Skip to content

Commit 3db2d6b

Browse files
committed
chore(db): enable auto-vacuum and add periodic maintenance
One-time migration: detect auto_vacuum = 0 (NONE) and switch to INCREMENTAL. Run a full VACUUM to apply the mode change. Subsequent database opens skip this since the mode persists. This prevents the database file from growing indefinitely as deleted rows leave behind free pages that are never reclaimed.
1 parent ed926be commit 3db2d6b

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

packages/core/src/database/database.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * as Database from "./database"
33
import { EffectDrizzleSqlite } from "@opencode-ai/effect-drizzle-sqlite"
44
import { layer as sqliteLayer } from "#sqlite"
55
import { Context, Effect, Layer } from "effect"
6+
import { sql } from "drizzle-orm"
67
import { Global } from "../global"
78
import { Flag } from "../flag/flag"
89
import { isAbsolute, join } from "path"
@@ -30,6 +31,14 @@ const layer = Layer.effect(
3031
yield* db.run("PRAGMA cache_size = -64000")
3132
yield* db.run("PRAGMA foreign_keys = ON")
3233
yield* db.run("PRAGMA wal_checkpoint(PASSIVE)")
34+
35+
// One-time migration: enable incremental auto-vacuum (takes effect after next VACUUM)
36+
const autoVacuumMode = yield* db.get<{ auto_vacuum: number }>(sql`PRAGMA auto_vacuum`)
37+
if (autoVacuumMode?.auto_vacuum === 0) {
38+
yield* db.run("PRAGMA auto_vacuum = INCREMENTAL")
39+
yield* db.run("VACUUM")
40+
}
41+
3342
yield* DatabaseMigration.apply(db)
3443

3544
return { db }

0 commit comments

Comments
 (0)