Skip to content

Conversation

@WCheyenneLu
Copy link

@WCheyenneLu WCheyenneLu commented Dec 18, 2025

roles.sql

  • create roles schema
  • added RLS policies
    • Select: all
    • Insert: none
    • Update: none
    • Delete: none

roles (seeds)

  • default, requestor, admin, superadmin, owner (0-4 accordingly)

user_roles function (private.can_assign_role(new_role_id int))

  • function sets hierarchy of roles ( return true if the current user has the “owner” role and the new role is “superadmin”, “admin”, or “requestor” or if the current user has the “superadmin” role and the new role is “admin” or “requestor”etc.)

user_roles.sql

  • create user roles schema
    • user_role_id, user_id, role_id
  • add RLS policies
    • Select: all
    • Insert: private.can_assign_role(new_role_id int)
    • Update: none
    • Delete: private.can_assign_role(new_role_id int)

Note: user_role.sql is named user_role_x.sql since it needs to run after the function during migration (since it runs alphabetically)

neeleshseerapu and others added 30 commits November 20, 2025 23:22
Co-authored-by: Raymond Kao <Oceanspray21@users.noreply.github.com>
Co-authored-by: Neelesh Seerapu <neeleshseerapu@users.noreply.github.com>
Co-authored-by: Neelesh Seerapu <neeleshseerapu@users.noreply.github.com>
@joy-y-cheng joy-y-cheng changed the base branch from user-setup to role-setup December 19, 2025 00:55
@joy-y-cheng joy-y-cheng self-requested a review December 19, 2025 05:05
Copy link
Contributor

@joy-y-cheng joy-y-cheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!! 🤩 Additional edits:

  • Added migration file with your changes
  • Formatted using Prettier
  • Renamed SQL files (put can_assign_role.sql into a functions folder)

Thank you for working on this over break! 🙏

@joy-y-cheng joy-y-cheng merged commit c7a52bc into role-setup Dec 19, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants