Documentation
¶
Index ¶
- func Apply(logger *log.Logger, driverName, dsn, migrationsPath string) error
- func Rollback(logger *log.Logger, driverName, dsn, migrationsPath string) error
- type Driver
- type Migration
- type Migrations
- type PostgresDriver
- func (d *PostgresDriver) CreateVersionsTable(db *sql.DB) error
- func (d *PostgresDriver) HasVersionBeenExecuted(db *sql.DB, version string) (bool, error)
- func (d *PostgresDriver) MarkVersionAsExecuted(tx *sql.Tx, version string) error
- func (d *PostgresDriver) UnmarkVersionAsExecuted(tx *sql.Tx, version string) error
- type SQLiteDriver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Driver ¶
type Driver interface {
CreateVersionsTable(db *sql.DB) error
HasVersionBeenExecuted(db *sql.DB, version string) (bool, error)
MarkVersionAsExecuted(tx *sql.Tx, version string) error
UnmarkVersionAsExecuted(tx *sql.Tx, version string) error
}
Driver ...
type Migration ¶
type Migration struct {
Name string
Path string
Version time.Time
Contents struct {
Up string
Down string
}
}
Migration represents a single migration to apply to or rollback from a database.
func NewMigration ¶
NewMigration returns an initialised migration read from the given file path.
func (*Migration) Apply ¶
Apply applies the migration to the given database using the given driver implementation.
func (*Migration) HasBeenMigrated ¶
HasBeenMigrated checks if the migration has been applied to the given database.
func (*Migration) Rollback ¶
Rollback rolls back the migration from the given database using the given driver implementation.
func (*Migration) VersionAsString ¶
VersionAsString returns the migration version as a string.
type Migrations ¶
type Migrations []*Migration
Migrations represents a set of migrations to apply to or rollback from a database.
func LoadMigrations ¶ added in v0.0.2
func LoadMigrations(migrationsPath string) (Migrations, error)
LoadMigrations returns all the loaded migrations from the given directory path.
func (Migrations) Apply ¶
Apply applies all the migrations that have not already been applied to the given database.
func (Migrations) Len ¶
func (m Migrations) Len() int
func (Migrations) Less ¶
func (m Migrations) Less(i, j int) bool
func (Migrations) Rollback ¶
Rollback rolls back all the migrations that have been applied to the given database.
func (Migrations) Swap ¶
func (m Migrations) Swap(i, j int)
type PostgresDriver ¶
type PostgresDriver struct{}
PostgresDriver is a PostgreSQL implementation of the Driver interface.
func (*PostgresDriver) CreateVersionsTable ¶
func (d *PostgresDriver) CreateVersionsTable(db *sql.DB) error
CreateVersionsTable creates the table for storing migrated versions if it doesn't exist.
func (*PostgresDriver) HasVersionBeenExecuted ¶
HasVersionBeenExecuted checks if the given version has been executed.
func (*PostgresDriver) MarkVersionAsExecuted ¶
func (d *PostgresDriver) MarkVersionAsExecuted(tx *sql.Tx, version string) error
MarkVersionAsExecuted marks a given version as been executed.
func (*PostgresDriver) UnmarkVersionAsExecuted ¶
func (d *PostgresDriver) UnmarkVersionAsExecuted(tx *sql.Tx, version string) error
UnmarkVersionAsExecuted unmarks a given version as been executed.
type SQLiteDriver ¶
type SQLiteDriver struct {
PostgresDriver
}
SQLiteDriver is a SQLite implementation of the Driver interface.