Overview
The Tandex Electronics API uses MySQL as its primary database for storing users, products, publications, and activity logs. This guide covers the complete database setup process.Database Schema Overview
The database consists of several core tables and stored procedures:Core Tables
usuarios - User accounts
usuarios - User accounts
Stores user authentication and profile information including:
- User credentials (email, encrypted password)
- User type/role (admin, regular user)
- Personal information (name, surname)
- Unique user identifier
productossae - Product catalog
productossae - Product catalog
Main product inventory table containing:
- Product key/SKU (
claveProducto) - Product line (
linea) - Description (
descripcionP) - Price (
precio) - Stock levels (
existencias) - Unit of entry (
unidadEntrada) - WooCommerce metadata (type, descriptions, categories)
productos_publicados - Published products
productos_publicados - Published products
Tracks which products have been published to external platforms:
- Product key reference (
claveProductoP) - Platform identifier (
woocomerce) - User who published (
idUsuarioPP) - Publication timestamp
bitacora - Activity log
bitacora - Activity log
Audit log for tracking system activities:
- User ID (
idUsuarioB) - Action timestamp (
fecha) - Type of modification (
modificacion) - Quantity of items affected (
cantidad)
Database Connection Setup
The API uses a connection pool for efficient database access:dbconn.js
Connection Configuration
Configure your database credentials inconfig/default.json:
config/default.json
The connection pool is configured with a limit of 20 concurrent connections for optimal performance.
Running the SQL Schema
Database Schema Tables
Thebackend.sql file creates the following table structure:
Stored Procedures
The application uses several stored procedures for data validation and manipulation:verificar_clave_primary_producto
Validates if a product key already exists before insertion:Usage in cliente.js
update_productos
Inserts or updates product information from Excel uploads:Usage in cliente.js
valida_correo_repetido
Checks if an email already exists in the user table:Usage in cliente.js
Database Credentials Setup
For production environments, use environment-specific configuration:The
config package automatically loads the appropriate configuration file based on the NODE_ENV environment variable.Connection Pool Benefits
- Performance: Reuses connections instead of creating new ones for each query
- Scalability: Handles up to 20 concurrent database operations
- Reliability: Automatic connection management and error handling
- Promise-based: Modern async/await compatible API
Troubleshooting
Connection refused errors
Connection refused errors
- Verify MySQL is running:
sudo systemctl status mysql - Check firewall settings allow connections on port 3306
- Ensure the host address is correct
Authentication failures
Authentication failures
- Verify username and password in
config/default.json - Check user has appropriate database privileges
- Test connection manually:
mysql -h host -u user -p
Database not found errors
Database not found errors
- Ensure the database exists:
SHOW DATABASES; - Check database name spelling in config file
- Create the database if missing