added admin console command tests
This commit is contained in:
@@ -17,7 +17,6 @@ package migratecmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -129,9 +128,12 @@ func (p *plugin) createCommand() *cobra.Command {
|
||||
command := &cobra.Command{
|
||||
Use: "migrate",
|
||||
Short: "Executes app DB migration scripts",
|
||||
ValidArgs: []string{"up", "down", "create", "collections"},
|
||||
Long: cmdDesc,
|
||||
Run: func(command *cobra.Command, args []string) {
|
||||
ValidArgs: []string{"up", "down", "create", "collections"},
|
||||
// prevents printing the error log twice
|
||||
SilenceErrors: true,
|
||||
SilenceUsage: true,
|
||||
RunE: func(command *cobra.Command, args []string) error {
|
||||
cmd := ""
|
||||
if len(args) > 0 {
|
||||
cmd = args[0]
|
||||
@@ -140,22 +142,24 @@ func (p *plugin) createCommand() *cobra.Command {
|
||||
switch cmd {
|
||||
case "create":
|
||||
if err := p.migrateCreateHandler("", args[1:], true); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
case "collections":
|
||||
if err := p.migrateCollectionsHandler(args[1:], true); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
default:
|
||||
runner, err := migrate.NewRunner(p.app.DB(), migrations.AppMigrations)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := runner.Run(args...); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user