refactor(store): sqlc override uuid→google/uuid.UUID (убирает pgtype boilerplate)

This commit is contained in:
2026-07-03 14:20:03 +07:00
parent 34bc49ee8c
commit 635b05361f
8 changed files with 65 additions and 62 deletions
+3 -11
View File
@@ -5,7 +5,6 @@ import (
"testing"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/vasyakrg/dns-autoresolver/internal/store/db"
@@ -13,14 +12,7 @@ import (
)
// defaultProject is the seed default tenant project (see migrations/0001_init.sql).
//
// NOTE: sqlc generated UUID columns as pgtype.UUID (not google/uuid.UUID) —
// pgUUID bridges the two so tests can still use uuid.New()/uuid.MustParse.
var defaultProject = pgUUID(uuid.MustParse("00000000-0000-0000-0000-000000000002"))
func pgUUID(id uuid.UUID) pgtype.UUID {
return pgtype.UUID{Bytes: id, Valid: true}
}
var defaultProject = uuid.MustParse("00000000-0000-0000-0000-000000000002")
func newStore(t *testing.T) (*Store, context.Context) {
dsn := startPostgres(t)
@@ -35,7 +27,7 @@ func newStore(t *testing.T) (*Store, context.Context) {
func TestAccountCRUD(t *testing.T) {
s, ctx := newStore(t)
acc, err := s.Queries().CreateAccount(ctx, db.CreateAccountParams{
ID: pgUUID(uuid.New()), ProjectID: defaultProject,
ID: uuid.New(), ProjectID: defaultProject,
Provider: "selectel", SecretEnc: "enc-blob", Comment: "prod",
})
if err != nil {
@@ -66,7 +58,7 @@ func TestTemplateJSONBRoundTrip(t *testing.T) {
{Type: "SRV", Name: "_autodiscover._tcp.example.com.", TTL: 3600, Values: []string{"0 0 443 mail.example.com."}},
}}
tpl, err := s.Queries().CreateTemplate(ctx, db.CreateTemplateParams{
ID: pgUUID(uuid.New()), ProjectID: defaultProject, Name: "base", Doc: &doc,
ID: uuid.New(), ProjectID: defaultProject, Name: "base", Doc: &doc,
})
if err != nil {
t.Fatal(err)