Documentation ¶
Overview ¶
Package migration is a simple and pragmatic migration tool for Go.
Index ¶
- func Migrate(driver Driver, migrations Source, direction Direction, max int) (int, error)
- func SetLogger(l *log.Logger)
- type Direction
- type Driver
- type EmbedMigrationSource
- type GolangMigrationSource
- func (s *GolangMigrationSource) AddMigration(file string, direction Direction, migration func() error)
- func (s *GolangMigrationSource) GetMigration(file string) func() error
- func (s *GolangMigrationSource) GetMigrationFile(file string) (io.Reader, error)
- func (s *GolangMigrationSource) ListMigrationFiles() ([]string, error)
- type MemoryMigrationSource
- type Migration
- type PlannedMigration
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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 EmbedMigrationSource ¶ added in v0.21.0
EmbedMigrationSource uses an embed.FS that is used to embed files natively in Go 1.16+
func (EmbedMigrationSource) GetMigrationFile ¶ added in v0.21.0
func (e EmbedMigrationSource) GetMigrationFile(name string) (io.Reader, error)
GetMigrationFile gets an embedded migration file
func (EmbedMigrationSource) ListMigrationFiles ¶ added in v0.21.0
func (e EmbedMigrationSource) ListMigrationFiles() ([]string, error)
ListMigrationFiles returns a list of embedded migration files
type GolangMigrationSource ¶ added in v0.15.0
GolangMigrationSource implements migration.Source
func NewGolangMigrationSource ¶ added in v0.15.0
func NewGolangMigrationSource() *GolangMigrationSource
NewGolangMigrationSource creates a source for storing Go functions as migrations.
func (*GolangMigrationSource) AddMigration ¶ added in v0.15.0
func (s *GolangMigrationSource) AddMigration(file string, direction Direction, migration func() error)
AddMigration adds a new migration to the source. The file parameter follows the same conventions as you would use for a physical file for other types of migrations, however you should omit the file extension. Example: 1_init.up and 1_init.down
func (*GolangMigrationSource) GetMigration ¶ added in v0.15.0
func (s *GolangMigrationSource) GetMigration(file string) func() error
GetMigration gets a golang migration
func (*GolangMigrationSource) GetMigrationFile ¶ added in v0.15.0
func (s *GolangMigrationSource) GetMigrationFile(file string) (io.Reader, error)
GetMigrationFile retrieves a migration given the filename.
func (*GolangMigrationSource) ListMigrationFiles ¶ added in v0.15.0
func (s *GolangMigrationSource) ListMigrationFiles() ([]string, error)
ListMigrationFiles lists the available migrations in the source
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)
GetMigrationFile gets a memory migration file
func (MemoryMigrationSource) ListMigrationFiles ¶
func (m MemoryMigrationSource) ListMigrationFiles() ([]string, error)
ListMigrationFiles returns a list of memory migration files
type Migration ¶
type Migration struct { ID string Up *parser.ParsedMigration Down *parser.ParsedMigration }
Migration represents a migration, containing statements for migrating up and down.
func (Migration) NumberPrefixMatches ¶
NumberPrefixMatches returns a list of string matches
func (Migration) VersionInt ¶
VersionInt converts the migration version to an 64-bit integer.
type PlannedMigration ¶
PlannedMigration is a migration with a direction defined. This allows the driver to work out how to apply the migration.