fastpastebin/vendor/github.com/pressly/goose/up.go

67 lines
1.2 KiB
Go
Raw Normal View History

2018-04-30 18:42:17 +05:00
package goose
import (
"database/sql"
"fmt"
)
// UpTo migrates up to a specific version.
func UpTo(db *sql.DB, dir string, version int64) error {
migrations, err := CollectMigrations(dir, minVersion, version)
if err != nil {
return err
}
for {
current, err := GetDBVersion(db)
if err != nil {
return err
}
next, err := migrations.Next(current)
if err != nil {
if err == ErrNoNextVersion {
fmt.Printf("goose: no migrations to run. current version: %d\n", current)
return nil
}
return err
}
if err = next.Up(db); err != nil {
return err
}
}
}
// Up applies all available migrations.
func Up(db *sql.DB, dir string) error {
return UpTo(db, dir, maxVersion)
}
// UpByOne migrates up by a single version.
func UpByOne(db *sql.DB, dir string) error {
migrations, err := CollectMigrations(dir, minVersion, maxVersion)
if err != nil {
return err
}
currentVersion, err := GetDBVersion(db)
if err != nil {
return err
}
next, err := migrations.Next(currentVersion)
if err != nil {
if err == ErrNoNextVersion {
fmt.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
}
return err
}
if err = next.Up(db); err != nil {
return err
}
return nil
}