question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Define DB schema and APIs for UserRoles

See original GitHub issue

šŸš€ Feature

Define the DB schema and APIs for user roles and permissions

NOTE : The delete user API should also call the remove user roles API

Implementation details

DB schema


MySQL

CREATE TABLE IF NOT EXISTS roles (
  role VARCHAR(255) NOT NULL,
  PRIMARY KEY (role)  
);

CREATE TABLE IF NOT EXISTS role_permissions (
  role VARCHAR(255) NOT NULL,
  permission VARCHAR(255) NOT NULL,
  PRIMARY KEY (role, permission),
  FOREIGN KEY (role) REFERENCES roles(role) ON DELETE CASCADE
);

CREATE INDEX role_permissions_permission_index ON role_permissions(permission);

CREATE TABLE IF NOT EXISTS user_roles (
  user_id VARCHAR(128) NOT NULL,
  role VARCHAR(255) NOT NULL,
  PRIMARY KEY (user_id, role),
  FOREIGN KEY (role)  REFERENCES roles (role) ON DELETE CASCADE
);

CREATE INDEX user_roles_role_index ON user_roles(role);

PSQL

CREATE TABLE IF NOT EXISTS roles (
  role VARCHAR(255) NOT NULL,
  CONSTRAINT roles_pkey PRIMARY KEY (role)  
);

CREATE TABLE IF NOT EXISTS role_permissions (
  role VARCHAR(255) NOT NULL,
  permission VARCHAR(255) NOT NULL,
  CONSTRAINT role_permissions_pkey PRIMARY KEY (role, permission),
  CONSTRAINT role_permissions_role_fkey FOREIGN KEY (role) REFERENCES roles(role) ON DELETE CASCADE
);

CREATE INDEX role_permissions_permission_index ON role_permissions(permission);

CREATE TABLE IF NOT EXISTS user_roles (
  user_id VARCHAR(128) NOT NULL,
  role VARCHAR(255) NOT NULL,
  CONSTRAINT user_roles_pkey PRIMARY KEY (user_id, role),
  CONSTRAINT user_roles_role_fkey FOREIGN KEY (role)  REFERENCES roles (role) ON DELETE CASCADE
);

CREATE INDEX user_roles_role_index ON user_roles(role);

Core API spec

user_roles_spec


Core APIs Psuedo code



Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rishabhpoddarcommented, Mar 26, 2022

Looks good.

0reactions
jscyocommented, Apr 27, 2022

API Spec:

PUT /recipe/user/role:

  • userId, role => { status: ā€œOKā€, didUserAlreadyHaveRole: boolean } | { status: ā€œUNKNOWN_ROLE_ERRORā€ }

POST /recipe/user/role/remove:

  • userId, role => {status: ā€œOKā€, didUserHaveRole: boolean } | {status: ā€œUNKNOWN_ROLE_ERRORā€ }

GET /recipe/user/roles:

  • userId => {status: ā€œOKā€, roles: str[ ] }

GET /recipe/role/users:

  • role => {status: ā€œOKā€, users: str[ ] } | {status: ā€œUNKNOWN_ROLE_ERRORā€ }

PUT /recipe/role:

  • role, permissions?: str[ ] => { status: ā€œOKā€, createdNewRole: boolean }

GET /recipe/role/permissions

  • role => { status: ā€œOKā€, permissions: str[ ]} | {status: ā€œUNKNOWN_ROLE_ERRORā€ }

POST /recipe/role/permissions/remove:

  • role, permissions?: str[ ] => { status: ā€œOKā€} | {status: ā€œUNKNOWN_ROLE_ERRORā€ }

GET /recipe/permission/roles:

  • permission => { status: ā€œOKā€, roles: str[]}

POST /recipe/role/remove

  • role => { status: OK, didRoleExist: boolean }

GET /recipe/roles:

  • => { status: ā€œOKā€, roles: str[ ] }
Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a Database Schema? - IBM
A database schema defines how data is organized within a relational database; this is inclusive of logical constraints such as, table names,Ā ...
Read more >
Overview of Role System ā€” PostgREST 9.0.0 documentation
PostgREST is designed to keep the database at the center of API security. ... types of roles used by PostgREST, the authenticator, anonymous...
Read more >
Using your own database schema and classes with ASP.NET ...
I'm going to walk you through configuring ASP.NET Core Identity to use your own database schema instead of the default tables and columnsĀ ......
Read more >
Managing Roles and Permissions - FIWARE Tutorials
Description: The tutorial explains how to create applications, and how to assign roles and permissions to them. It takes the users andĀ ...
Read more >
2 Configuring Application Users and Application Roles
About Application User Accounts. Traditional database users own database schemas and can create traditional heavyweight database sessions to those schemas.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found