allow customizing DB location
This commit is contained in:
@@ -69,6 +69,7 @@ export namespace Flag {
|
|||||||
export const OPENCODE_EXPERIMENTAL_MARKDOWN = !falsy("OPENCODE_EXPERIMENTAL_MARKDOWN")
|
export const OPENCODE_EXPERIMENTAL_MARKDOWN = !falsy("OPENCODE_EXPERIMENTAL_MARKDOWN")
|
||||||
export const OPENCODE_MODELS_URL = process.env["OPENCODE_MODELS_URL"]
|
export const OPENCODE_MODELS_URL = process.env["OPENCODE_MODELS_URL"]
|
||||||
export const OPENCODE_MODELS_PATH = process.env["OPENCODE_MODELS_PATH"]
|
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_DISABLE_CHANNEL_DB = truthy("OPENCODE_DISABLE_CHANNEL_DB")
|
||||||
export const OPENCODE_SKIP_MIGRATIONS = truthy("OPENCODE_SKIP_MIGRATIONS")
|
export const OPENCODE_SKIP_MIGRATIONS = truthy("OPENCODE_SKIP_MIGRATIONS")
|
||||||
export const OPENCODE_STRICT_CONFIG_DEPS = truthy("OPENCODE_STRICT_CONFIG_DEPS")
|
export const OPENCODE_STRICT_CONFIG_DEPS = truthy("OPENCODE_STRICT_CONFIG_DEPS")
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ const log = Log.create({ service: "db" })
|
|||||||
|
|
||||||
export namespace Database {
|
export namespace Database {
|
||||||
export const Path = iife(() => {
|
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
|
const channel = Installation.CHANNEL
|
||||||
if (["latest", "beta"].includes(channel) || Flag.OPENCODE_DISABLE_CHANNEL_DB)
|
if (["latest", "beta"].includes(channel) || Flag.OPENCODE_DISABLE_CHANNEL_DB)
|
||||||
return path.join(Global.Path.data, "opencode.db")
|
return path.join(Global.Path.data, "opencode.db")
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
|
import { Global } from "../../src/global"
|
||||||
import { Installation } from "../../src/installation"
|
import { Installation } from "../../src/installation"
|
||||||
import { Database } from "../../src/storage/db"
|
import { Database } from "../../src/storage/db"
|
||||||
|
|
||||||
describe("Database.Path", () => {
|
describe("Database.Path", () => {
|
||||||
test("returns database path for the current channel", () => {
|
test("returns database path for the current channel", () => {
|
||||||
const file = path.basename(Database.Path)
|
const db = process.env["OPENCODE_DB"]
|
||||||
const expected = ["latest", "beta"].includes(Installation.CHANNEL)
|
const expected = db
|
||||||
? "opencode.db"
|
? path.isAbsolute(db)
|
||||||
: `opencode-${Installation.CHANNEL.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`
|
? db
|
||||||
expect(file).toBe(expected)
|
: 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)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user