From 191401abe955532c022dac5fe32677cf29e8b2a7 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Fri, 24 Feb 2023 13:17:37 +0100 Subject: [PATCH] Temporarily switch to admin role to register types The authenticator role does not have access to the numerus schema, so it can not see the oid of discount_rate, for instance. --- pkg/pgtypes.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/pgtypes.go b/pkg/pgtypes.go index c7bfed2..521e0c7 100644 --- a/pkg/pgtypes.go +++ b/pkg/pgtypes.go @@ -35,6 +35,9 @@ func (src NewInvoiceProductArray) EncodeBinary(ci *pgtype.ConnInfo, buf []byte) } func registerPgTypes(ctx context.Context, conn *pgx.Conn) error { + if _, err := conn.Exec(ctx, "set role to admin"); err != nil { + return err + } discountRateOID, err := registerPgType(ctx, conn, &pgtype.Numeric{}, "discount_rate") if err != nil { return err @@ -67,7 +70,9 @@ func registerPgTypes(ctx context.Context, conn *pgx.Conn) error { if err != nil { return err } - return nil + + _, err = conn.Exec(ctx, "reset role") + return err } func registerPgType(ctx context.Context, conn *pgx.Conn, value pgtype.Value, name string) (oid uint32, err error) {