add uuid support

This commit is contained in:
2025-05-15 16:01:07 -04:00
parent 922ba98f6b
commit af4b0190d0
4 changed files with 36 additions and 4 deletions

View File

@@ -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)
}