mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-24 21:19:59 -06:00
45 lines
949 B
Go
45 lines
949 B
Go
package command
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/shroff/phylum/server/internal/db"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func setupSchemaCommand(db **db.DbHandler) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "schema",
|
|
Short: "Database Schema Management",
|
|
}
|
|
cmd.AddCommand([]*cobra.Command{
|
|
setupSchemaMigrateCommand(db),
|
|
}...)
|
|
return cmd
|
|
}
|
|
|
|
func setupSchemaMigrateCommand(db **db.DbHandler) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "migrate",
|
|
Short: "Migrate Database Schema",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if args[0] == "auto" || args[0] == "latest" {
|
|
if err := (*db).CheckVersion(true); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
} else {
|
|
(*db).CheckVersion(false)
|
|
v, err := strconv.Atoi(args[0])
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
if err = (*db).Migrate(v); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
}
|
|
},
|
|
}
|
|
}
|