Prerequisites
- MySQL 8.0 or higher
- Database user with CREATE, ALTER, INSERT, UPDATE, DELETE privileges
- MySQL client or GUI tool (optional)
Quick Start
Configure Connection
Update your
application.properties or set environment variables:The database name in the connection URL should match the database you created.
Database Schema
The DriveX application uses the following core tables:Vehicles Table
Stores vehicle inventory information:| Field | Type | Description |
|---|---|---|
id | INT | Primary key, auto-increment |
reference | VARCHAR(50) | Unique vehicle reference code (e.g., REF001) |
brand | ENUM | Vehicle brand from predefined list |
model | VARCHAR(20) | Vehicle model name |
hp | INT | Horsepower |
autonomy | INT | Range/autonomy in kilometers |
average_consumption | REAL | Average fuel/energy consumption |
price | REAL | Sale or rental price |
fuel_type | VARCHAR(20) | Fuel type (Gasolina, Diésel, Eléctrico, Híbrido) |
The
brand field uses an extensive ENUM containing over 100 vehicle brands including cars, motorcycles, and classic vehicles.Vehicle Images Table
Manages multiple images per vehicle:- Multiple images per vehicle
is_mainflag to mark the primary image- Cascading delete when vehicle is removed
Users Table
Stores user account information:| Field | Type | Description |
|---|---|---|
password_hash | VARCHAR(255) | Hashed password using BCrypt |
is_active | BOOLEAN | Account activation status |
role | VARCHAR(20) | User role (e.g., “Admin”, “User”) |
Rentals Table
Tracks vehicle rental reservations:- Date range validation for rental periods
- Composite index on vehicle and dates for efficient availability queries
- Cascading deletes to maintain referential integrity
- Automatic timestamp updates
Transactions Table
Records financial transactions for sales and rentals:- Vehicle sales
- Rental payments
- Deposits and refunds
pending- Payment pendingpaid- Payment completedshipped- Vehicle in transit (for sales)delivered- Transaction completedcancelled- Transaction cancelled
JPA Configuration
The application uses Spring Data JPA with Hibernate. Configuration inapplication.properties:
DDL Auto Options
| Option | Behavior | Use Case |
|---|---|---|
create | Drop and recreate tables on startup | Initial development |
create-drop | Create on startup, drop on shutdown | Testing |
update | Update schema to match entities | Development |
validate | Only validate schema matches entities | Production |
none | No schema management | Production with manual migrations |
Database Connection Pooling
Spring Boot automatically configures HikariCP as the connection pool. Default settings are suitable for most applications. Optional HikariCP Configuration:Sample Data
The database schema includes sample data for testing. Thebs.sql file contains INSERT statements for:
- 100 vehicles covering luxury cars, standard vehicles, motorcycles, and classic cars
- Diverse brands including Ferrari, Lamborghini, Toyota, Yamaha, Ducati, and more
- Price range from €3,000 to €2.8M
- Various fuel types: Gasoline, Diesel, Electric, Hybrid
Sample data is useful for development and testing but should not be used in production environments.
Database Migrations
For production environments, consider using database migration tools:Troubleshooting
Connection Issues
Unable to connect to MySQL
Unable to connect to MySQL
Checklist:
- Verify MySQL is running:
systemctl status mysqlorbrew services list - Check host and port in connection URL
- Verify username and password
- Ensure database exists:
SHOW DATABASES; - Check firewall rules if connecting remotely
Authentication errors
Authentication errors
Solutions:
Schema validation errors
Schema validation errors
If you encounter schema mismatch errors:
- Verify
spring.jpa.hibernate.ddl-autosetting - Check entity classes match database schema
- Clear and regenerate schema if in development:
Railway MySQL Deployment
The application is configured for Railway’s MySQL service:Railway automatically provides the internal MySQL hostname and injects credentials via environment variables.
Next Steps
Configuration
Configure application properties and environment variables
Deployment
Deploy your application to production