Documentation ¶
Index ¶
Constants ¶
const DefaultTableName = "schema_migrations"
DefaultTableName defines the name of the database table which will hold the status of applied migrations
Variables ¶
var ErrNilDB = errors.New("DB pointer is nil")
ErrNilDB is thrown when the database pointer is nil
var Postgres = postgresDialect{}
Postgres is the dialect for Postgres-compatible databases
Functions ¶
func MigrationIDFromFilename ¶
MigrationIDFromFilename removes directory paths and extensions from the filename to make a friendlier Migration ID
func SortMigrations ¶
func SortMigrations(migrations []*Migration)
SortMigrations sorts a slice of migrations by their IDs
Types ¶
type AppliedMigration ¶
type AppliedMigration struct { Migration Checksum string ExecutionTimeInMillis int AppliedAt time.Time }
AppliedMigration is a schema change which was successfully completed
type Dialect ¶
type Dialect interface { QuotedTableName(schemaName, tableName string) string LockSQL(tableName string) string UnlockSQL(tableName string) string CreateSQL(tableName string) string SelectSQL(tableName string) string InsertSQL(tableName string) string }
Dialect defines the interface for a database dialect. All interface functions take the customized table name as input and return a SQL statement with placeholders appropriate to the database.
type Logger ¶ added in v1.1.9
type Logger interface {
Print(...interface{})
}
Logger is the interface for logging operations of the logger. By default the migrator operates silently. Providing a Logger enables output of the migrator's operations.
type Migration ¶
Migration is a yet-to-be-run change to the schema
func MigrationFromFile ¶
MigrationFromFile builds a migration by reading from an open File-like object. The migration's ID will be based on the file's name. The file will *not* be closed after being read.
func MigrationFromFilePath ¶
MigrationFromFilePath creates a Migration from a path on disk
func MigrationsFromDirectoryPath ¶
MigrationsFromDirectoryPath retrieves a slice of Migrations from the contents of the directory. Only .sql files are read
type Migrator ¶
Migrator is an instance customized to perform migrations on a particular against a particular tracking table and with a particular dialect defined.
func NewMigrator ¶
NewMigrator creates a new Migrator with the supplied options
func (Migrator) Apply ¶
Apply takes a slice of Migrations and applies any which have not yet been applied
func (Migrator) GetAppliedMigrations ¶
func (m Migrator) GetAppliedMigrations(db Queryer) (applied map[string]*AppliedMigration, err error)
GetAppliedMigrations retrieves all already-applied migrations in a map keyed by the migration IDs
func (Migrator) QuotedTableName ¶
QuotedTableName returns the dialect-quoted fully-qualified name for the migrations tracking table
type Option ¶
Option supports option chaining when creating a Migrator. An Option is a function which takes a Migrator and returns a Migrator with an Option modified.
func WithDialect ¶
WithDialect builds an Option which will set the supplied dialect on a Migrator. Usage: NewMigrator(WithDialect(MySQL))
func WithLogger ¶ added in v1.1.9
WithLogger builds an Option which will set the supplied Logger on a Migrator. Usage: NewMigrator(WithLogger(logrus.New()))
func WithTableName ¶
WithTableName is an option which customizes the name of the schema_migrations tracking table. It can be called with either 1 or 2 string arguments. If called with 2 arguments, the first argument is assumed to be a schema qualifier (for example, WithTableName("public", "schema_migrations") would assign the table named "schema_migrations" in the the default "public" schema for Postgres)