taskcafe/internal/command/migrate.go

34 lines
722 B
Go
Raw Permalink Normal View History

2022-05-06 23:41:52 +02:00
package command
import (
"database/sql"
"fmt"
"github.com/jordanknott/taskcafe/internal/config"
"github.com/pressly/goose/v3"
"github.com/spf13/cobra"
)
func newMigrateCmd() *cobra.Command {
cc := &cobra.Command{
Use: "migrate",
Short: "run the migrations",
Long: "Run the migrations",
RunE: func(cmd *cobra.Command, args []string) error {
appConfig, err := config.GetAppConfig()
if err != nil {
return err
}
fmt.Println(appConfig.Database.GetDatabaseConnectionUri())
db, err := sql.Open("postgres", appConfig.Database.GetDatabaseConnectionUri())
if err != nil {
return err
}
return goose.Up(db, "migrations")
},
}
cc.AddCommand(newMigrateCreateCmd())
return cc
}