Skip to main content

Core Database Tables

This page documents the core database tables in the MLM CMMS system, defined in sql/modules/core_cmms/03_tables.sql.

RBAC Tables

roles

User roles for permission management.
ColumnTypeDescription
idserialPrimary key
nametextRole name (unique)
descriptionvarcharRole description
is_systembooleanSystem role flag (cannot be deleted)
created_attimestamptzCreation timestamp
Source: sql/modules/core_cmms/03_tables.sql:18

permissions

Permission definitions for access control.
ColumnTypeDescription
iduuidPrimary key
resourcetextResource name (e.g., ‘work_orders’)
actionpermission_actionAction type (create, read, update, etc.)
codetextPermission code (unique, format: resource:action)
labeltextHuman-readable label
descriptiontextPermission description
is_activebooleanActive status
created_attimestamptzCreation timestamp
Source: sql/modules/core_cmms/03_tables.sql:45

role_permissions

Many-to-many mapping between roles and permissions.
ColumnTypeDescription
role_idintForeign key to roles
permission_iduuidForeign key to permissions
Primary Key: (role_id, permission_id) Source: sql/modules/core_cmms/03_tables.sql:56

user_roles

Many-to-many mapping between users and roles.
ColumnTypeDescription
user_iduuidForeign key to auth.users
role_idintForeign key to roles
Primary Key: (user_id, role_id) Source: sql/modules/core_cmms/03_tables.sql:62

User Management

users

Public user profiles linked to auth.users.
ColumnTypeDescription
iduuidPrimary key (FK to auth.users)
rol_idbigintForeign key to roles (legacy)
nametextFirst name
last_nametextLast name
location_idbigintForeign key to locations
emailtextEmail address
phonetextPhone number
is_activebooleanActive status
created_attimestampCreation timestamp
updated_attimestamptzLast update timestamp
created_byuuidUser who created this record
updated_byuuidUser who last updated this record
password_reset_attimestamptzLast password reset timestamp
password_reset_byuuidUser who performed password reset
Source: sql/modules/core_cmms/03_tables.sql:28

assignees

Technicians and maintenance staff who can be assigned to work orders.
ColumnTypeDescription
idbigserialPrimary key
nametextFirst name
last_nametextLast name
sectionassignee_section_enumSection (INTERNOS, TERCEROS, OTROS)
user_iduuidOptional link to users table
emailtextEmail address
phonetextPhone number
is_activebooleanActive status
created_attimestamptzCreation timestamp
updated_attimestamptzLast update timestamp
created_byuuidUser who created this record
updated_byuuidUser who last updated this record
Unique Constraint: (name, section) Source: sql/modules/core_cmms/03_tables.sql:68

Ticket Management

tickets

Main table for work requests and work orders.
ColumnTypeDescription
idbigserialPrimary key
titletextTicket title
descriptiontextDetailed description
is_acceptedbooleanAccepted as work order flag
is_urgentbooleanUrgent priority flag
prioritypriority_enumPriority level
requestertextRequester name
location_idbigintForeign key to locations
assigneetextLegacy assignee field (visible)
special_incident_idintegerForeign key to special_incidents
incident_datedateDate incident occurred
deadline_datedateDeadline for completion
is_archivedbooleanArchived status
finalized_attimestampCompletion timestamp
imagetextImage URL or path
emailtextRequester email
statusstatus_enumCurrent status
order_indexintegerManual ordering index
notestextAdditional notes
created_attimestamptzCreation timestamp
updated_attimestamptzLast update timestamp
Source: sql/modules/core_cmms/03_tables.sql:84

work_order_assignees

Many-to-many relationship between tickets and assignees.
ColumnTypeDescription
idbigserialPrimary key
ticket_idbigintForeign key to tickets
assignee_idbigintForeign key to assignees
rolewo_assignee_role_enumRole (PRIMARY, SECONDARY)
assigned_attimestamptzAssignment timestamp
assigned_byuuidUser who made the assignment
Unique Constraint: (ticket_id, assignee_id) Source: sql/modules/core_cmms/03_tables.sql (reference in DROP statements)

Configuration Tables

locations

Physical locations where maintenance is performed.
ColumnTypeDescription
idbigserialPrimary key
nametextLocation name
addresstextPhysical address
is_activebooleanActive status
created_attimestamptzCreation timestamp
updated_attimestamptzLast update timestamp
Source: Referenced in foreign keys

societies

Company or organization information.
ColumnTypeDescription
idbigserialPrimary key
nametextCompany name
logo_urltextLogo image URL
primary_colortextBrand primary color
secondary_colortextBrand secondary color
is_activebooleanActive status
Source: Referenced in DROP statements

app_settings

Application-wide configuration settings.
ColumnTypeDescription
keytextSetting key (primary key)
valuejsonbSetting value (JSON)
updated_attimestamptzLast update timestamp
Source: Referenced in DROP statements

special_incidents

Predefined incident types for categorization.
ColumnTypeDescription
idserialPrimary key
nametextIncident type name
descriptiontextDescription
is_activebooleanActive status
Source: Referenced in DROP statements

Communication Tables

announcements

System-wide announcements.
ColumnTypeDescription
idbigserialPrimary key
titletextAnnouncement title
messagetextAnnouncement content
severitytextSeverity level
is_activebooleanActive status
created_attimestamptzCreation timestamp
expires_attimestamptzExpiration timestamp
Source: Referenced in DROP statements

announcement_audience_roles

Roles that should see specific announcements.
ColumnTypeDescription
announcement_idbigintForeign key to announcements
role_idintForeign key to roles
Primary Key: (announcement_id, role_id) Source: Referenced in DROP statements

Notification Tables

See Notifications Database Schema for detailed documentation of the notification system tables:
  • notification_events
  • notification_deliveries
  • notification_outbox
  • notification_push_subscriptions

Reporting Tables

report_layout_preferences

User preferences for report dashboard layouts.
ColumnTypeDescription
user_iduuidPrimary key (FK to users)
layout_datajsonbLayout configuration (JSON)
updated_attimestamptzLast update timestamp
Source: Referenced in DROP statements

Database Enums

The system uses several PostgreSQL enums defined in sql/modules/core_cmms/01_enums.sql:
  • permission_action: create, read, read_own, update, delete, work, import, export, approve, assign, disable, full_access, cancel, manage_roles, manage_permissions
  • priority_enum: LOW, MEDIUM, HIGH, CRITICAL
  • status_enum: PENDIENTE, EN_EJECUCION, FINALIZADA
  • assignee_section_enum: INTERNOS, TERCEROS, OTROS, SIN_ASIGNAR
  • wo_assignee_role_enum: PRIMARY, SECONDARY

Next Steps

Database Functions

Learn about stored procedures and triggers

RLS Policies

Understand row-level security implementation

Notifications Schema

Explore the notification system tables

Database Schema Overview

See the complete schema documentation