Skip to main content

User Roles and Permissions

Brief introduction to the concept of user roles and permissions. Database Schema Overview and how it is used in the context of user roles and permissions.

Introduction to Database Schema

In a system where users have different roles and permissions, a well-designed database schema is essential for managing user access effectively. This page explains the database schema for user roles and permissions, outlining the tables, their relationships, and how users interact with them.

Roles Table

The roles table stores information about the different roles available in the system. Each role has a unique identifier (role_id), a name (role_name), a description (description), and a timestamp (created_at) indicating when the role was created. The role_id column serves as the primary key for the table.

Below is the schema for the roles table:

Column NameData TypeDescriptionKey Details
role_idstringUnique identifier for the rolePrimary Key
role_namestringName of the roleNot Null
descriptionstringDescription of the roleNot Null
created_atdatetimeTimestamp when the role was createdNot Null

Permissions Table

The permissions table stores information about the different permissions available in the system. Each permission has a unique identifier (permission_id), a name (permission_name), a description (description), and timestamps (created_at, updated_at) indicating when the permission was created or last updated. The permission_id column serves as the primary key for the table.

The permission_data column is a JSON field that can store additional key-value pairs of data related to the permission. This can be used to store metadata or configuration information for the permission.

Schema for the permissions table as follows:

Column NameData TypeDescriptionKey Details
permission_idstringUnique identifier for the permissionPrimary Key
permission_namestringName of the permissionNot Null
descriptionstringDescription of the permissionNot Null
created_atdatetimeTimestamp when the permission was createdNot Null
updated_atdatetimeTimestamp when the permission was last updatedNot Null
permission_datajsonAdditional data related to the permissionOptional

User_Roles Table

The user_roles table is a mapping table that associates users with roles. It stores information about which roles are assigned to which users, along with the user who assigned the role and the timestamp when the role was assigned.

Schema for the user_roles table as follows:

Column NameData TypeDescriptionKey Details
user_idstringUser identifier of the userForeign Key to Users
role_idstringRole identifier of the roleForeign Key to Roles
assigned_bystringUser identifier of the user who assigned the roleForeign Key to Users
assigned_atdatetimeTimestamp when the role was assignedNot Null

Role_Permissions Table

The role_permissions table is a mapping table that associates roles with permissions. It stores information about which permissions are assigned to which roles, along with the user who assigned the permission and the timestamp when the permission was assigned.

Schema for the role_permissions table as follows:

Column NameData TypeDescriptionKey Details
role_idstringRole identifier of the roleForeign Key to Roles
permission_idstringPermission identifier of the permissionForeign Key to Permissions
assigned_bystringUser identifier of the user who assigned the permissionForeign Key to Users
assigned_atdatetimeTimestamp when the permission was assignedNot Null
Note

We are planning to add Groups table in the future to manage user groups and their permissions. Along with nested groups functionality. Stay tuned for updates.