Documentation ¶
Overview ¶
Package burrow allows for no-frills database migrations.
Index ¶
Constants ¶
const ( // DialectMySQL enables the use of GET_LOCK() and RELEASE_LOCK() in addition // to row-level locking on the migrations table, since MySQL doesn't // properly support normal transactions for table creation and alternation // queries. DialectMySQL dialect = 1 + iota // DialectPostgres enables Postgres-specific features. DialectPostgres // DialectPgx enables Postgres-specific features using the pgx driver, with // COPY support. DialectPgx )
Supported SQL Dialects. Pass one of these as an argument to New to enable dialect-specific features.
const DefaultStateTable = "migrations"
DefaultStateTable is the default name of the table where migration state is stored. It is created the first time Migrator.Migrate is called.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemorySource ¶
MemorySource is a Source implemented by an in-memory map
type Migration ¶
type Migrator ¶
type Migrator struct {
// contains filtered or unexported fields
}
Migrator is an instance that applies migrations to a database. A Migrator instance is stateful, and should only be used once after initialization. If you need to apply the same migration to multiple databases, or to the same database multiple times, create one Migrator instance for migration run.
func (*Migrator) AddSource ¶
AddSource adds a source to m. You may provide multiple sources, but the migration IDs returned must be unique across all sources.
func (*Migrator) Migrate ¶
Migrate performs the actual migration. It returns the number of successful migration scripts applied.
Migrate will create the state table if it does not exist. It will also lock the state table for each migration. If Migrate returns a non-nil error, it means that all migrations up to that point were applied successfully.
type Option ¶ added in v0.2.0
type Option interface {
// contains filtered or unexported methods
}
Option is a functional that can be used to configure a Burrow instance or source.
func Exclude ¶ added in v0.2.0
Exclude returns an Option that excludes migrations matching the given regular expression pattern.
func WithLogger ¶ added in v0.5.0
WithLogger allows setting a custom logger for logs.
A single INFO-level log is emitted for each migration, indicating whether it was run, or skipped. A failed migration logs an error, as well as returning the error value. All other information is logged at DEBUG level.
func WithStateTable ¶ added in v0.6.0
WithStateTable allows specifying a custom state table name.
type Source ¶
type Source interface { // Index returns a list of all available migration versions. Index(context.Context) ([]uint, error) // Migration is expected to return the numbered migration. Migration(_ context.Context, id uint) (*Migration, error) }
func FSSource ¶
FSSource returns a Source implemented by a directory of files. See FileSource for full description of behavior.