Skip to content

Commit

Permalink
use left join to also fetch users without a role, and sort by usernam…
Browse files Browse the repository at this point in the history
…e for better consistency
  • Loading branch information
frederikhs committed Aug 2, 2023
1 parent 38a2192 commit ddfa973
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions database/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func (u *User) ParseValidUntil() (*string, error) {
func (conn *DBConn) GetAllUsers() ([]User, error) {
var users []User
err := conn.db.Select(&users, `
SELECT a.rolname AS usename,
a.rolvaliduntil AS valuntil,
SELECT a.usename AS usename,
a.valuntil AS valuntil,
json_agg(c.rolname) AS roles
FROM pg_roles a
INNER JOIN pg_auth_members b ON a.oid = b.member
INNER JOIN pg_roles c ON b.roleid = c.oid
FROM pg_user a
LEFT JOIN pg_auth_members b ON a.usesysid = b.member
LEFT JOIN pg_roles c ON b.roleid = c.oid
GROUP BY 1, 2
ORDER BY 2, 1
ORDER BY 1;
`)
if err != nil {
return nil, err
Expand Down

0 comments on commit ddfa973

Please sign in to comment.