Documentation Index
Fetch the complete documentation index at: https://mintlify.com/EdgarJr30/proyecto-de-grado-cms/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The MLM CMMS database is structured using modular SQL scripts that must be executed in a specific order. The database setup includes core CMMS functionality, RBAC (Role-Based Access Control), notifications, assets management, and optional inventory modules.Module Structure
The SQL modules are organized undersql/modules/:
core_cmms
Core CMMS functionality including RBAC, tickets, work orders, RLS policies, storage, and notifications
assets
Fixed assets management and preventive maintenance scheduling
inventory
Inventory and spare parts management (optional, isolated module)
Execution Order
Phase 1: Core CMMS Module
Execute these scripts in order through the Supabase SQL Editor:Extensions
File:
sql/modules/core_cmms/00_extensions.sqlInstalls required PostgreSQL extensions:pg_trgm: Trigram-based text searchunaccent: Remove accents for search normalizationpgcrypto: Cryptographic functionspg_cron: Scheduled job execution
Enums
File:
sql/modules/core_cmms/01_enums.sqlCreates enum types:priority_enum: Ticket priorities (Baja, Media, Alta)assignee_section_enum: Assignee categoriesassignee_role_enum: Primary/Secondary roles
Permission Actions
File:
sql/modules/core_cmms/02_permission_action.sqlDefines permission action enum for RBAC system.Tables
File:
sql/modules/core_cmms/03_tables.sqlCreates core database tables:users: User profiles linked to auth.usersroles: User rolespermissions: Permission definitionsrole_permissions: Role-permission mappingsuser_roles: User-role assignmentstickets: Maintenance tickets/work requestsassignees: Maintenance personnellocations: Service locationssocieties: Company/organization entitieswork_order_assignees: Work order assignmentsspecial_incidents: Incident categoriesapp_settings: Application configurationannouncements: System announcements
Functions & Triggers
File:
sql/modules/core_cmms/04_functions_triggers.sqlImplements business logic functions and automated triggers.Foreign Keys
File:
sql/modules/core_cmms/05_fk.sqlEstablishes referential integrity constraints between tables.Indexes
File:
sql/modules/core_cmms/07_indexes.sqlAdds performance indexes for frequently queried columns.Row-Level Security (RLS)
File:
sql/modules/core_cmms/08_rls.sqlEnables RLS on all public tables to enforce data access control.Security Policies
File:
sql/modules/core_cmms/09_policies.sqlDefines RLS policies based on RBAC permissions.Admin Permissions Seed
File:
sql/modules/core_cmms/10_seed_admin_permissions.sqlSeeds initial permissions for system administrators.Bootstrap Data
File:
sql/modules/core_cmms/11_seed_bootstrap.sqlLoads initial data:- Default roles (Admin, Technician, Requester)
- System locations
- Incident categories
- Application settings
Schema Updates
File:
sql/modules/core_cmms/12_updates.sqlApplies incremental schema updates and migrations.Realtime Configuration
File:
sql/modules/core_cmms/13_realtime.sqlConfigures Supabase Realtime for live data synchronization:Storage Policies
File:
sql/modules/core_cmms/14_storage.sqlConfigures Supabase Storage buckets and policies for file uploads:- Ticket attachments
- User avatars
- Asset photos
Auth Grants
File:
sql/modules/core_cmms/15_grants_auth.sqlGrants necessary permissions to auth schema for user management.Notifications System
File:
sql/modules/core_cmms/16_notifications.sqlImplements complete notifications infrastructure:notification_deliveries: In-app notificationsticket_comments: Comment system with automatic notificationsnotification_outbox: Push notification queue- Outbox pattern with retry logic and deduplication
- Admin test tools
- RPC functions for frontend integration
Phase 2: Assets Module (Optional)
If you need fixed assets and preventive maintenance:Fixed Assets Tables
File:
sql/modules/assets/01_activos_fijos.sqlCreates tables for asset tracking and management.Assets-Tickets Integration
File:
sql/modules/assets/02_ticket_assets_policies_patch.sqlLinks assets to tickets with appropriate RLS policies.Phase 3: Inventory Module (Optional)
Post-SQL Configuration
After executing all SQL modules, complete these additional configurations:Realtime Verification
Verify that critical tables are enabled for Realtime:- Via Supabase Dashboard
- Via SQL Query
- Go to Database > Replication
- Verify these tables are in the publication:
public.notification_deliveriespublic.ticket_comments
- Check that both tables have
REPLICA IDENTITY FULL
Verify Database Setup
Run these verification queries to ensure proper setup:Creating the First Admin User
After database setup, create your first admin user:- Prompts for admin credentials
- Creates the user in auth.users
- Assigns the admin role
- Grants full system permissions
The script requires
SUPABASE_URL and SUPABASE_SERVICE_ROLE_KEY environment variables.Database Backup Recommendations
Enable Point-in-Time Recovery
Configure automatic backups in Supabase dashboard under Settings > Database > Backups.
Troubleshooting
”Permission denied” Errors
- Ensure you’re using a user with
postgresrole privileges - Some extensions require superuser access
- Contact Supabase support if you cannot install required extensions
Foreign Key Constraint Errors
- Verify all previous scripts completed successfully
- Check that referenced tables exist before creating foreign keys
- Review execution order
RLS Policy Errors
- Ensure the RBAC permission functions are created before policies
- Verify that
public.me_has_permission()function exists - Check that admin permissions were seeded properly
Outbox Not Processing
Next Steps
Supabase Configuration
Configure Edge Functions, Storage, and Realtime settings
Production Build
Build and deploy the frontend application