39 lines
891 B
Go
39 lines
891 B
Go
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)
|
|
|
|
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
|
|
},
|
|
}
|
|
}
|