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

66 lines
1.2 KiB
Go
Raw Normal View History

2018-04-30 18:42:17 +05:00
package goose
import (
"database/sql"
)
// 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 {
2019-10-13 13:55:38 +05:00
log.Printf("goose: no migrations to run. current version: %d\n", current)
2018-04-30 18:42:17 +05:00
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 {
2019-10-13 13:55:38 +05:00
log.Printf("goose: no migrations to run. current version: %d\n", currentVersion)
2018-04-30 18:42:17 +05:00
}
return err
}
if err = next.Up(db); err != nil {
return err
}
return nil
}