Init: bootstrap go module with basic framework
This commit is contained in:
33
cmd/migrates/up.go
Normal file
33
cmd/migrates/up.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package migrates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var upCmd = &cobra.Command{
|
||||
Use: "up",
|
||||
Short: "migrate up",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
ctx := cmd.Context()
|
||||
|
||||
if err := migrator.Lock(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
defer migrator.Unlock(ctx)
|
||||
|
||||
group, err := migrator.Migrate(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if group.IsZero() {
|
||||
fmt.Printf("there are no new migrations to run\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("migrated to %s\n", group)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user