db

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package db provides database migration functionality using embedded filesystem for migration files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrInvalidSequenceNumber

func ErrInvalidSequenceNumber(seq int32) error

ErrInvalidSequenceNumber returns an error indicating an invalid sequence number.

func RunMigrations

func RunMigrations(ctx context.Context, logger Logger, connParams Configurator, fs FilesystemProvider, stopAfter int32, printSummary bool) (fault error)

RunMigrations runs the database migrations to the specified version.

Types

type Configurator

type Configurator interface {
	DatabaseURL() string
}

Configurator defines the interface for database configuration.

type DBMigrator

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

DBMigrator handles database migrations.

func NewMigrator

func NewMigrator(ctx context.Context, logger Logger, connParams Configurator, fs FilesystemProvider) (migrator DBMigrator, fault error)

NewMigrator creates a new DBMigrator instance.

func (DBMigrator) GetCurrentVersion

func (m DBMigrator) GetCurrentVersion() (currentVersion int32, fault error)

GetCurrentVersion retrieves the current migration version from the database.

func (DBMigrator) Info

func (m DBMigrator) Info(stopAfter int32) (information Info, fault error)

Info provides information about the current migration status.

func (*DBMigrator) Migrate

func (m *DBMigrator) Migrate() (fault error)

Migrate migrates the database to the latest version.

func (*DBMigrator) MigrateTo

func (m *DBMigrator) MigrateTo(sequence int32) (fault error)

MigrateTo migrates the database to the specified sequence number.

type FilesystemProvider

type FilesystemProvider interface {
	ReadDir(name string) ([]fs.FileInfo, error)
	ReadFile(name string) ([]byte, error)
	Open(name string) (fs.File, error)
}

FilesystemProvider defines the interface for providing migration files from a filesystem.

type Info

type Info struct {
	DBConnStr  string
	Port       string
	Database   string
	Migrations MigrationInfo
}

Info holds information about the current migration status.

type Logger

type Logger interface {
	Debug(msg string, ephemeralArgs ...any)
	Info(msg string, ephemeralArgs ...any)
	Error(msg string, err error, severity string, ephemeralArgs ...any)
}

Logger defines the logging interface used by the DBMigrator and allows go11y to be used to log messages.

type MigrationFS

type MigrationFS struct {
	FS embed.FS
}

MigrationFS provides methods to interact with an embedded filesystem for migrations.

func (MigrationFS) Glob

func (m MigrationFS) Glob(pattern string) (matches []string, fault error)

Glob returns the file paths matching the given pattern from the embedded filesystem.

func (MigrationFS) Open

func (m MigrationFS) Open(name string) (file fs.File, fault error)

Open opens a file from the embedded filesystem.

func (MigrationFS) ReadDir

func (m MigrationFS) ReadDir(name string) ([]fs.FileInfo, error)

ReadDir reads the directory from the embedded filesystem.

func (MigrationFS) ReadFile

func (m MigrationFS) ReadFile(name string) (contents []byte, fault error)

ReadFile reads a file from the embedded filesystem.

type MigrationInfo

type MigrationInfo struct {
	CurrentVersion int32
	TargetVersion  int32
	Stages         []Stage
	Summary        string
}

MigrationInfo holds information about the migration status.

type Stage

type Stage struct {
	Sequence int32
	Name     string
	Migrated bool
}

Stage represents a single migration stage.

Jump to

Keyboard shortcuts

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