persistence

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package persistence manages the agent's SQLite database: opening it with the pragmas Patchcord relies on, and applying versioned migrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, db *sql.DB, fsys fs.FS, logger *slog.Logger) error

Migrate brings db up to date with every migration found in fsys, applying each one exactly once inside its own transaction, in ascending version order. Already-applied migrations are skipped, so Migrate is safe to call on every agent startup.

func Open

func Open(dataDir string) (*sql.DB, error)

Open creates dataDir if needed and opens the agent's SQLite database inside it, with foreign keys enforced, WAL journaling, and a busy timeout so concurrent access waits instead of failing immediately.

Types

type Migration

type Migration struct {
	Version int
	Name    string
	SQL     string
}

Migration is one versioned, ordered step of the database schema.

func LoadMigrations

func LoadMigrations(fsys fs.FS) ([]Migration, error)

LoadMigrations reads and orders every *.sql file in fsys. File names must follow the "NNNN_name.sql" convention, e.g. "0001_init.sql".

Jump to

Keyboard shortcuts

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