migrate

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2023 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sqlx

type Sqlx struct {
	Migrations []SqlxMigration
	// Printf is used to print out additional information during a migration, such
	// as which step the migration is currently on. It can be replaced with any
	// custom printf function, including one that just ignores inputs. If nil it
	// will default to fmt.Printf.
	Printf func(format string, a ...interface{}) (n int, err error)
}

Sqlx is a migrator that uses github.com/jmoiron/sqlx

func (*Sqlx) Migrate

func (s *Sqlx) Migrate(sqlDB *sql.DB, dialect string) error

Migrate will run the migrations using the provided db connection.

func (*Sqlx) Rollback

func (s *Sqlx) Rollback(sqlDB *sql.DB, dialect string) error

Rollback will run all rollbacks using the provided db connection.

type SqlxMigration

type SqlxMigration struct {
	ID       string
	Migrate  func(tx *sqlx.Tx) error
	Rollback func(tx *sqlx.Tx) error
}

SqlxMigration is a unique ID plus a function that uses a sqlx transaction to perform a database migration step.

Note: Long term this could have a Rollback field if we wanted to support that.

func SqlxFileMigration

func SqlxFileMigration(id, upFile, downFile string) SqlxMigration

SqlxFileMigration will create a SqlxMigration using the provided file.

func SqlxQueryMigration

func SqlxQueryMigration(id, upQuery, downQuery string) SqlxMigration

SqlxQueryMigration will create a SqlxMigration using the provided id and query string. It is a helper function designed to simplify the process of creating migrations that only depending on a SQL query string.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL