12345678910111213141516171819202122232425262728293031323334353637383940 |
- package main
- import (
- "code.osinet.fr/fgm/kurz/infrastructure"
- "os"
- _ "code.osinet.fr/fgm/kurz/migrations"
- "github.com/pressly/goose"
- "github.com/spf13/cobra"
- )
- var cmdMigrateDownTo = &cobra.Command{
- Args: migrateVersionValidator,
- Long: "Roll the Kurz schema back to a specific version. Kurz version of 'goose down-to'.",
- Run: migrateDownToHandler,
- Short: "Roll back to specific version",
- Use: "down-to <version>",
- }
- func init() {
- cmdMigrate.AddCommand(cmdMigrateDownTo)
- }
- // migrateDownToHandler implements the "kurzd migrate down-to" command.
- func migrateDownToHandler(cmd *cobra.Command, args []string) {
- dbDriver, dbDsn := infrastructure.ParseDbCred()
- db, err := infrastructure.DbDial(dbDriver, dbDsn)
- if err != nil {
- panic(err)
- }
- defer db.Close()
- cwd, err := os.Getwd()
- if err != nil {
- panic(err)
- }
- goose.SetDialect(dbDriver)
- goose.DownTo(db, cwd, migrateTargetVersion)
- }
|