@toist/aja 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/runtime-db.ts CHANGED
@@ -1,44 +1,25 @@
1
1
  // 2121
2
- // Platform-internal runtime ledger. Holds:
3
- // - runs — every pipeline execution (status, payload, result, steps, timing)
4
- // - logs — log lines emitted from kinds during a run, scoped to run_id
5
- // - tasks — HITL pending tasks (added in migration 002)
6
- // - node_outputs — checkpoint-between-nodes memoization (added in migration 002)
7
- //
8
- // Schema is owned by the platform and evolved via numbered SQL migrations
9
- // in ../migrations/. See migrate.ts for the runner.
10
- //
11
- // Kinds never receive a handle to this DB — they only see ctx.db (data
12
- // store) and ctx.cache (capability), so they cannot accidentally touch
13
- // runtime tables.
14
- //
15
- // Migration policy: by default the runner applies pending migrations at
16
- // startup. RUNTIME_AUTO_MIGRATE=false flips to fail-loud — startup aborts if
17
- // anything is pending.
18
- //
19
- // Lifecycle: openRuntimeDb() is a pure factory. The runner lock is acquired
20
- // separately by db-handles.initDbs() before this is called, so two callers
21
- // cannot race on migrations.
22
-
23
2
  import { Database } from "bun:sqlite"
24
3
  import { mkdirSync } from "node:fs"
25
4
  import { dirname } from "node:path"
26
5
  import { runMigrations, pendingMigrations } from "./migrate.ts"
27
- import { runtimeDbPath } from "./config.ts"
28
6
 
29
- export function openRuntimeDb(): Database {
30
- const path = runtimeDbPath()
7
+ export function openRuntimeDb(path: string, opts: { skipMigrations?: boolean } = {}): Database {
31
8
  mkdirSync(dirname(path), { recursive: true })
32
9
 
33
- if (process.env.RUNTIME_AUTO_MIGRATE === "false") {
10
+ if (opts.skipMigrations) {
11
+ const pending = pendingMigrations(path)
12
+ if (pending.length > 0) {
13
+ throw new Error(
14
+ `[runtime-db] ${pending.length} pending migration(s) with skipMigrations=true: ${pending.join(", ")}`,
15
+ )
16
+ }
17
+ } else if (process.env.RUNTIME_AUTO_MIGRATE === "false") {
34
18
  const pending = pendingMigrations(path)
35
19
  if (pending.length > 0) {
36
- console.error(
37
- `[runtime-db] ${pending.length} pending migration(s); RUNTIME_AUTO_MIGRATE=false.`,
20
+ throw new Error(
21
+ `[runtime-db] ${pending.length} pending migration(s); RUNTIME_AUTO_MIGRATE=false. Pending: ${pending.join(", ")}`,
38
22
  )
39
- console.error(`[runtime-db] pending: ${pending.join(", ")}`)
40
- console.error(`[runtime-db] run migrations explicitly, or unset RUNTIME_AUTO_MIGRATE.`)
41
- process.exit(1)
42
23
  }
43
24
  } else {
44
25
  runMigrations(path)