Documentation ¶
Index ¶
- func Create(path, name string) (string, error)
- func CurrentVersion(db *sql.DB) (version int64, err error)
- func Down(db *sql.DB, tx bool) (oldVersion, newVersion int64, err error)
- func DropAll(db DB, tables ...string) error
- func ExecAll(db DB, stmts ...string) error
- func Register(up, down MigrationFunc)
- func SetTableName(name string)
- func SetVersion(db DB, v int64) error
- func ToVersion(db *sql.DB, tx bool, v int64) (oldVersion, newVersion int64, err error)
- func Up(db *sql.DB, tx bool) (oldVersion, newVersion int64, err error)
- type DB
- type MigrationFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrentVersion ¶
CurrentVersion returns the current version of the database.
func Down ¶
Down rolls back a single database migration. If tx is true, all migrations will be run inside a transaction.
func DropAll ¶
DropAll is an utility function to drop all tables in the given order.
DropAll(db, `baz`, `bar`, `foo`)
func ExecAll ¶
ExecAll is an utility function to execute all the given migrations. This is specially useful for running a bunch of create tables and so on.
ExecAll(db, `CREATE TABLE foo ( ... )`, `CREATE TABLE bar ( ... )`, `CREATE TABLE baz ( ... )`, )
func Register ¶
func Register(up, down MigrationFunc)
Register adds a new migration. Its order will depend on the name of the file calling this function. For example, a file named 00001_initial_migration.go will be executed before a migration defined in 000004_add_users_table.go. Register needs to provide both an up and a down function.
func SetTableName ¶
func SetTableName(name string)
SetTableName sets the name of the table used to store the migrations information in your database.
func SetVersion ¶
SetVersion sets the current version of the database to the given version.
Types ¶
type DB ¶
type DB interface { Exec(query string, args ...interface{}) (sql.Result, error) Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row }
DB is an interface that both a database instance and a transaction satisfy. It should be able to execute and perform queries.
type MigrationFunc ¶
MigrationFunc is a function that receives a database instance and runs a migration, either an up or a down.