Skip to content

Commit

Permalink
Use uint32 for OID to stop conversion errors with pguint32 (#324)
Browse files Browse the repository at this point in the history
Co-authored-by: michaelt <[email protected]>
Co-authored-by: Cyril Gaudin <[email protected]>
  • Loading branch information
3 people authored Sep 9, 2023
1 parent 7a8b1ef commit 592f723
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions postgresql/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,12 @@ func isSuperuser(db QueryAble, role string) (bool, error) {

const publicRole = "public"

func getRoleOID(db QueryAble, role string) (int, error) {
func getRoleOID(db QueryAble, role string) (uint32, error) {
if role == publicRole {
return 0, nil
}

var oid int
var oid uint32
if err := db.QueryRow("SELECT oid FROM pg_roles WHERE rolname = $1", role).Scan(&oid); err != nil {
return 0, fmt.Errorf("could not find oid for role %s: %w", role, err)
}
Expand Down
8 changes: 4 additions & 4 deletions postgresql/resource_postgresql_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func resourcePostgreSQLGrantDelete(db *DBConnection, d *schema.ResourceData) err
return nil
}

func readDatabaseRolePriviges(txn *sql.Tx, d *schema.ResourceData, roleOID int) error {
func readDatabaseRolePriviges(txn *sql.Tx, d *schema.ResourceData, roleOID uint32) error {
dbName := d.Get("database").(string)
query := `
SELECT array_agg(privilege_type)
Expand All @@ -274,7 +274,7 @@ WHERE grantee = $2
return nil
}

func readSchemaRolePriviges(txn *sql.Tx, d *schema.ResourceData, roleOID int) error {
func readSchemaRolePriviges(txn *sql.Tx, d *schema.ResourceData, roleOID uint32) error {
dbName := d.Get("schema").(string)
query := `
SELECT array_agg(privilege_type)
Expand All @@ -293,7 +293,7 @@ WHERE grantee = $2
return nil
}

func readForeignDataWrapperRolePrivileges(txn *sql.Tx, d *schema.ResourceData, roleOID int) error {
func readForeignDataWrapperRolePrivileges(txn *sql.Tx, d *schema.ResourceData, roleOID uint32) error {
objects := d.Get("objects").(*schema.Set).List()
fdwName := objects[0].(string)
query := `
Expand All @@ -313,7 +313,7 @@ WHERE grantee = $2
return nil
}

func readForeignServerRolePrivileges(txn *sql.Tx, d *schema.ResourceData, roleOID int) error {
func readForeignServerRolePrivileges(txn *sql.Tx, d *schema.ResourceData, roleOID uint32) error {
objects := d.Get("objects").(*schema.Set).List()
srvName := objects[0].(string)
query := `
Expand Down

0 comments on commit 592f723

Please sign in to comment.