migrate_status.go 842 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package main
  2. import (
  3. "code.osinet.fr/fgm/kurz/infrastructure"
  4. "os"
  5. _ "code.osinet.fr/fgm/kurz/migrations"
  6. "github.com/pressly/goose"
  7. "github.com/spf13/cobra"
  8. )
  9. var cmdMigrateStatus = &cobra.Command{
  10. Args: cobra.NoArgs,
  11. Long: "Dump the Kurz migration status table. Kurz version of 'goose status'",
  12. Run: migrateStatusHandler,
  13. Short: "Migration status",
  14. Use: "status",
  15. }
  16. func init() {
  17. cmdMigrate.AddCommand(cmdMigrateStatus)
  18. }
  19. // migrateStatusHandler implements the "kurzd migrate status" command.
  20. func migrateStatusHandler(_ *cobra.Command, args []string) {
  21. dbDriver, dbDsn := infrastructure.ParseDbCred()
  22. db, err := infrastructure.DbDial(dbDriver, dbDsn)
  23. if err != nil {
  24. panic(err)
  25. }
  26. defer db.Close()
  27. cwd, err := os.Getwd()
  28. if err != nil {
  29. panic(err)
  30. }
  31. goose.SetDialect(dbDriver)
  32. goose.Status(db, cwd)
  33. }