Add goose command for database migrations

This commit is contained in:
Luis Eduardo Jeréz Girón
2024-07-19 23:50:02 -06:00
parent 24cb986929
commit b97e6296f7
2 changed files with 40 additions and 0 deletions

37
cmd/goose/main.go Normal file
View File

@@ -0,0 +1,37 @@
package main
import (
"fmt"
"os"
"github.com/eduardolat/pgbackweb/internal/config"
)
const migrationsFolder string = "./internal/database/migrations"
func main() {
if len(os.Args) < 2 {
fmt.Println("goose command is required")
fmt.Println("example: task goose -- up")
return
}
gooseCmd := ""
for i, arg := range os.Args {
if i == 0 {
continue
}
gooseCmd += arg + " "
}
env := config.GetEnv()
cmd := fmt.Sprintf(
"goose -dir %s postgres \"%s\" %s",
migrationsFolder,
*env.PBW_POSTGRES_CONN_STRING,
gooseCmd,
)
fmt.Println(cmd)
}

View File

@@ -30,6 +30,9 @@ tasks:
- task build
- task serve
goose:
cmd: eval $(go run ./cmd/goose/. {{.CLI_ARGS}})
gen-css:
cmd: >
npm run tailwindcss --