Documentation
¶
Overview ¶
Package migrate applies SQL schema migrations to one SQLite database (PLAN §4, decided instead of goose).
Rules:
- Files are named NNNN_description.sql; versions start at 1 and have no gaps.
- Forward only: there are no down migrations. Going back means restoring a backup (myownpki restore).
- Each migration runs in its own transaction together with its bookkeeping row, so a crash leaves it either fully applied or not at all.
- The SHA-256 of every applied file is stored. A file that changed after it was applied, or a database migrated by a newer binary, stops everything: the schema history of a CA must not diverge silently.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrInvalidSet is returned for a malformed set of migration files. ErrInvalidSet = errors.New("invalid migration set") // ErrModified means an applied migration file has changed since. ErrModified = errors.New("applied migration was modified") // ErrNewer means the database has migrations this binary doesn't know. ErrNewer = errors.New("database was migrated by a newer version") )
Functions ¶
Types ¶
type Migration ¶
type Migration struct {
Version int
Name string // file name without the version and .sql
SQL string
Checksum string // hex SHA-256 of the file with LF line endings
}
Migration is one SQL file.
type Querier ¶
type Querier interface {
QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
}
Querier is satisfied by *sql.DB and *sql.Tx.
type Report ¶
type Report struct {
Migrations []Status
}
Report is the migration state of a database.
func Check ¶
Check compares the database with the migration set without changing anything. It returns ErrModified or ErrNewer when they don't fit together.
Click to show internal directories.
Click to hide internal directories.