-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate.go
44 lines (36 loc) · 909 Bytes
/
migrate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Package main runs all pending migrations
package main
import (
"embed"
"github.com/ZeusWPI/events/pkg/config"
"github.com/ZeusWPI/events/pkg/db"
"github.com/jackc/pgx/v5/stdlib"
"github.com/pressly/goose/v3"
)
//go:embed db/migrations/*.sql
var embedMigrations embed.FS
func main() {
if err := config.Init(); err != nil {
panic(err)
}
// setup database
database, err := db.NewPSQL(db.PSQLOptions{
Host: config.GetString("db.host"),
Port: uint16(config.GetInt("db.port")),
Database: config.GetString("db.database"),
User: config.GetString("db.user"),
Password: config.GetString("db.password"),
})
if err != nil {
panic(err)
}
db := stdlib.OpenDBFromPool(database.Pool())
goose.SetBaseFS(embedMigrations)
if err := goose.SetDialect("postgres"); err != nil {
panic(err)
}
if err := goose.Up(db, "db/migrations"); err != nil {
panic(err)
}
// run app
}