fix(local-db): restore persist_terminal so shipped builds can still read settings

Merged
SA
3mo ago
+1599-0

Release-blocking for 1.21.0. The desktop version bump to 1.21.0 has already landed on main, so migration 0046 — which drops a column the currently-shipped 1.20.2 build still selects — is in the next release as things stand. Anyone who runs 1.21.0 and then rolls back to 1.20.2 gets a permanently broken settings layer. This PR neutralizes the drop before the release is cut.

Problem

DESKTOP-VZ: every read of the desktop app's local settings row fails against SQLite with no such column for the column that used to back the terminal-persistence toggle. Reported on stable Superset@1.20.2.

The failing call is the shared getSettings() accessor in the desktop tRPC settings router, reached in the reported event through the parked-terminal-runtime-cap query the authenticated layout issues on startup. It is not specific to that procedure — it breaks every settings read on the affected install.

Root cause

Migration 0046_drop_dead_persist_terminal_column.sql issues ALTER TABLE settings DROP COLUMN persist_terminal. It landed on main on 2026-08-12, after the 1.20.2 stable build was cut.

1.20.2's code still declares that column in its Drizzle schema, and Drizzle's select() emits an explicit column list rather than select *. So once any newer build (canary, dev, or 1.21.0) applies 0046 against the shared local.db, going back to — or concurrently running — 1.20.2 makes the settings read throw forever. The reporting user is on 1.20.2 and has already been through the newer schema.

A dropped column has to be retired in two stages: stop reading it in one release, drop it a release or more later, once the reading build is out of circulation. 0046 did both at once.

Fix

  1. 0047_restore_persist_terminal_column.sql (generated via bunx drizzle-kit generate, no hand-edits under drizzle/) adds the column back. Its SQL is byte-identical to 0012_add_persist_terminal.sql, which created it originally — same type, same DEFAULT true. This repairs installs that already ran 0046, which deleting 0046 could not do.
  2. packages/local-db/src/schema/schema.ts re-declares the column, marked @deprecated, so drizzle-kit stops wanting to drop it and the next person reads the two-stage rule before trying again.
  3. packages/cli/src/lib/settings/registry.ts gets its exclusion entry back, so the registry coverage ratchet stays accurate about the column existing but not being exposed.
  4. getSettings() now degrades instead of hard-throwing on schema skew — see below.

0046 itself is untouched. Nothing under any drizzle/ directory was hand-edited; _journal.json and the 0047 snapshot are drizzle-kit generate output.

Should the accessor degrade? Yes — and it now does

A settings read that hard-throws takes out unrelated startup queries; that is exactly how a dead column killed the parked-runtime-cap query. The narrow fallback:

  • triggers only on a no such column error from the settings read;
  • re-reads with select * from settings limit 1 and maps through Drizzle's own getTableColumns / mapFromDriverValue, so present columns keep their real values (booleans, JSON presets) and only the genuinely missing ones fall back to null — callers already do row.x ?? DEFAULT. This matters: an all-defaults row would make a user's settings look reset;
  • reports once per process, distinguishably — console.error plus a Sentry capture tagged settings_schema_skew, so this class never hides inside the generic tRPC 500 stream;
  • rethrows every other SQLite error, rethrows if the raw re-read also fails, and does not cover the insert path.

It does not mask genuine query bugs: a query naming a column that exists in neither the file nor the schema still throws (verified below, check D). The practical effect is that 1.21.0 and later become rollback-tolerant; 1.20.2 is already shipped and can only be repaired by the migration.

No typed cause was added — nothing branches on this. The fallback returns a row rather than throwing, so there is no TRPCError to classify, and the existing tRPC Sentry middleware behaviour is unchanged.

Verification

bunx biome check on the changed files:

$ bunx biome check packages/local-db/src/schema/schema.ts packages/cli/src/lib/settings/registry.ts apps/desktop/src/lib/trpc/routers/settings/index.ts
Checked 3 files in 35ms. No fixes applied.

Typecheck, each touched package:

$ cd packages/local-db && bun run typecheck
$ tsc --noEmit --emitDeclarationOnly false        # clean

$ cd packages/cli && bun run typecheck
$ tsc --noEmit                                    # clean

$ cd apps/desktop && bun run typecheck
$ tsc --noEmit                                    # clean

Tests (bun 1.3.14, matching .bun-version):

$ cd packages/cli && bun test src/lib/settings
 44 pass
 0 fail
 132 expect() calls
Ran 44 tests across 7 files. [187.00ms]

$ cd apps/desktop && bun test src/lib/trpc/routers/settings
 36 pass
 0 fail
 64 expect() calls
Ran 36 tests across 3 files. [79.00ms]

packages/local-db has no test files. Repo-wide bun run lint was deliberately not run (it hangs on cross-worktree bun locks).

End-to-end repro against the real driver

Throwaway script (not committed) run under ELECTRON_RUN_AS_NODE=1 electron, so it uses the same better-sqlite3 build the app ships: apply the full migration chain to a scratch local.db, write real settings values, then simulate the skew by dropping the column and reopening.

A. after full migrate, terminalPersistence = true
B. skewed select() throws: no such column: "persist_terminal" - should this be a string literal in single-quotes?
C. fallback recovers real values: {
  id: 1,
  confirmOnQuit: true,
  notificationVolume: 42,
  terminalPresets: [ { id: 'p1', name: 'preset one' } ],
  terminalPersistence: null
}
D. unrelated bad query still throws: no such column: nonexistent_column

A confirms 0047 restores the column with its original default, so an older build's select() works again. B reproduces the reported failure. C shows the fallback preserving real booleans and JSON while nulling only the missing column. D shows a genuine bad query is still not swallowed.

Driver note worth recording: this only reproduces on better-sqlite3, which compiles with SQLITE_DQS=0. Drizzle double-quotes identifiers, and a stock SQLite build (bun:sqlite, for instance) silently reinterprets an unresolvable double-quoted identifier as a string literal, returning garbage instead of erroring. An earlier bun:sqlite version of this script could not reproduce B at all.

Nothing was run against any shared or production database — this is the per-user local SQLite file, and the script used a scratch path.

Refs DESKTOP-VZ


https://claude.ai/code/session_f7985783-b18c-48cf-a169-a571d3cbce02


Summary by cubic

Restores the dropped settings column so older desktop builds can read settings after upgrade/downgrade. Previously, 1.20.2 reads failed with “no such column” after migration 0046; now migration 0047 re-adds persist_terminal (DEFAULT true). The speculative getSettings() schema-skew fallback was removed; no read-path behavior changes ship with this PR.

  • Adds migration 0047_restore_persist_terminal_column.sql; 0046 remains unchanged.
  • Re-declares persist_terminal in packages/local-db/src/schema/schema.ts as deprecated to prevent re-drop; current code does not use it.
  • Restores the exclusion in packages/cli/src/lib/settings/registry.ts for terminalPersistence.
  • Rollout: ship before cutting 1.21.0; no manual DB action. Do not delete or reorder 0046. Drop the column in a later release once 1.20.2 is out of circulation.
  • Satisfies DESKTOP-VZ by allowing 1.20.2 to read settings after newer builds touch local.db.

Summary by CodeRabbit

  • Bug Fixes

    • Improved compatibility when opening settings created by newer app versions.
    • Prevented unrelated settings errors from being hidden while preserving existing recovery behavior.
    • Added one-time reporting for settings schema mismatches to improve diagnostics.
  • Improvements

    • Restored support for retaining terminal session preferences across upgrades.
    • Preserved compatibility with legacy settings data without affecting current settings behavior.