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 ¶
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 ¶
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.