Documentation
¶
Overview ¶
Package dbverify runs SQLite integrity checks against the cloop state database.
It exposes a Verify() function used by both the `cloop db verify` CLI command and `cloop doctor` so that silent on-disk corruption (after a crash, a disk error, or a partial write) is surfaced before it manifests as a confusing runtime failure deeper in the stack.
The package opens its own read-only handle — statedb.OpenConn, the connection policy's reader, not statedb.Open — and runs only PRAGMA integrity_check / quick_check / foreign_key_check. We avoid statedb.Open here because:
- statedb.Open executes the CREATE TABLE schema, which would mutate a freshly-corrupted database during a read-only diagnostic.
- statedb.Open enables WAL mode, which writes -wal/-shm sidecar files even on a verify-only path.
A directly-opened, read-only handle keeps verification truly side-effect-free.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ForeignKeyViolation ¶
ForeignKeyViolation describes one row returned by PRAGMA foreign_key_check.
Columns (per https://www.sqlite.org/pragma.html#pragma_foreign_key_check):
table — name of the child table rowid — rowid of the offending row in the child table (NULL for views) parent — name of the parent table the FK should reference fkid — index of the failed FK constraint within the child table
type Report ¶
type Report struct {
// DBPath is the path of the database that was checked.
DBPath string
// QuickCheck is true if PRAGMA quick_check was used instead of
// the slower-but-more-thorough PRAGMA integrity_check.
QuickCheck bool
// IntegrityIssues holds the rows returned by integrity_check / quick_check.
// A clean database returns a single row containing the literal string "ok"
// — Verify normalises that into an empty slice so callers can simply
// check len(IntegrityIssues) == 0.
IntegrityIssues []string
// ForeignKeyViolations holds rows returned by PRAGMA foreign_key_check.
// Each row identifies a child row that does not satisfy its FK constraint.
ForeignKeyViolations []ForeignKeyViolation
}
Report summarises the result of an integrity verification run.
func Verify ¶
Verify runs PRAGMA integrity_check (or quick_check when quick is true) and PRAGMA foreign_key_check against the SQLite database at dbPath.
Returns a populated *Report describing any issues found. A nil error with report.OK() == true means the database is structurally sound. Any error returned indicates Verify itself could not run (file missing, driver failure, etc.) — distinct from "ran successfully but found corruption".