From 5dc47905a93d01efeaff3de713d9aaea1246dd59 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Fri, 20 Mar 2026 22:49:55 -0400 Subject: [PATCH] allow customizing DB location --- packages/opencode/src/flag/flag.ts | 1 + packages/opencode/src/storage/db.ts | 4 ++++ packages/opencode/test/storage/db.test.ts | 15 ++++++++++----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/opencode/src/flag/flag.ts b/packages/opencode/src/flag/flag.ts index 43b3de37b..05f04c85c 100644 --- a/packages/opencode/src/flag/flag.ts +++ b/packages/opencode/src/flag/flag.ts @@ -69,6 +69,7 @@ export namespace Flag { export const OPENCODE_EXPERIMENTAL_MARKDOWN = !falsy("OPENCODE_EXPERIMENTAL_MARKDOWN") export const OPENCODE_MODELS_URL = process.env["OPENCODE_MODELS_URL"] export const OPENCODE_MODELS_PATH = process.env["OPENCODE_MODELS_PATH"] + export const OPENCODE_DB = process.env["OPENCODE_DB"] export const OPENCODE_DISABLE_CHANNEL_DB = truthy("OPENCODE_DISABLE_CHANNEL_DB") export const OPENCODE_SKIP_MIGRATIONS = truthy("OPENCODE_SKIP_MIGRATIONS") export const OPENCODE_STRICT_CONFIG_DEPS = truthy("OPENCODE_STRICT_CONFIG_DEPS") diff --git a/packages/opencode/src/storage/db.ts b/packages/opencode/src/storage/db.ts index dcf0942e1..1bb8c1a69 100644 --- a/packages/opencode/src/storage/db.ts +++ b/packages/opencode/src/storage/db.ts @@ -28,6 +28,10 @@ const log = Log.create({ service: "db" }) export namespace Database { export const Path = iife(() => { + if (Flag.OPENCODE_DB) { + if (path.isAbsolute(Flag.OPENCODE_DB)) return Flag.OPENCODE_DB + return path.join(Global.Path.data, Flag.OPENCODE_DB) + } const channel = Installation.CHANNEL if (["latest", "beta"].includes(channel) || Flag.OPENCODE_DISABLE_CHANNEL_DB) return path.join(Global.Path.data, "opencode.db") diff --git a/packages/opencode/test/storage/db.test.ts b/packages/opencode/test/storage/db.test.ts index 601289e58..af5ddec36 100644 --- a/packages/opencode/test/storage/db.test.ts +++ b/packages/opencode/test/storage/db.test.ts @@ -1,14 +1,19 @@ import { describe, expect, test } from "bun:test" import path from "path" +import { Global } from "../../src/global" import { Installation } from "../../src/installation" import { Database } from "../../src/storage/db" describe("Database.Path", () => { test("returns database path for the current channel", () => { - const file = path.basename(Database.Path) - const expected = ["latest", "beta"].includes(Installation.CHANNEL) - ? "opencode.db" - : `opencode-${Installation.CHANNEL.replace(/[^a-zA-Z0-9._-]/g, "-")}.db` - expect(file).toBe(expected) + const db = process.env["OPENCODE_DB"] + const expected = db + ? path.isAbsolute(db) + ? db + : path.join(Global.Path.data, db) + : ["latest", "beta"].includes(Installation.CHANNEL) + ? path.join(Global.Path.data, "opencode.db") + : path.join(Global.Path.data, `opencode-${Installation.CHANNEL.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`) + expect(Database.Path).toBe(expected) }) })