Skip to content

Commit 5dc4790

Browse files
committed
allow customizing DB location
1 parent dc00448 commit 5dc4790

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

packages/opencode/src/flag/flag.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export namespace Flag {
6969
export const OPENCODE_EXPERIMENTAL_MARKDOWN = !falsy("OPENCODE_EXPERIMENTAL_MARKDOWN")
7070
export const OPENCODE_MODELS_URL = process.env["OPENCODE_MODELS_URL"]
7171
export const OPENCODE_MODELS_PATH = process.env["OPENCODE_MODELS_PATH"]
72+
export const OPENCODE_DB = process.env["OPENCODE_DB"]
7273
export const OPENCODE_DISABLE_CHANNEL_DB = truthy("OPENCODE_DISABLE_CHANNEL_DB")
7374
export const OPENCODE_SKIP_MIGRATIONS = truthy("OPENCODE_SKIP_MIGRATIONS")
7475
export const OPENCODE_STRICT_CONFIG_DEPS = truthy("OPENCODE_STRICT_CONFIG_DEPS")

packages/opencode/src/storage/db.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ const log = Log.create({ service: "db" })
2828

2929
export namespace Database {
3030
export const Path = iife(() => {
31+
if (Flag.OPENCODE_DB) {
32+
if (path.isAbsolute(Flag.OPENCODE_DB)) return Flag.OPENCODE_DB
33+
return path.join(Global.Path.data, Flag.OPENCODE_DB)
34+
}
3135
const channel = Installation.CHANNEL
3236
if (["latest", "beta"].includes(channel) || Flag.OPENCODE_DISABLE_CHANNEL_DB)
3337
return path.join(Global.Path.data, "opencode.db")
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { describe, expect, test } from "bun:test"
22
import path from "path"
3+
import { Global } from "../../src/global"
34
import { Installation } from "../../src/installation"
45
import { Database } from "../../src/storage/db"
56

67
describe("Database.Path", () => {
78
test("returns database path for the current channel", () => {
8-
const file = path.basename(Database.Path)
9-
const expected = ["latest", "beta"].includes(Installation.CHANNEL)
10-
? "opencode.db"
11-
: `opencode-${Installation.CHANNEL.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`
12-
expect(file).toBe(expected)
9+
const db = process.env["OPENCODE_DB"]
10+
const expected = db
11+
? path.isAbsolute(db)
12+
? db
13+
: path.join(Global.Path.data, db)
14+
: ["latest", "beta"].includes(Installation.CHANNEL)
15+
? path.join(Global.Path.data, "opencode.db")
16+
: path.join(Global.Path.data, `opencode-${Installation.CHANNEL.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`)
17+
expect(Database.Path).toBe(expected)
1318
})
1419
})

0 commit comments

Comments
 (0)