initSchema mishandles an unversioned database that already has the files table #11

Open
opened 2026-08-09 03:45:01 +02:00 by clawbot · 0 comments
Collaborator

initSchema (db.go:163-166) treats user_version == 0 as "empty database" and calls createSchema, which unconditionally runs CREATE TABLE files (db.go:176-191). If the database already has a files table but user_version is 0 — a database created by some other tool, a partially initialized file, or one whose user_version was reset — the user gets create schema: table files already exists, which explains nothing and suggests no action.

README §Database says a database whose schema version is not 1 is a fatal error, so the intended behaviour for an unrecognized database is a clear schema-version error, not a raw SQLite complaint.

Definition of done

  1. initSchema distinguishes a genuinely empty database from one that has a files table but no recognized version, and reports the latter with a clear fatal error naming the file and telling the operator to remove it and rescan.
  2. Alternatively createSchema uses CREATE TABLE IF NOT EXISTS — but only if the version is then still validated, so an unversioned foreign database is not silently adopted.
  3. A test creates a database with a bare files table and user_version = 0 and asserts the error message.
  4. make check green.
`initSchema` (`db.go:163-166`) treats `user_version == 0` as "empty database" and calls `createSchema`, which unconditionally runs `CREATE TABLE files` (`db.go:176-191`). If the database already has a `files` table but `user_version` is 0 — a database created by some other tool, a partially initialized file, or one whose `user_version` was reset — the user gets `create schema: table files already exists`, which explains nothing and suggests no action. README §Database says a database whose schema version is not 1 is a fatal error, so the intended behaviour for an unrecognized database is a clear schema-version error, not a raw SQLite complaint. ## Definition of done 1. `initSchema` distinguishes a genuinely empty database from one that has a `files` table but no recognized version, and reports the latter with a clear fatal error naming the file and telling the operator to remove it and rescan. 2. Alternatively `createSchema` uses `CREATE TABLE IF NOT EXISTS` — but only if the version is then still validated, so an unversioned foreign database is not silently adopted. 3. A test creates a database with a bare `files` table and `user_version = 0` and asserts the error message. 4. `make check` green.
clawbot added this to the 1.0.0 milestone 2026-08-09 03:45:01 +02:00
Sign in to join this conversation.