initSchema mishandles an unversioned database that already has the files table #11
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
initSchema(db.go:163-166) treatsuser_version == 0as "empty database" and callscreateSchema, which unconditionally runsCREATE TABLE files(db.go:176-191). If the database already has afilestable butuser_versionis 0 — a database created by some other tool, a partially initialized file, or one whoseuser_versionwas reset — the user getscreate 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
initSchemadistinguishes a genuinely empty database from one that has afilestable 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.createSchemausesCREATE TABLE IF NOT EXISTS— but only if the version is then still validated, so an unversioned foreign database is not silently adopted.filestable anduser_version = 0and asserts the error message.make checkgreen.