Overview
vLife DGO uses MySQL as its primary database, with connection pooling provided by themysql2 package. The application creates multiple connection pools for different database operations, all configured through environment variables.
Database Connection Pools
The application establishes two main connection pools defined insrc/database/Connection.js:
Primary Pool (PoolvLife)
The main connection pool used for most database operations:Secondary Pool (PoolvLifeV2)
An additional connection pool with identical configuration:Both pools connect to the same database as
DB_DATABASE and DB_DATABASEV2 use the same environment variable. The dual-pool architecture provides flexibility for future database separation.Connection Configuration
Connection Parameters
MySQL server hostname or IP address. Set via
DB_HOST environment variable.Database username with appropriate privileges. Set via
DB_USER environment variable.Database user password. Set via
DB_PASS environment variable.MySQL server port. Set via
DB_PORT environment variable.Database name (
vlifedgo_db). Set via DB_DATABASE environment variable.Forces MySQL date and datetime fields to be returned as strings rather than JavaScript Date objects. This ensures consistent date formatting across the application.
Database Requirements
MySQL Version
MySQL 5.7 or higher
vLife DGO requires MySQL 5.7 or higher. MySQL 8.0+ is recommended for optimal performance and security features.
UTF-8 Character Set
Ensure the database uses UTF-8 encoding to support special characters in Spanish text:
Database Setup
Creating the Database
Session Database Configuration
The application also exports a session database configuration object:While this configuration is available for use with
express-mysql-session, the application currently uses MemoryStore for sessions. See Session Management for details.Connection Pool Best Practices
Pool Size Configuration
Themysql2 package uses default pool settings:
- Connection Limit: 10 connections (default)
- Queue Limit: 0 (no limit)
Using Connection Pools
Import and use the connection pools in your code:Database Schema
The vLife DGO database includes tables for:- usuarios - User accounts and authentication
- evaluaciones - Background evaluation records
- datos_personales - Personal information
- datos_familiares - Family information
- datos_academicos - Academic history
- trayectoria_laboral - Work history
- datos_economicos - Economic data
- referencias - References
- documentos - Uploaded documents
- constancias - Verification certificates
Refer to the database migration scripts or schema documentation for complete table definitions and relationships.
Backup and Maintenance
Database Backups
Regular backups are essential for data protection:Automated Backup Script
Troubleshooting
Connection Refused
- Verify MySQL server is running:
sudo systemctl status mysql - Check firewall settings allow port 3306
- Verify
DB_HOSTandDB_PORTare correct
Access Denied
- Verify username and password are correct
- Check user has proper privileges
- Ensure user can connect from the specified host
Too Many Connections
- Increase MySQL max_connections setting
- Reduce connectionLimit in pool configuration
- Check for connection leaks (unreleased connections)
Unknown Database
- Create the database:
CREATE DATABASE vlifedgo_db; - Verify
DB_DATABASEenvironment variable - Check database name spelling
Performance Optimization
Indexes
Ensure proper indexes exist on frequently queried columns:Query Optimization
- Use prepared statements (automatically handled by
mysql2) - Avoid SELECT * queries; specify only needed columns
- Use connection pooling for all database access
- Enable MySQL query cache if using MySQL 5.7
Related Documentation
- Environment Variables - Database connection settings
- Session Management - Session store configuration
- Installation Guide - Complete setup including database