core: allow beta channel to share database with stable channel
This commit is contained in:
@@ -14,6 +14,7 @@ import { readFileSync, readdirSync, existsSync } from "fs"
|
|||||||
import * as schema from "./schema"
|
import * as schema from "./schema"
|
||||||
import { Installation } from "../installation"
|
import { Installation } from "../installation"
|
||||||
import { Flag } from "../flag/flag"
|
import { Flag } from "../flag/flag"
|
||||||
|
import { iife } from "@/util/iife"
|
||||||
|
|
||||||
declare const OPENCODE_MIGRATIONS: { sql: string; timestamp: number; name: string }[] | undefined
|
declare const OPENCODE_MIGRATIONS: { sql: string; timestamp: number; name: string }[] | undefined
|
||||||
|
|
||||||
@@ -27,15 +28,13 @@ export const NotFoundError = NamedError.create(
|
|||||||
const log = Log.create({ service: "db" })
|
const log = Log.create({ service: "db" })
|
||||||
|
|
||||||
export namespace Database {
|
export namespace Database {
|
||||||
export function file(channel: string) {
|
export const Path = iife(() => {
|
||||||
if (channel === "latest" || Flag.OPENCODE_DISABLE_CHANNEL_DB) return "opencode.db"
|
const channel = Installation.CHANNEL
|
||||||
|
if (["latest", "beta"].includes(channel) || Flag.OPENCODE_DISABLE_CHANNEL_DB)
|
||||||
|
return path.join(Global.Path.data, "opencode.db")
|
||||||
const safe = channel.replace(/[^a-zA-Z0-9._-]/g, "-")
|
const safe = channel.replace(/[^a-zA-Z0-9._-]/g, "-")
|
||||||
return `opencode-${safe}.db`
|
return path.join(Global.Path.data, `opencode-${safe}.db`)
|
||||||
}
|
})
|
||||||
|
|
||||||
export const Path = (() => {
|
|
||||||
return path.join(Global.Path.data, file(Installation.CHANNEL))
|
|
||||||
})()
|
|
||||||
|
|
||||||
type Schema = typeof schema
|
type Schema = typeof schema
|
||||||
export type Transaction = SQLiteTransaction<"sync", void, Schema>
|
export type Transaction = SQLiteTransaction<"sync", void, Schema>
|
||||||
|
|||||||
Reference in New Issue
Block a user