Overview
InvestGo uses MySQL as its primary database for storing users, invoices, investments, transactions, and related data. The application is configured with Hibernate JPA for ORM and includes automatic schema creation and initial data seeding.Database Requirements
Prerequisites
- MySQL Version: 8.0 or higher recommended
- Character Set: UTF-8 (default)
- Storage Engine: InnoDB (default)
- Minimum Storage: 100MB initial, scale as needed
- Database Name:
InvestGo
MySQL Installation
Database Creation
Manual Setup
The application will automatically create all required tables on first run using Hibernate’s
ddl-auto=update setting.Application Configuration
application.properties
Fromsrc/main/resources/application.properties:
Configuration Properties Explained
| Property | Value | Description |
|---|---|---|
server.port | 8091 | Tomcat server port |
spring.jpa.database | MYSQL | Database type |
spring.jpa.show-sql | true | Log SQL queries to console (disable in production) |
spring.datasource.driver-class-name | com.mysql.cj.jdbc.Driver | MySQL JDBC driver |
spring.datasource.url | jdbc:mysql://localhost:3306/InvestGo | Database connection URL |
spring.datasource.username | root | Database username |
spring.datasource.password | 1234 | Database password |
hibernate.dialect | MySQL8Dialect | Hibernate SQL dialect for MySQL 8 |
ddl-auto | update | Auto-update schema on changes |
hibernate.format_sql | true | Format SQL output for readability |
Schema Creation (ddl-auto)
Automatic Schema Management
Withspring.jpa.hibernate.ddl-auto=update, Hibernate automatically:
- Creates tables if they don’t exist
- Adds new columns when entities are modified
- Does NOT remove columns or tables
- Updates relationships and constraints
DDL-Auto Options
| Option | Behavior | Use Case |
|---|---|---|
none | No automatic schema management | Manual control |
validate | Validate schema matches entities | Production (safest) |
update | Update schema to match entities | Development |
create | Drop and recreate schema on startup | Testing |
create-drop | Drop schema on shutdown | Integration tests |
Recommendation: Use
update for development, but switch to validate in production and manage schema changes with migration tools like Flyway or Liquibase.Initial Data Seeding
The application automatically seeds essential data on first startup throughCommandLineRunner in SistemaFactoringBackendApplication.java:51-140.
Seeded Data Overview
Detailed Seed Data
Roles (2 records)
Roles (2 records)
SistemaFactoringBackendApplication.javaAdmin User (1 record)
Admin User (1 record)
- Username:
jamie - Password:
Admin12345 - Initial Balance: S/. 10,000,000
SistemaFactoringBackendApplication.javaTransaction Types (2 records)
Transaction Types (2 records)
SistemaFactoringBackendApplication.javaBanks (7 records)
Banks (7 records)
SistemaFactoringBackendApplication.javaCurrencies (2 records)
Currencies (2 records)
SistemaFactoringBackendApplication.javaRisk Levels (3 records)
Risk Levels (3 records)
- A: Minimal risk (safest investments)
- B: Near-zero risk
- C: Elevated risk (higher returns, higher risk)
SistemaFactoringBackendApplication.javaSeed data is only inserted if the corresponding records don’t already exist. The application checks for existence before seeding to avoid duplicates on restarts.
Table Structure and Relationships
Core Tables
The application manages the following main entities:Table Descriptions
| Table | Purpose | Key Relationships |
|---|---|---|
Usuario | User accounts (investors & admin) | Has one Cartera, belongs to Rol |
Rol | User roles (ADMIN, INVERSIONISTA) | Has many Usuario |
Cartera | User wallet/balance | Belongs to Usuario, has many Transaccion |
Factura | Invoices available for factoring | Has many Inversion, uses Monedas and Riesgo |
Inversion | Investment records | Belongs to Usuario and Factura |
Transaccion | Financial transactions | Belongs to Cartera, uses TipoTransaccion and Bancos |
TipoTransaccion | Transaction types (Deposit/Withdrawal) | Has many Transaccion |
Bancos | Supported banks | Has many Transaccion |
Monedas | Currencies (PEN, USD) | Has many Factura |
Riesgo | Risk levels (A, B, C) | Has many Factura |
Database Migration Considerations
From Development to Production
When moving to production, consider these migration strategies:Implement Migration Tool
Add Flyway or Liquibase for version-controlled migrations:Flyway (recommended):
Connection Testing
Verify Database Connectivity
Common Database Issues
Connection Refused
Connection Refused
Error:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failurePossible Causes:- MySQL server not running
- Wrong host or port in connection URL
- Firewall blocking connection
Access Denied for User
Access Denied for User
Error:
java.sql.SQLException: Access denied for user 'root'@'localhost'Possible Causes:- Wrong username or password in
application.properties - User doesn’t have privileges on database
Database Does Not Exist
Database Does Not Exist
Error: Or enable automatic creation (development only):
java.sql.SQLSyntaxErrorException: Unknown database 'InvestGo'Solution:Table Already Exists
Table Already Exists
Error:
Table 'Usuario' already existsCause: Usually occurs with ddl-auto=create when tables existSolutions:- Change to
ddl-auto=update - Drop and recreate database (development only)
Hibernate Dialect Error
Hibernate Dialect Error
Error:
org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be nullSolution: Ensure MySQL8Dialect is specified:Performance Optimization
Connection Pool Configuration
For production environments, configure HikariCP (default in Spring Boot):Database Indexes
Consider adding indexes for frequently queried columns:Query Optimization
Enable query logging to identify slow queries:Backup and Recovery
Backup Strategy
Recovery
Related Configuration Files
- Database Properties:
src/main/resources/application.properties - Seed Data Logic:
src/main/java/com/proyecto/integrador/SistemaFactoringBackendApplication.java - Entity Definitions:
src/main/java/com/proyecto/integrador/entidades/ - Service Layers:
src/main/java/com/proyecto/integrador/servicios/
Next Steps
- Configure Authentication
- Review Security Settings
- Explore API Endpoints