storagecheck

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

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

View Source
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

View Source
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

func Check(ctx context.Context, role Role, path string) error

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

func Upgrade(ctx context.Context, role Role, path string) (int64, error)

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 ForeignKeyViolation

type ForeignKeyViolation struct {
	Table  string
	Parent string
	Rows   int
}

ForeignKeyViolation counts the rows of Table that reference a missing row of Parent.

func ForeignKeyViolations

func ForeignKeyViolations(ctx context.Context, path string) ([]ForeignKeyViolation, error)

ForeignKeyViolations reports the rows of the database at path whose references PRAGMA foreign_key_check finds broken. The daemons enforce foreign keys only on new writes, so rows written before they did stay as they are; this is how an operator learns of them. It opens the database read-only and changes nothing.

func (ForeignKeyViolation) String

func (v ForeignKeyViolation) String() string

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.

func PolicyFor

func PolicyFor(role Role) (Policy, error)

PolicyFor returns the schema policy of the given role.

func (Policy) Check

func (p Policy) Check(ctx context.Context, path string) error

Check verifies one database against this policy.

func (Policy) Supports

func (p Policy) Supports(version int64) bool

Supports reports whether a schema version is inside the supported range.

type Role

type Role string

Role names one of the two databases a local environment keeps.

const (
	Dispatcher Role = "dispatcher"
	Executor   Role = "executor"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL