You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 60340ff
Browse filesBrowse the repository at this point in the historyBrowse files
fix: [#1203] --dir silently read a populated warehouse store as empty
`--dir` calls `process.chdir()` (`cli/cmd/run.ts:412`). `ConnectionRegistry`
never absolutized the `path` field, so a relative store path in a connection
config resolved against whatever working directory the process happened to
have when the driver opened it. Both file-backed drivers then answered the
miss by CREATING an empty database — `new duckdb.Database(path)` in
`drivers/src/duckdb.ts`, `create: !isReadonly` in `drivers/src/sqlite.ts`.
Every query afterwards succeeded and returned zero rows, with no error and no
fault signal for a caller to key on.
Two fixes, either of which breaks the chain; both are needed because the
second is the root hazard and is independent of `--dir`:
1. Resolve store paths deterministically. `resolveStorePaths()` absolutizes a
relative `path` once, at config-load time, against the directory that
declared it — global config against `~/.altimate-code`, project config and
`ALTIMATE_CODE_CONN_*` against the project root. A later `chdir` cannot
move it. `warehouse_add` persists the absolute form for the same reason.
The project root comes from `Instance.directory`, not `process.cwd()`. A
server or `run --attach` session never chdirs — it carries the project in
the instance context and leaves cwd at the server's launch directory — so
cwd there is somebody else's project. `localConfigPath()` had that bug
already; absolutizing at load time would have baked it in permanently.
2. Never conjure a store that was meant to exist. New
`drivers/src/file-store.ts` holds `assertStoreExists()`, which both
file-backed drivers call before opening: a missing local file throws an
error naming the path it looked for. Creation is opt-in via `create: true`,
which `schema_sync` and `test_local` — the two tools that deliberately
materialize a scratch store — now pass. Exempt from the check: the exact
string `:memory:`, an empty path, and scheme-qualified targets (`md:`,
`s3://`, `ducklake:`, anything a DuckDB extension provides), which the
driver reports as an unknown scheme rather than creating. Only the EXACT
`:memory:` — DuckDB writes a real file for `:memory:named` and for `:foo`,
so those stay inside the guard. Windows drive letters stay paths.
`bun:sqlite` rejects an options object with no open flag, so the SQLite driver
now passes `readwrite` explicitly where `create` used to imply it.
Relative SQLite `file:` URIs are deliberately NOT handled here, and are filed
as #1209 with the evidence. They follow cwd the same way, but `bun:sqlite`
parses `file:` as a URI on macOS and appears to treat it as a literal filename
on Linux, and Windows is unverified. A rewrite changes which database opens,
so shipping one across platforms it has not been proven on would create the
same class of defect this fixes.
Verified through a compiled binary built with the production build options,
invoked with `--dir` from an unrelated working directory. Before: `tables: []`
plus a stray `warehouse.db` (+ `-wal`, `-shm`) written into the `--dir` target;
the DuckDB arm left a 12,288-byte stray `.duckdb`. After: the real table, and
nothing created. `test/altimate/store-path-resolution.test.ts` compiles that
binary and runs five arms — including a server-style request driven through
`Instance.provide` with a decoy config and store in the launch directory — of
which three fail on unmodified main.
Existing tests that relied on create-on-open to build their own scratch store
now pass `create: true`.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VqnuBDGkh1ZT65Ti7e6DHZ
Copy file name to clipboardExpand all lines: docs/docs/configure/warehouses.md
+26Lines changed: 26 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -262,6 +262,26 @@ If you're already authenticated via `gcloud`, omit `credentials_path`:
262
262
| Field | Required | Description |
263
263
|-------|----------|-------------|
264
264
|`path`| No | Database file path. Omit or use `":memory:"` for in-memory |
265
+
|`create`| No | Create the database file if it is missing (default: `false`) |
266
+
267
+
!!! warning "The store must already exist"
268
+
Connecting never creates the database. If the file is missing, the connection
269
+
fails with an error naming the path it looked for — an empty database would
270
+
otherwise answer every query with no rows and no error, which reads as a
271
+
successful query against an empty warehouse. Set `"create": true` only when
272
+
you intend this store to be created.
273
+
274
+
!!! note "How a relative `path` is resolved"
275
+
A relative `path` is resolved once, when the config is loaded, against the
276
+
directory that declares it:
277
+
278
+
- `~/.altimate-code/connections.json` → resolved against `~/.altimate-code`
279
+
- `<project>/.altimate-code/connections.json` → resolved against `<project>`
280
+
- `ALTIMATE_CODE_CONN_*` environment variables → resolved against the project root
281
+
282
+
It is never resolved against the current working directory, so `--dir` cannot
283
+
re-point an existing connection at a different file. Absolute paths are always
284
+
safest.
265
285
266
286
!!! note "Concurrent access"
267
287
DuckDB does not support concurrent write access to the same file. If another process holds a write lock, Altimate Code automatically retries the connection in **read-only** mode so you can still query the data. A clear error message is shown if read-only access also fails.
@@ -443,10 +463,16 @@ If you're already authenticated via `gcloud`, omit `credentials_path`:
443
463
|-------|----------|-------------|
444
464
|`path`| No | Database file path. Omit or use `":memory:"` for in-memory |
445
465
|`readonly`| No | Open in read-only mode (default: `false`) |
466
+
|`create`| No | Create the database file if it is missing (default: `false`) |
446
467
447
468
!!! note
448
469
SQLite uses Bun's built-in `bun:sqlite` driver. WAL journal mode is enabled automatically for writable databases.
449
470
471
+
!!! warning "The store must already exist"
472
+
As with DuckDB, connecting never creates the database, and a relative `path`
473
+
resolves against the directory of the config that declares it — not the current
474
+
working directory. See the DuckDB section above for the full rules.
0 commit comments