add uuid support
This commit is contained in:
@@ -7,10 +7,12 @@ import (
|
||||
"time"
|
||||
|
||||
"gitea.michaelthomson.dev/mthomson/habits/internal/migrate"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/testcontainers/testcontainers-go"
|
||||
"github.com/testcontainers/testcontainers-go/modules/postgres"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
pgxuuid "github.com/jackc/pgx-gofrs-uuid"
|
||||
)
|
||||
|
||||
type TestDatabase struct {
|
||||
@@ -42,8 +44,18 @@ func NewTestDatabase(tb testing.TB) *TestDatabase {
|
||||
tb.Fatalf("Failed to get connection string: %v", err)
|
||||
}
|
||||
|
||||
dbconfig, err := pgxpool.ParseConfig(connectionString)
|
||||
if err != nil {
|
||||
tb.Fatalf("Failed to create db config: %v", err)
|
||||
}
|
||||
|
||||
dbconfig.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error {
|
||||
pgxuuid.Register(conn.TypeMap())
|
||||
return nil
|
||||
}
|
||||
|
||||
// create db pool
|
||||
db, err := pgxpool.New(context.Background(), connectionString)
|
||||
db, err := pgxpool.NewWithConfig(context.Background(), dbconfig)
|
||||
if err != nil {
|
||||
tb.Fatalf("Failed to open db pool: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user