Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrBadFilenameFormat is returned if a migration file does not conform // with the expected name patter. Ex: 001_my-migration_up.sql ErrBadFilenameFormat = errors.New("bad-filename-format") // ErrInvalidDirection is returned if the direction of a migration is other // than 'up' or 'down' ErrInvalidDirection = errors.New("invalid-migration-direction") // ErrDBNotSupported is returned when trying to create a migrator instance // for an unsupported database. ErrDBNotSupported = errors.New("database-not-supported") // ErrInvalidDB is returned when a nil *sql.DB pointer is passed to NewMigrator ErrInvalidDB = errors.New("invalid-database-handle") // ErrMigrationFailed is returned when a migration failed to run ErrMigrationFailed = errors.New("migration-failed") )
Functions ¶
This section is empty.
Types ¶
type AssetDirFunc ¶
AssetDirFunc is the type that defines the function to access specific embedded dirs
type DBType ¶
type DBType string
DBType defines a type for specifying the databasse to use during migration.
const (
Postgres DBType = "postgres"
)
Supported databases.
type Migration ¶
type Migration struct {
ID string
Name string
Filename string `db:"filename"`
Up string
Down string
Status string
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
Migration represents an actual migration file.
type Migrator ¶
type Migrator interface {
// Init initializes migrations table in the given database.
Init() error
// Migrate applies all migrations that hasn't been applied.
Migrate() error
// Redo undos specific migrations and applies them again. By default
// if no parameter is specified, it will redo the latest migration.
Redo(n ...uint) error
// Rollback reverts the last migration if not parameter is specified.
Rollback(n ...uint) error
// Migrations returns the list of migrations currently applied to the database.
Migrations(ids ...string) ([]*Migration, error)
// Up applies a specific migration version.
Up(version string) error
// Down rolls back or takes down a specific migration version.
Down(version string) error
}
Migrator defines the set of functions used by this package.
func NewMigrator ¶
func NewMigrator(db *sql.DB, dbType DBType, assetFunc AssetFunc, assetDirFunc AssetDirFunc) (Migrator, error)
NewMigrator creates a new instance of the migration process, based on the database type provided.
Click to show internal directories.
Click to hide internal directories.