Documentation
¶
Overview ¶
Package database opens the SQLite database, applies the embedded, versioned migrations (always after a verified backup) and makes verified online backups (spec 7.6).
Index ¶
- Variables
- func Backup(ctx context.Context, db *sql.DB, s BackupSettings, now time.Time) (string, error)
- func LatestVersion() int
- func List(dir string) ([]string, error)
- func Migrate(ctx context.Context, db *sql.DB, backup BackupFunc, now time.Time) error
- func Newest(dir string) (time.Time, error)
- func Open(ctx context.Context, path string) (*sql.DB, error)
- func OpenReadOnly(ctx context.Context, path string) (*sql.DB, error)
- func Prune(dir string, keep int) error
- func Verify(ctx context.Context, path string) error
- func Version(ctx context.Context, db *sql.DB) (int, error)
- type BackupFunc
- type BackupSettings
Constants ¶
This section is empty.
Variables ¶
var ErrBackupInvalid = errors.New("database: backup failed integrity check")
ErrBackupInvalid means integrity_check of a new backup failed; the file was deleted.
var ErrTooNew = errors.New("database: schema is newer than this binary")
ErrTooNew means the database was written by a newer pvmon.
Functions ¶
func Backup ¶
Backup writes a verified online backup (VACUUM INTO + integrity_check), copies the secret key next to it and prunes old backups. It returns the backup path.
func LatestVersion ¶
func LatestVersion() int
LatestVersion returns the schema version of this binary.
func Migrate ¶
Migrate brings the schema to LatestVersion. A non-empty database is backed up first; a newer database is refused with ErrTooNew.
func OpenReadOnly ¶
OpenReadOnly opens an existing database file read-only (mode=ro), e.g. the solis database of an import; a missing file fails instead of creating one.
Types ¶
type BackupFunc ¶
BackupFunc makes and verifies a backup before a migration of a non-empty database.
type BackupSettings ¶
type BackupSettings struct {
Dir string // backup directory
KeyFile string // data/secret.key; skipped while it does not exist
MaxBackups int
}
BackupSettings locates backups and the secret key that belongs to them.