Fix help message for migrate

This commit is contained in:
Vikram Rangnekar 2019-09-28 20:46:55 -04:00
parent 7e4d14fbca
commit 7243e9ef34
3 changed files with 24 additions and 8 deletions

View File

@ -77,22 +77,22 @@ func Init() {
Destination migration version can be one of the following value types: Destination migration version can be one of the following value types:
Migrate to the most recent migration. Migrate to the most recent migration.
e.g. migrate up e.g. db:migrate up
Rollback the most recent migration. Rollback the most recent migration.
e.g. migrate down e.g. db:migrate down
Migrate to a specific migration. Migrate to a specific migration.
e.g. migrate 42 e.g. db:migrate 42
Migrate forward N steps. Migrate forward N steps.
e.g. migrate +3 e.g. db:migrate +3
Migrate backward N steps. Migrate backward N steps.
e.g. migrate -2 e.g. db:migrate -2
Redo previous N steps (migrate backward N steps then forward N steps). Redo previous N steps (migrate backward N steps then forward N steps).
e.g. migrate -+1 e.g. db:migrate -+1
`, `,
Run: cmdDBMigrate, Run: cmdDBMigrate,
}) })

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -37,7 +38,20 @@ var newMigrationText = `-- Write your migrate up statements here
func cmdDBSetup(cmd *cobra.Command, args []string) { func cmdDBSetup(cmd *cobra.Command, args []string) {
cmdDBCreate(cmd, []string{}) cmdDBCreate(cmd, []string{})
cmdDBMigrate(cmd, []string{"up"}) cmdDBMigrate(cmd, []string{"up"})
cmdDBSeed(cmd, []string{})
sfile := path.Join(confPath, conf.SeedFile)
_, err := os.Stat(sfile)
if err == nil {
cmdDBSeed(cmd, []string{})
return
}
if os.IsNotExist(err) == false {
logger.Fatal().Err(err).Msgf("unable to check if '%s' exists", sfile)
}
logger.Warn().Msgf("failed to read seed file '%s'", sfile)
} }
func cmdDBCreate(cmd *cobra.Command, args []string) { func cmdDBCreate(cmd *cobra.Command, args []string) {

View File

@ -30,9 +30,11 @@ func cmdDBSeed(cmd *cobra.Command, args []string) {
initCompiler() initCompiler()
sfile := path.Join(confPath, conf.SeedFile)
b, err := ioutil.ReadFile(path.Join(confPath, conf.SeedFile)) b, err := ioutil.ReadFile(path.Join(confPath, conf.SeedFile))
if err != nil { if err != nil {
logger.Fatal().Err(err).Msg("failed to read file") logger.Fatal().Err(err).Msgf("failed to read seed file '%s'", sfile)
} }
vm := goja.New() vm := goja.New()