Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions packages/opencode/src/storage/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import z from "zod"
import path from "path"
import { readFileSync, readdirSync, existsSync } from "fs"
import { Flag } from "../flag/flag"
import { InstallationChannel } from "../installation/version"
import { InstanceState } from "@/effect"
import { iife } from "@/util/iife"
import { init } from "#db"
Expand All @@ -27,19 +26,12 @@ export const NotFoundError = NamedError.create(

const log = Log.create({ service: "db" })

export function getChannelPath() {
if (["latest", "beta", "prod"].includes(InstallationChannel) || Flag.OPENCODE_DISABLE_CHANNEL_DB)
return path.join(Global.Path.data, "opencode.db")
const safe = InstallationChannel.replace(/[^a-zA-Z0-9._-]/g, "-")
return path.join(Global.Path.data, `opencode-${safe}.db`)
}

export const Path = iife(() => {
if (Flag.OPENCODE_DB) {
if (Flag.OPENCODE_DB === ":memory:" || path.isAbsolute(Flag.OPENCODE_DB)) return Flag.OPENCODE_DB
return path.join(Global.Path.data, Flag.OPENCODE_DB)
}
return getChannelPath()
return path.join(Global.Path.data, "opencode.db")
})

export type Transaction = SQLiteTransaction<"sync", void>
Expand Down
10 changes: 2 additions & 8 deletions packages/opencode/test/storage/db.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { describe, expect, test } from "bun:test"
import path from "path"
import { Global } from "../../src/global"
import { InstallationChannel } from "../../src/installation/version"
import { Database } from "../../src/storage"

describe("Database.Path", () => {
test("returns database path for the current channel", () => {
const expected = ["latest", "beta"].includes(InstallationChannel)
? path.join(Global.Path.data, "opencode.db")
: path.join(Global.Path.data, `opencode-${InstallationChannel.replace(/[^a-zA-Z0-9._-]/g, "-")}.db`)
expect(Database.getChannelPath()).toBe(expected)
test("respects OPENCODE_DB env override", () => {
expect(Database.Path).toBe(":memory:")
})
})