goose/up.go

62 lines
1.0 KiB
Go

package goose
import (
"database/sql"
"fmt"
)
func Up(db *sql.DB, dir string) error {
migrations, err := collectMigrations(dir, minVersion, maxVersion)
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
}
}
return nil
}
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
}