diff options
| author | Dax Raad <[email protected]> | 2026-03-06 10:58:07 -0500 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2026-03-06 10:58:19 -0500 |
| commit | 5e699c9426223409bd237174446d3abb88edb8cb (patch) | |
| tree | 4b6afaae375c04ed3c6ea5a8e1f6e07807d933eb /packages | |
| parent | e0ca52ed1f77e2ffeaa5a455949c8d7c913b9175 (diff) | |
| download | opencode-5e699c9426223409bd237174446d3abb88edb8cb.tar.gz opencode-5e699c9426223409bd237174446d3abb88edb8cb.zip | |
chore(storage): update drizzle and channel db handling
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/opencode/package.json | 8 | ||||
| -rw-r--r-- | packages/opencode/src/flag/flag.ts | 1 | ||||
| -rw-r--r-- | packages/opencode/src/storage/db.ts | 22 | ||||
| -rw-r--r-- | packages/opencode/test/storage/json-migration.test.ts | 1 |
4 files changed, 22 insertions, 10 deletions
diff --git a/packages/opencode/package.json b/packages/opencode/package.json index f502382ba..d07d2f920 100644 --- a/packages/opencode/package.json +++ b/packages/opencode/package.json @@ -45,8 +45,8 @@ "@types/yargs": "17.0.33", "@types/which": "3.0.4", "@typescript/native-preview": "catalog:", - "drizzle-kit": "1.0.0-beta.12-a5629fb", - "drizzle-orm": "1.0.0-beta.12-a5629fb", + "drizzle-kit": "1.0.0-beta.16-ea816b6", + "drizzle-orm": "1.0.0-beta.16-ea816b6", "typescript": "catalog:", "vscode-languageserver-types": "3.17.5", "why-is-node-running": "3.2.2", @@ -106,7 +106,7 @@ "clipboardy": "4.0.0", "decimal.js": "10.5.0", "diff": "catalog:", - "drizzle-orm": "1.0.0-beta.12-a5629fb", + "drizzle-orm": "1.0.0-beta.16-ea816b6", "fuzzysort": "3.1.0", "glob": "13.0.5", "google-auth-library": "10.5.0", @@ -135,6 +135,6 @@ "zod-to-json-schema": "3.24.5" }, "overrides": { - "drizzle-orm": "1.0.0-beta.12-a5629fb" + "drizzle-orm": "1.0.0-beta.16-ea816b6" } } diff --git a/packages/opencode/src/flag/flag.ts b/packages/opencode/src/flag/flag.ts index 22eba6320..c743cd18d 100644 --- a/packages/opencode/src/flag/flag.ts +++ b/packages/opencode/src/flag/flag.ts @@ -60,6 +60,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_DISABLE_CHANNEL_DB = truthy("OPENCODE_DISABLE_CHANNEL_DB") function number(key: string) { const value = process.env[key] diff --git a/packages/opencode/src/storage/db.ts b/packages/opencode/src/storage/db.ts index f29aac18d..d7538dc70 100644 --- a/packages/opencode/src/storage/db.ts +++ b/packages/opencode/src/storage/db.ts @@ -12,8 +12,10 @@ import z from "zod" import path from "path" import { readFileSync, readdirSync, existsSync } from "fs" import * as schema from "./schema" +import { Installation } from "../installation" +import { Flag } from "../flag/flag" -declare const OPENCODE_MIGRATIONS: { sql: string; timestamp: number }[] | undefined +declare const OPENCODE_MIGRATIONS: { sql: string; timestamp: number; name: string }[] | undefined export const NotFoundError = NamedError.create( "NotFoundError", @@ -25,13 +27,20 @@ export const NotFoundError = NamedError.create( const log = Log.create({ service: "db" }) export namespace Database { - export const Path = path.join(Global.Path.data, "opencode.db") + export const Path = (() => { + const name = + Installation.CHANNEL !== "latest" && !Flag.OPENCODE_DISABLE_CHANNEL_DB + ? `opencode-${Installation.CHANNEL}.db` + : "opencode.db" + return path.join(Global.Path.data, name) + })() + type Schema = typeof schema export type Transaction = SQLiteTransaction<"sync", void, Schema> type Client = SQLiteBunDatabase<Schema> - type Journal = { sql: string; timestamp: number }[] + type Journal = { sql: string; timestamp: number; name: string }[] const state = { sqlite: undefined as BunDatabase | undefined, @@ -62,6 +71,7 @@ export namespace Database { return { sql: readFileSync(file, "utf-8"), timestamp: time(name), + name, } }) .filter(Boolean) as Journal @@ -70,9 +80,9 @@ export namespace Database { } export const Client = lazy(() => { - log.info("opening database", { path: path.join(Global.Path.data, "opencode.db") }) + log.info("opening database", { path: Path }) - const sqlite = new BunDatabase(path.join(Global.Path.data, "opencode.db"), { create: true }) + const sqlite = new BunDatabase(Path, { create: true }) state.sqlite = sqlite sqlite.run("PRAGMA journal_mode = WAL") @@ -143,7 +153,7 @@ export namespace Database { } catch (err) { if (err instanceof Context.NotFound) { const effects: (() => void | Promise<void>)[] = [] - const result = Client().transaction((tx) => { + const result = (Client().transaction as any)((tx: TxOrDb) => { return ctx.provide({ tx, effects }, () => callback(tx)) }) for (const effect of effects) effect() diff --git a/packages/opencode/test/storage/json-migration.test.ts b/packages/opencode/test/storage/json-migration.test.ts index b70c9e1eb..40dd61145 100644 --- a/packages/opencode/test/storage/json-migration.test.ts +++ b/packages/opencode/test/storage/json-migration.test.ts @@ -84,6 +84,7 @@ function createTestDb() { .map((entry) => ({ sql: readFileSync(path.join(dir, entry.name, "migration.sql"), "utf-8"), timestamp: Number(entry.name.split("_")[0]), + name: entry.name, })) .sort((a, b) => a.timestamp - b.timestamp) migrate(drizzle({ client: sqlite }), migrations) |
