taskcafe/internal/command/migrate.go
Jordan Knott 64093e19f6 redesign
2022-05-06 16:44:31 -05:00

34 lines
722 B
Go

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
}