-
Notifications
You must be signed in to change notification settings - Fork 132
/
util.go
39 lines (33 loc) · 901 Bytes
/
util.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
package database
import (
"embed"
_ "embed"
"time"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/armadaproject/armada/internal/common/armadacontext"
"github.com/armadaproject/armada/internal/common/database"
)
//go:embed migrations/*.sql
var fs embed.FS
func Migrate(ctx *armadacontext.Context, db database.Querier) error {
start := time.Now()
migrations, err := database.ReadMigrations(fs, "migrations")
if err != nil {
return err
}
err = database.UpdateDatabase(ctx, db, migrations)
if err != nil {
return err
}
ctx.Infof("Updated scheduler database in %s", time.Now().Sub(start))
return nil
}
func WithTestDb(action func(queries *Queries, db *pgxpool.Pool) error) error {
migrations, err := database.ReadMigrations(fs, "migrations")
if err != nil {
return err
}
return database.WithTestDb(migrations, func(db *pgxpool.Pool) error {
return action(New(db), db)
})
}