Repository navigation
Description
Summary
After deleting (or first-time creation of) `<GFLOW_CLI_HOME>/gflow.db`, `gflow data list profiles` crashes:
```
Data store error: Data store error: Catalog query failed: no such table: assets
```
Cause
`src/gflow_cli/data/queries.py:24-37` (`_safe_db`) opens a raw `sqlite3.connect(db_path)` and never invokes `DataStore.apply_migrations()`. `sqlite3.connect` auto-creates an empty DB file if missing, but the schema is never installed → first query fails with `no such table: assets`.
By contrast `gflow_cli/data/store.py:153` `DataStore.open` always runs migrations on a fresh file. `data media` (which goes through `DataStore.open`) works on the empty DB; `data list` does not.
Repro (Windows path; same on Linux/macOS)
```bash
$ rm "$(.venv/Scripts/python.exe -c 'from gflow_cli.config import get_settings; print(get_settings().resolved_db_path())')"
$ gflow data list profiles
Data store error: Data store error: Catalog query failed: no such table: assets
$ gflow data list videos # same crash for all list subcommands
```
Impact
- First-time users on a clean install see this error on the very first `gflow data list` they run before any generation has been recorded.
- Anyone who clears the DB to recover from test isolation: DataStore writes leak into user's production gflow.db during pytest #86 (test pollution) hits this immediately.
- Inconsistent with `gflow data media ` which handles the empty case gracefully ("No local media record found").
Proposed fix
Two options:
Option A — `_safe_db` delegates to `DataStore.open`. Replace the raw `sqlite3.connect` in `_safe_db` with `DataStore.open(db_path)`, yield `store.conn`. Reuses the existing migration path; consistent with `data media`.
Option B — query functions defend against missing schema. Catch `sqlite3.OperationalError("no such table")` and return empty lists. Mirrors how a fresh catalog "has no rows."
Recommendation: Option A. Treating the DB-open path as the single source of truth keeps migrations in one place and prevents future schema-drift bugs.
Files
- `src/gflow_cli/data/queries.py` — replace `_safe_db` body with `DataStore.open` delegation
- `tests/test_data_queries.py` — new test: empty DB path → `list_*` returns `[]` without raising
- `tests/cli/test_cli_data.py` — CLI-level test: `data list videos` on missing-file DB exits 0 with no rows
Acceptance
After deleting the catalog DB, `gflow data list profiles | images | videos | projects` all return empty output (or "no rows") with exit 0 — no `no such table` errors.
Discovered while cleaning the polluted DB to recover from #86 (2026-05-26).
Activity
polish(data): kind in disambiguation hint + LIVE_VERIFICATION note
fix(data): queries auto-migrate on empty/missing DB (#88)
polish(data): kind in disambiguation hint + LIVE_VERIFICATION note
docs(data): document cross-profile media + empty-DB list contracts
Merge pull request #89 from ffroliva/bugfix/data-list-and-media-fixes
fix(data): queries auto-migrate on empty/missing DB (ffroliva#88)
polish(data): kind in disambiguation hint + LIVE_VERIFICATION note
docs(data): document cross-profile media + empty-DB list contracts
Merge pull request ffroliva#89 from ffroliva/bugfix/data-list-and-med…