File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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" )
Original file line number Diff line number Diff line change @@ -28,6 +28,10 @@ const log = Log.create({ service: "db" })
2828
2929export 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" )
Original file line number Diff line number Diff line change 11import { describe , expect , test } from "bun:test"
22import path from "path"
3+ import { Global } from "../../src/global"
34import { Installation } from "../../src/installation"
45import { Database } from "../../src/storage/db"
56
67describe ( "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 - z A - Z 0 - 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 - z A - Z 0 - 9 . _ - ] / g, "-" ) } .db` )
17+ expect ( Database . Path ) . toBe ( expected )
1318 } )
1419} )
You can’t perform that action at this time.
0 commit comments