From d36ebf779845be161fcba85075abea4cdb4b0271 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 ba7aa91b0ee0..efb60e785db6 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" @@ -29,6 +30,14 @@ export 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 }