1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
package main
import (
"flag"
"strings"
"github.com/rubenv/sql-migrate"
)
type UpCommand struct {
}
func (c *UpCommand) Help() string {
helpText := `
Usage: sql-migrate up [options] ...
Migrates the database to the most recent version available.
Options:
-config=dbconfig.yml Configuration file to use.
-env="development" Environment.
-limit=0 Limit the number of migrations (0 = unlimited).
-dryrun Don't apply migrations, just print them.
`
return strings.TrimSpace(helpText)
}
func (c *UpCommand) Synopsis() string {
return "Migrates the database to the most recent version available"
}
func (c *UpCommand) Run(args []string) int {
var limit int
var dryrun bool
cmdFlags := flag.NewFlagSet("up", flag.ContinueOnError)
cmdFlags.Usage = func() { ui.Output(c.Help()) }
cmdFlags.IntVar(&limit, "limit", 0, "Max number of migrations to apply.")
cmdFlags.BoolVar(&dryrun, "dryrun", false, "Don't apply migrations, just print them.")
ConfigFlags(cmdFlags)
if err := cmdFlags.Parse(args); err != nil {
return 1
}
err := ApplyMigrations(migrate.Up, dryrun, limit)
if err != nil {
ui.Error(err.Error())
return 1
}
return 0
}
|