migrate_version.go 812 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 cmdMigrateVersion = &cobra.Command{
  10. Args: cobra.NoArgs,
  11. Long: "Kurz version of goose version",
  12. Run: migrateVersionHandler,
  13. Short: "Migration version",
  14. Use: "version",
  15. }
  16. func init() {
  17. cmdMigrate.AddCommand(cmdMigrateVersion)
  18. }
  19. // migrateVersionHandler implements the "kurzd migrate version" command.
  20. func migrateVersionHandler(_ *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.Version(db, cwd)
  33. }