sqlite

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package sqlite provides utility functions for SQLite database operations such as online backup and integrity verification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backup

func Backup(dbPath string) (backupPath string, err error)

Backup creates a safe online backup of a SQLite database using VACUUM INTO. VACUUM INTO produces a clean, defragmented copy of the database while allowing concurrent reads on the source. The backup file is named with a timestamp suffix (e.g., "loom.db.backup.20260224T153000"). On failure, any partially written backup file is removed before returning.

func VerifyBackup

func VerifyBackup(backupPath string) error

VerifyBackup opens a SQLite database file and runs PRAGMA integrity_check to confirm the file is a valid, uncorrupted SQLite database.

Types

type Migration

type Migration struct {
	Version     int
	Description string
	UpSQL       string
	DownSQL     string
}

Migration represents a single database migration step.

type Migrator

type Migrator struct {
	// contains filtered or unexported fields
}

Migrator manages SQLite schema migrations using embedded SQL files. Unlike the PostgreSQL migrator which uses advisory locks, this uses a sync.Mutex to prevent concurrent migration execution within the process.

func NewMigrator

func NewMigrator(db *sql.DB, tracer observability.Tracer) (*Migrator, error)

NewMigrator creates a new migrator with embedded SQL migrations. It sets PRAGMA busy_timeout = 5000 on the database to handle lock contention.

func (*Migrator) CurrentVersion

func (m *Migrator) CurrentVersion(ctx context.Context) (int, error)

CurrentVersion returns the highest applied migration version. Returns 0 if the schema_migrations table does not exist yet.

func (*Migrator) MigrateDown

func (m *Migrator) MigrateDown(ctx context.Context, steps int) error

MigrateDown rolls back the specified number of migrations.

func (*Migrator) MigrateUp

func (m *Migrator) MigrateUp(ctx context.Context) error

MigrateUp applies all pending migrations up to the latest version. Uses a sync.Mutex to prevent concurrent migration execution.

func (*Migrator) PendingMigrations

func (m *Migrator) PendingMigrations(ctx context.Context) ([]Migration, error)

PendingMigrations returns the list of migrations that have not yet been applied.

Jump to

Keyboard shortcuts

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