Refuse an unversioned database that already has a files table (closes #11) #58

Open
clawbot wants to merge 1 commits from issue-11-unversioned-db-error into next
Collaborator

Fixes #11 .

scan treated any database with user_version 0 as empty and ran an unconditional CREATE TABLE files. A foreign or partially initialized file that already had a files table therefore failed with the raw SQLite table files already exists, which explains nothing and suggests no action.

createSchema now checks for an existing files table before creating one. At version 0 with a files table present it returns the schema-version error (errSchemaVersion) telling the operator to remove the file and rescan, so an unrecognized database is fatal per README.md and is never silently adopted. A genuinely empty database is unchanged.

The change stays inside initSchema/createSchema; openDB is untouched. The operator-facing file path comes from the existing openScanDatabase wrap (database <path>: ...).

Trip hazard: the guard only fires at user_version 0. A file already carrying a non-zero, non-matching version still takes the existing version-mismatch path.

Test: a database with a bare files table and user_version 0 is opened for scan and must fail with errSchemaVersion and the remove-and-rescan guidance.

Model: opus-4-8

Fixes https://git.eeqj.de/sneak/sfdupes/issues/11 . `scan` treated any database with `user_version` 0 as empty and ran an unconditional `CREATE TABLE files`. A foreign or partially initialized file that already had a `files` table therefore failed with the raw SQLite `table files already exists`, which explains nothing and suggests no action. `createSchema` now checks for an existing `files` table before creating one. At version 0 with a `files` table present it returns the schema-version error (`errSchemaVersion`) telling the operator to remove the file and rescan, so an unrecognized database is fatal per `README.md` and is never silently adopted. A genuinely empty database is unchanged. The change stays inside `initSchema`/`createSchema`; `openDB` is untouched. The operator-facing file path comes from the existing `openScanDatabase` wrap (`database <path>: ...`). Trip hazard: the guard only fires at `user_version` 0. A file already carrying a non-zero, non-matching version still takes the existing version-mismatch path. Test: a database with a bare `files` table and `user_version` 0 is opened for scan and must fail with `errSchemaVersion` and the remove-and-rescan guidance. Model: opus-4-8
clawbot added the needs-review label 2026-09-21 09:23:33 +02:00
clawbot self-assigned this 2026-09-21 09:23:33 +02:00
Author
Collaborator

Findings:

  • TODO.md, new Completed Steps entry: it is four physical lines and restates the rationale ("instead of a raw SQLite ..."). The entry cap is three lines and no narration. Acceptable: a three-line entry giving what landed, the date, and the full issue URL, without the raw-SQLite explanation.

The code change is otherwise correct: an unversioned database carrying a files table is refused with the schema-version error naming the file and telling the operator to remove it and rescan, a genuinely empty database is unchanged, the test covers it, and the gate is green on the current next head.

Model: opus-4-8

Findings: - `TODO.md`, new Completed Steps entry: it is four physical lines and restates the rationale ("instead of a raw SQLite ..."). The entry cap is three lines and no narration. Acceptable: a three-line entry giving what landed, the date, and the full issue URL, without the raw-SQLite explanation. The code change is otherwise correct: an unversioned database carrying a `files` table is refused with the schema-version error naming the file and telling the operator to remove it and rescan, a genuinely empty database is unchanged, the test covers it, and the gate is green on the current `next` head. Model: opus-4-8
clawbot added needs-rework and removed needs-review labels 2026-09-21 09:43:26 +02:00
Author
Collaborator
  • TODO.md entry: trimmed to three lines and dropped the raw-SQLite narration; it now gives what landed, the date, and the issue URL.

Model: opus-4-8

- `TODO.md` entry: trimmed to three lines and dropped the raw-SQLite narration; it now gives what landed, the date, and the issue URL. Model: opus-4-8
clawbot added needs-review and removed needs-rework labels 2026-09-21 10:01:02 +02:00
clawbot added needs-rebase and removed needs-review labels 2026-09-21 15:02:19 +02:00
clawbot added 1 commit 2026-09-22 00:51:50 +02:00
An unversioned database (user_version 0) that already contains a files
table was not created by this build; it is a foreign or partially
initialized file. Adopting it silently could corrupt unrelated data, so
createSchema now checks for a files table first and, when one exists,
returns the schema-version error telling the operator to remove the file
and rescan. A genuinely empty database is still created and stamped as
before.

Model: opus-4-8
clawbot force-pushed issue-11-unversioned-db-error from d111b3c665 to dd405054fe 2026-09-22 00:51:50 +02:00 Compare
clawbot added needs-review and removed needs-rebase labels 2026-09-22 00:52:21 +02:00
Author
Collaborator

Rebased onto current next (which now includes #22) and squashed to one commit. Only the TODO.md Completed Steps conflict needed resolving; both entries are kept. No change to the code or tests — the earlier review finding stays fixed.

Disclosure: this PR's TODO entry now uses the three-line what/date/URL form and no longer names a branch, per the Completed Steps rule.

Model: opus-4-8

Rebased onto current `next` (which now includes https://git.eeqj.de/sneak/sfdupes/issues/22) and squashed to one commit. Only the TODO.md Completed Steps conflict needed resolving; both entries are kept. No change to the code or tests — the earlier review finding stays fixed. Disclosure: this PR's TODO entry now uses the three-line what/date/URL form and no longer names a branch, per the Completed Steps rule. Model: opus-4-8
Some required checks failed
check / check (push) Failing after 1s
You are not authorized to merge this pull request.
This pull request can be merged automatically.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin issue-11-unversioned-db-error:issue-11-unversioned-db-error
git checkout issue-11-unversioned-db-error
Sign in to join this conversation.