Documentation ¶
Index ¶
- Variables
- func Execute(driver Driver, events EventHandler, namespace string, timeout time.Duration) (err error)
- func MustRegisterFS(namespace string, in fs.FS)
- func Register(namespace string, migration Migration)
- func RegisterFS(namespace string, in fs.FS) error
- type Driver
- type EventHandler
- type Migration
- type Migrations
- type MySQLDriver
- func (d *MySQLDriver) Begin(ctx context.Context) error
- func (d *MySQLDriver) Commit(_ context.Context) error
- func (d *MySQLDriver) CreateVersionsTable(ctx context.Context) error
- func (d *MySQLDriver) Exec(ctx context.Context, command string) error
- func (d *MySQLDriver) InsertVersion(ctx context.Context, version int) error
- func (d *MySQLDriver) Lock(ctx context.Context) error
- func (d *MySQLDriver) Rollback(_ context.Context) error
- func (d *MySQLDriver) Unlock()
- func (d *MySQLDriver) VersionTableExists(ctx context.Context) (bool, error)
- func (d *MySQLDriver) Versions(ctx context.Context) ([]int, error)
- type NamespacedMigrations
- type NoopEventHandler
- func (n NoopEventHandler) AfterVersionMigrate(version int)
- func (n NoopEventHandler) AfterVersionsMigrate(versions []int)
- func (n NoopEventHandler) BeforeVersionMigrate(version int)
- func (n NoopEventHandler) BeforeVersionsMigrate(versions []int)
- func (n NoopEventHandler) OnExecuteError(err error)
- func (n NoopEventHandler) OnRollbackError(err error)
- func (n NoopEventHandler) OnVersionSkipped(version int)
- func (n NoopEventHandler) OnVersionTableCreated()
- func (n NoopEventHandler) OnVersionTableNotExists()
- type PostgresDriver
- func (d *PostgresDriver) Begin(ctx context.Context) error
- func (d *PostgresDriver) Commit(ctx context.Context) error
- func (d *PostgresDriver) CreateVersionsTable(ctx context.Context) error
- func (d *PostgresDriver) Exec(ctx context.Context, command string) error
- func (d *PostgresDriver) InsertVersion(ctx context.Context, version int) error
- func (d *PostgresDriver) Lock(ctx context.Context) error
- func (d *PostgresDriver) Rollback(ctx context.Context) error
- func (d *PostgresDriver) VersionTableExists(ctx context.Context) (bool, error)
- func (d *PostgresDriver) Versions(ctx context.Context) ([]int, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTransactionAlreadyStarted ... ErrTransactionAlreadyStarted = errors.New("migrate: transaction already started") // ErrTransactionNotStarted ... ErrTransactionNotStarted = errors.New("migrate: transaction not started") )
Functions ¶
func Execute ¶
func Execute(driver Driver, events EventHandler, namespace string, timeout time.Duration) (err error)
Execute ...
func MustRegisterFS ¶ added in v0.3.0
MustRegisterFS calls RegisterFS, but panics if an error is returned.
Types ¶
type Driver ¶
type Driver interface { Begin(ctx context.Context) error Commit(ctx context.Context) error Rollback(ctx context.Context) error Lock(ctx context.Context) error Exec(ctx context.Context, command string) error CreateVersionsTable(ctx context.Context) error InsertVersion(ctx context.Context, version int) error Versions(ctx context.Context) ([]int, error) VersionTableExists(ctx context.Context) (bool, error) }
Driver ... TODO: Can this be simplified, leaving more to each driver? It's quite heavily tied to SQL databases currently?
type EventHandler ¶
type EventHandler interface { BeforeVersionsMigrate(versions []int) BeforeVersionMigrate(version int) AfterVersionsMigrate(versions []int) AfterVersionMigrate(version int) OnVersionSkipped(version int) OnVersionTableNotExists() OnVersionTableCreated() OnExecuteError(err error) OnRollbackError(err error) }
EventHandler is a type used to allow consumers of this library to handle output themselves for certain events as they happen during the migration process.
type Migration ¶
Migration ...
func NewMigration ¶ added in v0.2.0
NewMigration returns a new Migration value.
type MySQLDriver ¶ added in v0.2.0
type MySQLDriver struct {
// contains filtered or unexported fields
}
MySQLDriver ...
func NewMySQLDriver ¶ added in v0.2.0
func NewMySQLDriver(conn *sql.DB, database, table string) *MySQLDriver
NewMySQLDriver returns a new MySQLDriver instance.
func (*MySQLDriver) Begin ¶ added in v0.2.0
func (d *MySQLDriver) Begin(ctx context.Context) error
Begin ...
func (*MySQLDriver) Commit ¶ added in v0.2.0
func (d *MySQLDriver) Commit(_ context.Context) error
Commit ...
func (*MySQLDriver) CreateVersionsTable ¶ added in v0.2.0
func (d *MySQLDriver) CreateVersionsTable(ctx context.Context) error
CreateVersionsTable ...
func (*MySQLDriver) Exec ¶ added in v0.2.0
func (d *MySQLDriver) Exec(ctx context.Context, command string) error
Exec ...
func (*MySQLDriver) InsertVersion ¶ added in v0.2.0
func (d *MySQLDriver) InsertVersion(ctx context.Context, version int) error
InsertVersion ...
func (*MySQLDriver) Lock ¶ added in v0.2.0
func (d *MySQLDriver) Lock(ctx context.Context) error
Lock ...
func (*MySQLDriver) Rollback ¶ added in v0.2.0
func (d *MySQLDriver) Rollback(_ context.Context) error
Rollback ...
func (*MySQLDriver) Unlock ¶ added in v0.2.0
func (d *MySQLDriver) Unlock()
Unlock must be explicitly implemented for MySQL.
func (*MySQLDriver) VersionTableExists ¶ added in v0.2.0
func (d *MySQLDriver) VersionTableExists(ctx context.Context) (bool, error)
VersionTableExists ...
type NamespacedMigrations ¶
type NamespacedMigrations map[string]Migrations
NamespacedMigrations ...
type NoopEventHandler ¶
type NoopEventHandler struct{}
NoopEventHandler is a no-op EventHandler implementation.
func (NoopEventHandler) AfterVersionMigrate ¶
func (n NoopEventHandler) AfterVersionMigrate(version int)
AfterVersionMigrate is a no-op AfterVersionMigrate method.
func (NoopEventHandler) AfterVersionsMigrate ¶
func (n NoopEventHandler) AfterVersionsMigrate(versions []int)
AfterVersionsMigrate is a no-op AfterVersionsMigrate method.
func (NoopEventHandler) BeforeVersionMigrate ¶
func (n NoopEventHandler) BeforeVersionMigrate(version int)
BeforeVersionMigrate is a no-op BeforeVersionMigrate method.
func (NoopEventHandler) BeforeVersionsMigrate ¶
func (n NoopEventHandler) BeforeVersionsMigrate(versions []int)
BeforeVersionsMigrate is a no-op BeforeVersionsMigrate method.
func (NoopEventHandler) OnExecuteError ¶ added in v0.2.0
func (n NoopEventHandler) OnExecuteError(err error)
OnExecuteError is a no-op OnExecuteError method.
func (NoopEventHandler) OnRollbackError ¶
func (n NoopEventHandler) OnRollbackError(err error)
OnRollbackError is a no-op OnRollbackError method.
func (NoopEventHandler) OnVersionSkipped ¶
func (n NoopEventHandler) OnVersionSkipped(version int)
OnVersionSkipped is a no-op OnVersionSkipped method.
func (NoopEventHandler) OnVersionTableCreated ¶
func (n NoopEventHandler) OnVersionTableCreated()
OnVersionTableCreated is a no-op OnVersionTableCreated method.
func (NoopEventHandler) OnVersionTableNotExists ¶
func (n NoopEventHandler) OnVersionTableNotExists()
OnVersionTableNotExists is a no-op OnVersionTableNotExists method.
type PostgresDriver ¶ added in v0.2.0
type PostgresDriver struct {
// contains filtered or unexported fields
}
PostgresDriver ...
func NewPostgresDriver ¶ added in v0.2.0
func NewPostgresDriver(conn *pgxpool.Pool, schema, table string) *PostgresDriver
NewPostgresDriver returns a new PostgresDriver instance. TODO: Config...
func (*PostgresDriver) Begin ¶ added in v0.2.0
func (d *PostgresDriver) Begin(ctx context.Context) error
Begin ...
func (*PostgresDriver) Commit ¶ added in v0.2.0
func (d *PostgresDriver) Commit(ctx context.Context) error
Commit ...
func (*PostgresDriver) CreateVersionsTable ¶ added in v0.2.0
func (d *PostgresDriver) CreateVersionsTable(ctx context.Context) error
CreateVersionsTable ...
func (*PostgresDriver) Exec ¶ added in v0.2.0
func (d *PostgresDriver) Exec(ctx context.Context, command string) error
Exec ...
func (*PostgresDriver) InsertVersion ¶ added in v0.2.0
func (d *PostgresDriver) InsertVersion(ctx context.Context, version int) error
InsertVersion ...
func (*PostgresDriver) Lock ¶ added in v0.2.0
func (d *PostgresDriver) Lock(ctx context.Context) error
Lock ...
func (*PostgresDriver) Rollback ¶ added in v0.2.0
func (d *PostgresDriver) Rollback(ctx context.Context) error
Rollback ...
func (*PostgresDriver) VersionTableExists ¶ added in v0.2.0
func (d *PostgresDriver) VersionTableExists(ctx context.Context) (bool, error)
VersionTableExists ...