Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use uint32 for OID to stop conversion errors with pguint32 #324

Merged
merged 2 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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