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 cmdMigrateDown = &cobra.Command{ Args: cobra.NoArgs, Long: "Roll back the latest applied Kurz schema migration. Kurz version of 'goose down'.", Run: migrateDownHandler, Short: "Roll back latest migration", Use: "down", } func init() { cmdMigrate.AddCommand(cmdMigrateDown) } // migrateDownHandler implements the "kurzd migrate down" command. func migrateDownHandler(_ *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.Down(db, cwd) }