emissary/internal/command/server/database/reset.go

39 lines
891 B
Go
Raw Permalink Normal View History

2023-02-02 10:55:24 +01:00
package database
import (
"forge.cadoles.com/Cadoles/emissary/internal/command/common"
"forge.cadoles.com/Cadoles/emissary/internal/migrate"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"gitlab.com/wpetit/goweb/logger"
)
func ResetCommand() *cli.Command {
return &cli.Command{
Name: "reset",
Usage: "Reset database",
Action: func(ctx *cli.Context) error {
conf, err := common.LoadConfig(ctx)
if err != nil {
return errors.Wrap(err, "Could not load configuration")
}
driver := string(conf.Server.Database.Driver)
dsn := string(conf.Server.Database.DSN)
2023-02-02 10:55:24 +01:00
migr, err := migrate.New("migrations", driver, dsn)
if err != nil {
return errors.WithStack(err)
}
if err := migr.Drop(); err != nil {
return errors.Wrap(err, "could not drop tables")
}
logger.Info(ctx.Context, "database schema reinitialized")
return nil
},
}
}