Documentation ¶
Overview ¶
Package migrate provides a dead simple Go package for performing sql migrations using database/sql.
Index ¶
Constants ¶
const DefaultTable = "schema_migrations"
DefaultTable The default table to store what migrations have been run.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Migration ¶
type Migration struct { // ID is a unique, numeric, identifier for this migration. ID int // Up is a function that gets called when this migration should go up. Up func(tx *sql.Tx) error // Down is a function that gets called when this migration should go // down. Down func(tx *sql.Tx) error }
Migration represents a sql migration that can be migrated up or down.
type MigrationError ¶
MigrationError is an error that gets returned when an individual migration fails.
func (*MigrationError) Error ¶
func (e *MigrationError) Error() string
Error implements the error interface.
type Migrator ¶
type Migrator struct { // Table is the table to store what migrations have been run. The zero // value is DefaultTable. Table string // Locker is a sync.Locker to use to ensure that only 1 process is // running migrations. sync.Locker // The TransactionMode to use. The zero value is IndividualTransactions, // which runs each migration in it's own transaction. TransactionMode TransactionMode // contains filtered or unexported fields }
Migrator performs migrations.
func NewMigrator ¶
NewMigrator returns a new Migrator instance that will use the sql.DB to perform the migrations.
func NewPostgresMigrator ¶
NewPostgresMigrator returns a new Migrator instance that uses the underlying sql.DB connection to a postgres database to perform migrations. It will use Postgres's advisory locks to ensure that only 1 migration is run at a time.
type TransactionMode ¶
type TransactionMode int
const ( // IndividualTransactions In this mode, each migration is run in it's own isolated transaction. // If a migration fails, only that migration will be rolled back. IndividualTransactions TransactionMode = iota // SingleTransaction In this mode, all migrations are run inside a single transaction. If // one migration fails, all migrations are rolled back. SingleTransaction )