Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Migrate ¶
func Migrate(driver Driver, migrations MigrationSource, direction MigrationDirection, max int) (int, error)
Migrate runs a migration using a given driver and MigrationSource. The direction defines whether the migration is up or down, and max is the maximum number of migrations to apply. If max is set to 0, then there is no limit on the number of migrations to apply.
Types ¶
type AssetMigrationSource ¶
type AssetMigrationSource struct {
// Asset should return content of file in path if exists
Asset func(path string) ([]byte, error)
// AssetDir should return list of files in the path
AssetDir func(path string) ([]string, error)
// Path in the bindata to use.
Dir string
}
AssetMigrationSource is a MigrationSource that uses migration files embedded in a Go application.
func (AssetMigrationSource) GetMigrationFile ¶
func (a AssetMigrationSource) GetMigrationFile(name string) (io.Reader, error)
func (AssetMigrationSource) ListMigrationFiles ¶
func (a AssetMigrationSource) ListMigrationFiles() ([]string, error)
type Driver ¶
type Driver interface {
// Close is the last function to be called.
// Close any open connection here.
Close() error
// Migrate is the heart of the driver.
// It will receive a PlannedMigration which the driver should apply
// to its backend or whatever.
Migrate(migration *PlannedMigration) error
// Version returns all applied migration versions
Versions() ([]string, error)
}
Driver is the interface type that needs to implemented by all drivers.
type MemoryMigrationSource ¶
MemoryMigrationSource is a MigrationSource that uses migration sources in memory. It is mainly used for testing.
func (MemoryMigrationSource) GetMigrationFile ¶
func (m MemoryMigrationSource) GetMigrationFile(name string) (io.Reader, error)
func (MemoryMigrationSource) ListMigrationFiles ¶
func (m MemoryMigrationSource) ListMigrationFiles() ([]string, error)
type Migration ¶
Migration represents a migration, containing statements for migrating up and down.
func (Migration) NumberPrefixMatches ¶
func (Migration) VersionInt ¶
VersionInt converts the migration version to an 64-bit integer.
type MigrationSource ¶
type MigrationSource interface {
ListMigrationFiles() ([]string, error)
GetMigrationFile(file string) (io.Reader, error)
}
MigrationSource is an interface that defines how a source can find and read migration files.
type PlannedMigration ¶
type PlannedMigration struct {
*Migration
Direction MigrationDirection
}
PlannedMigration is a migration with a direction defined. This allows the driver to work out how to apply the migration.
