Skip to content

Commit 0c48dd0

Browse files
committed
feat(api,cli): postgres with-fixtures option
1 parent b845d79 commit 0c48dd0

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

api/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ require (
1919
github.com/stretchr/testify v1.10.0
2020
github.com/testcontainers/testcontainers-go/modules/mongodb v0.35.0
2121
github.com/uptrace/bun v1.2.11
22+
github.com/uptrace/bun/dbfixture v1.2.11
2223
github.com/uptrace/bun/dialect/pgdialect v1.2.11
2324
golang.org/x/crypto v0.33.0
2425
)

api/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0o
374374
github.com/uptrace/bun v0.3.9/go.mod h1:aL6D9vPw8DXaTQTwGrEPtUderBYXx7ShUmPfnxnqscw=
375375
github.com/uptrace/bun v1.2.11 h1:l9dTymsdZZAoSZ1+Qo3utms0RffgkDbIv+1UGk8N1wQ=
376376
github.com/uptrace/bun v1.2.11/go.mod h1:ww5G8h59UrOnCHmZ8O1I/4Djc7M/Z3E+EWFS2KLB6dQ=
377+
github.com/uptrace/bun/dbfixture v1.2.11 h1:9rKYVDwQCLdXtPkgzMgvDsHKHXelNlXmnpuNHvFz2w0=
378+
github.com/uptrace/bun/dbfixture v1.2.11/go.mod h1:E2H4A4/dx6+xB61qGsjVqV17Pqyb+Gg5QTmswy4hUpk=
377379
github.com/uptrace/bun/dialect/pgdialect v1.2.11 h1:n0VKWm1fL1dwJK5TRxYYLaRKRe14BOg2+AQgpvqzG/M=
378380
github.com/uptrace/bun/dialect/pgdialect v1.2.11/go.mod h1:NvV1S/zwtwBnW8yhJ3XEKAQEw76SkeH7yUhfrx3W1Eo=
379381
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package options
2+
3+
import (
4+
"context"
5+
"io/fs"
6+
"os"
7+
8+
"github.com/uptrace/bun"
9+
"github.com/uptrace/bun/dbfixture"
10+
)
11+
12+
func WithFixtures(dir string) Option {
13+
return func(ctx context.Context, db *bun.DB) error {
14+
println("path: ", dir)
15+
16+
fixture := dbfixture.New(db)
17+
18+
fsys := os.DirFS(dir)
19+
files, err := fs.ReadDir(fsys, ".")
20+
if err != nil {
21+
return err
22+
}
23+
24+
names := make([]string, 0)
25+
for _, file := range files {
26+
println("\tname: ", file.Name)
27+
28+
if !file.IsDir() {
29+
names = append(names, file.Name())
30+
}
31+
}
32+
33+
return fixture.Load(ctx, fsys, names...)
34+
}
35+
}

cli/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ require (
3838
github.com/stretchr/objx v0.5.2 // indirect
3939
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
4040
github.com/uptrace/bun v1.2.11 // indirect
41+
github.com/uptrace/bun/dbfixture v1.2.11 // indirect
4142
github.com/uptrace/bun/dialect/pgdialect v1.2.11 // indirect
4243
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
4344
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect

cli/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GH
113113
github.com/uptrace/bun v0.3.9/go.mod h1:aL6D9vPw8DXaTQTwGrEPtUderBYXx7ShUmPfnxnqscw=
114114
github.com/uptrace/bun v1.2.11 h1:l9dTymsdZZAoSZ1+Qo3utms0RffgkDbIv+1UGk8N1wQ=
115115
github.com/uptrace/bun v1.2.11/go.mod h1:ww5G8h59UrOnCHmZ8O1I/4Djc7M/Z3E+EWFS2KLB6dQ=
116+
github.com/uptrace/bun/dbfixture v1.2.11 h1:9rKYVDwQCLdXtPkgzMgvDsHKHXelNlXmnpuNHvFz2w0=
117+
github.com/uptrace/bun/dbfixture v1.2.11/go.mod h1:E2H4A4/dx6+xB61qGsjVqV17Pqyb+Gg5QTmswy4hUpk=
116118
github.com/uptrace/bun/dialect/pgdialect v1.2.11 h1:n0VKWm1fL1dwJK5TRxYYLaRKRe14BOg2+AQgpvqzG/M=
117119
github.com/uptrace/bun/dialect/pgdialect v1.2.11/go.mod h1:NvV1S/zwtwBnW8yhJ3XEKAQEw76SkeH7yUhfrx3W1Eo=
118120
github.com/vmihailenco/msgpack/v5 v5.3.4/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=

0 commit comments

Comments
 (0)