github.com/10ego/gthp@v0.0.0-20241025155251-e1514fa71fbb/cmd/schema/main.go (about) 1 package main 2 3 import ( 4 "database/sql" 5 "fmt" 6 "os" 7 8 _ "github.com/lib/pq" 9 10 root "github.com/10ego/gthp" 11 "github.com/pressly/goose/v3" 12 ) 13 14 func main() { 15 db_url := os.Getenv("DATABASE_URL") 16 // setup database 17 18 // Register the PostgreSQL driver 19 if _, err := sql.Open("postgres", ""); err != nil { 20 fmt.Println("Failed to find driver") 21 panic(err) 22 } 23 24 db, err := sql.Open("postgres", db_url) 25 if err != nil { 26 panic(fmt.Sprintf("Failed to open database: %v", err)) 27 } 28 defer db.Close() 29 30 goose.SetBaseFS(root.GetMigrationFS()) 31 32 if err := goose.SetDialect("postgres"); err != nil { 33 panic(err) 34 } 35 36 if err := goose.Up(db, "migrations"); err != nil { 37 panic(err) 38 } 39 40 fmt.Println("Migrations ran successfully!") 41 // run app 42 }