Skip to content

Commit

Permalink
fix(user_mapping): Adds fallback query to fix #327 (#469)
Browse files Browse the repository at this point in the history
#274 broke
support for GCP Cloud Postgres and perhaps other versions.

fix: #327
  • Loading branch information
ademariag authored Oct 19, 2024
1 parent dea1401 commit cdcab17
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions postgresql/resource_postgresql_user_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ func resourcePostgreSQLUserMappingReadImpl(db *DBConnection, d *schema.ResourceD
var userMappingOptions []string
query := "SELECT umoptions FROM information_schema._pg_user_mappings WHERE authorization_identifier = $1 and foreign_server_name = $2"
err = txn.QueryRow(query, username, serverName).Scan(pq.Array(&userMappingOptions))

if err != sql.ErrNoRows && err != nil {
// Fallback to pg_user_mappings table if information_schema._pg_user_mappings is not available
query := "SELECT umoptions FROM pg_user_mappings WHERE usename = $1 and srvname = $2"
err = txn.QueryRow(query, username, serverName).Scan(pq.Array(&userMappingOptions))
}

switch {
case err == sql.ErrNoRows:
log.Printf("[WARN] PostgreSQL user mapping (%s) for server (%s) not found", username, serverName)
Expand Down

0 comments on commit cdcab17

Please sign in to comment.