From 1c92d82501d2f552ab0236ffaea8b2a98e4ebc42 Mon Sep 17 00:00:00 2001 From: Burak Yigit Kaya Date: Tue, 9 Jun 2026 14:34:56 +0000 Subject: [PATCH] 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. --- packages/core/src/database/database.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/core/src/database/database.ts b/packages/core/src/database/database.ts index d61adf047eac..8d3451f4837f 100644 --- a/packages/core/src/database/database.ts +++ b/packages/core/src/database/database.ts @@ -3,6 +3,7 @@ export * as Database from "./database" import { EffectDrizzleSqlite } from "@opencode-ai/effect-drizzle-sqlite" import { layer as sqliteLayer } from "#sqlite" import { Context, Effect, Layer } from "effect" +import { sql } from "drizzle-orm" import { Global } from "../global" import { Flag } from "../flag/flag" import { isAbsolute, join } from "path" @@ -30,6 +31,14 @@ const layer = Layer.effect( yield* db.run("PRAGMA cache_size = -64000") yield* db.run("PRAGMA foreign_keys = ON") yield* db.run("PRAGMA wal_checkpoint(PASSIVE)") + + // One-time migration: enable incremental auto-vacuum (takes effect after next VACUUM) + const autoVacuumMode = yield* db.get<{ auto_vacuum: number }>(sql`PRAGMA auto_vacuum`) + if (autoVacuumMode?.auto_vacuum === 0) { + yield* db.run("PRAGMA auto_vacuum = INCREMENTAL") + yield* db.run("VACUUM") + } + yield* DatabaseMigration.apply(db) return { db }