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.
This commit is contained in:
jordi fita mas 2023-02-24 13:17:37 +01:00
parent 18fba2964f
commit 191401abe9
1 changed files with 6 additions and 1 deletions

View File

@ -35,6 +35,9 @@ func (src NewInvoiceProductArray) EncodeBinary(ci *pgtype.ConnInfo, buf []byte)
} }
func registerPgTypes(ctx context.Context, conn *pgx.Conn) error { 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") discountRateOID, err := registerPgType(ctx, conn, &pgtype.Numeric{}, "discount_rate")
if err != nil { if err != nil {
return err return err
@ -67,7 +70,9 @@ func registerPgTypes(ctx context.Context, conn *pgx.Conn) error {
if err != nil { if err != nil {
return err 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) { func registerPgType(ctx context.Context, conn *pgx.Conn, value pgtype.Value, name string) (oid uint32, err error) {