Documentation
¶
Overview ¶
Package storagecheck states which database schemas a build can operate on and verifies a supplied SQLite file against that policy before a daemon serves requests or restores work. The check never migrates or repairs a database: an incompatible file is refused with the action its operator has to take. Upgrade applies the packaged migrations only when an operator runs it explicitly.
Index ¶
Constants ¶
const ( MinimumDispatcherVersion int64 = 9 MinimumExecutorVersion int64 = 5 )
Minimum supported schema versions. Every version from the minimum up to the version the packaged migrations produce is served without a migration step. Raise the minimum together with a migration the daemon's queries depend on: an older database can then no longer answer them and must be refused instead of failing later during service.
Variables ¶
var ( ErrAbsent = errors.New("database not found") ErrUnknown = errors.New("unknown database") ErrUnreadable = errors.New("unreadable database") ErrOutdated = errors.New("outdated database schema") ErrNewer = errors.New("newer database schema") ErrIncomplete = errors.New("incomplete database schema") )
Reasons a database is refused. An absent database, a readable one that is not ours, and a storage fault are separate answers for an operator.
Functions ¶
func Check ¶
Check verifies the database at path against the schema policy of the role. It opens the file read-only and leaves its bytes unchanged even when it refuses it, so a refused database can still be inspected or restored. A database in WAL mode can still gain the usual -wal and -shm companions.
func Upgrade ¶
Upgrade applies the packaged migrations of the role to the database at path and returns the schema version it then records, once Check accepts it. It first refuses, with Check's answers, a path that is absent, unreadable, not this role's Debuglet database, or newer than this build, and writes nothing to it. It takes no backup and expects the daemon using the file to be stopped. Each migration commits on its own, so a failed one leaves the earlier ones applied; Check then reports the version reached as outdated and a later Upgrade continues from it.
Types ¶
type Policy ¶
type Policy struct {
Role Role
// Minimum is the oldest schema version the daemon serves.
Minimum int64
// Current is the version the packaged migrations produce. A database
// beyond it was written by a newer Debuglet.
Current int64
// Identity lists tables, with columns, that only this role's database
// has and that it has carried since its first migration. They are
// checked before the version, so a path pointing at the other role's
// database is reported as the wrong file rather than as a wrong version.
Identity map[string][]string
// Tables lists the tables the supported schema must contain, with the
// columns that distinguish a completely applied schema from one whose
// migrations stopped halfway.
Tables map[string][]string
}
Policy is the schema contract of one database for this build.