Documentation
¶
Overview ¶
Package migrator implements database migration functionalities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var FilenameRgx = regexp.MustCompile(`^(\d+)_(.*)\.sql$`)
FilenameRgx is the regular expression to match migration filenames.
Functions ¶
This section is empty.
Types ¶
type DuplicateMigrationVersionError ¶
type DuplicateMigrationVersionError struct {
Version int
}
DuplicateMigrationVersionError is returned when there are multiple migrations with the same version.
func (DuplicateMigrationVersionError) Error ¶
func (e DuplicateMigrationVersionError) Error() string
type EmptyMigrationError ¶
type EmptyMigrationError struct {
Filename string
}
EmptyMigrationError is returned when a migration file is empty.
func (EmptyMigrationError) Error ¶
func (e EmptyMigrationError) Error() string
type InvalidCurrentVersionError ¶
type InvalidCurrentVersionError struct {
Version int
}
InvalidCurrentVersionError is returned when the current database version does not correspond to any migration.
func (InvalidCurrentVersionError) Error ¶
func (e InvalidCurrentVersionError) Error() string
type InvalidMigrationFileError ¶
type InvalidMigrationFileError struct {
Filename string
}
InvalidMigrationFileError is returned when a migration file foramt is invalid.
func (InvalidMigrationFileError) Error ¶
func (e InvalidMigrationFileError) Error() string
type InvalidMigrationFilenameError ¶
type InvalidMigrationFilenameError struct {
Filename string
}
InvalidMigrationFilenameError is returned when a migration filename does not match the expected pattern.
func (InvalidMigrationFilenameError) Error ¶
func (e InvalidMigrationFilenameError) Error() string
type Migration ¶
type Migration struct {
// contains filtered or unexported fields
}
Migration represents a database migration.
type Migrator ¶
type Migrator interface {
// Migrate applies all pending database migrations.
Migrate() error
// Version returns the current version of the database schema.
Version() (int, error)
}
Migrator is the interface to manage database migrations.
func New ¶
New creates a new Migrator instance.
It loads migrations from the provided fs.FS and checks the current database version. If the schema_migrations table does not exist, it creates it.
It can returns the following errors:
- InvalidMigrationFilenameError
- InvalidMigrationFileError
- EmptyMigrationError
- DuplicateMigrationVersionError
- MissingMigrationVersionError
type MissingMigrationVersionError ¶
type MissingMigrationVersionError struct {
Version int
}
MissingMigrationVersionError is returned when a migration version is missing in the sequence.
func (MissingMigrationVersionError) Error ¶
func (e MissingMigrationVersionError) Error() string