Database Setup
DentControl uses Laravel’s migration system to manage database schema. This guide covers database configuration, running migrations, and understanding the database structure.Database Options
DentControl supports multiple database systems out of the box.Supported Databases
SQLite
Default choiceSingle file database, perfect for development and small deployments. No server required.
MySQL
Production readyPopular relational database with excellent performance and wide hosting support.
PostgreSQL
Advanced featuresRobust database with advanced features and strong data integrity.
SQLite Setup (Default)
SQLite is the default database and requires minimal configuration.SQLite stores the entire database in a single file at
database/database.sqlite.MySQL Setup
PostgreSQL Setup
Running Migrations
Migrations create and modify database tables. DentControl includes all necessary migrations.Initial Migration
Run migrations for the first time:Migration Commands
| Command | Description |
|---|---|
php artisan migrate | Run pending migrations |
php artisan migrate:status | Show migration status |
php artisan migrate:rollback | Rollback last batch |
php artisan migrate:reset | Rollback all migrations |
php artisan migrate:refresh | Reset and re-run all migrations |
php artisan migrate:fresh | Drop all tables and re-migrate |
Use
migrate:fresh with caution - it deletes all data!Migration File Structure
DentControl includes the following migrations (in execution order):Laravel System Tables
System Migrations
DentControl Application Tables
Clinica (Clinic)
File:
2026_02_23_084014_create_clinica_table.phpThe root table for multi-clinic support. Stores clinic information, address, and status.Key Fields
Catalogo Servicios (Service Catalog)
File:
2026_02_23_085029_create_catalogo_servicios_table.phpServices offered by each clinic (e.g., “Limpieza”, “Ortodoncia”).Key Fields
Catalogo Tratamientos (Treatment Catalog)
File:
2026_02_23_085812_create_catalogo_tratamientos_table.phpTreatment types offered by clinics.Paciente (Patient)
File:
2026_02_23_090302_create_paciente_table.phpPatient information and medical records.Key Fields
Usuario (User)
File:
2026_02_23_090927_create_usuario_table.phpSystem users (dentists, assistants, admins).Key Fields
Expediente Clinico (Clinical Record)
File:
2026_02_23_092325_create_expediente_clinico_table.phpPatient medical history and clinical information.Tratamiento (Treatment)
File:
2026_02_23_092642_create_tratamiento_table.phpActive treatments for patients.Key Fields
Notas Evolucion (Clinical Notes)
File:
2026_02_23_093121_create_notas_evolucion_table.phpProgress notes for treatments.Acceso Movil (Mobile Access)
File:
2026_02_23_093639_create_acceso_movil_table.phpMobile app access tokens.Database Schema Overview
Here’s how the main tables relate to each other:Key Relationships
- Clinic-centric: All major entities belong to a clinic (
id_clinica) - User assignments: Users (dentists/assistants) are assigned to one clinic
- Patient records: Patients belong to a clinic and have multiple appointments
- Appointments: Link patients, users (dentists), services, and optionally treatments
- Treatments: Ongoing treatment plans with clinical notes
- Cascade deletes: Most tables use
onDelete('cascade')for referential integrity
Seeding Data
Seeders populate the database with initial or test data.Running Seeders
Creating Custom Seeders
Create a seeder for initial data:Database Maintenance
Backup Database
Restore Database
Database Optimization
Optimize Database
Database Inspection
Using Artisan Commands
Using Tinker
Interact with your database using Laravel Tinker:Troubleshooting
Migration fails - table already exists
Migration fails - table already exists
This means migrations were partially run. Options:
-
Check migration status:
-
Rollback and retry:
-
Fresh start (destroys data!):
SQLite database locked
SQLite database locked
SQLite locks the entire database during writes.Solutions:
- Close any database browser tools
- Stop any running queue workers
- Check file permissions:
- For production, consider MySQL or PostgreSQL
Foreign key constraint fails
Foreign key constraint fails
This occurs when trying to insert data without required parent records.Example: Creating a user without a clinic:Order matters! Create parent records first:
- Clinica
- CatalogoServicios, CatalogoTratamientos
- Usuario, Paciente
- ExpedienteClinico, Tratamiento
- Citas, NotasEvolucion
Migration timeout on large databases
Migration timeout on large databases
For large migrations, increase timeout:Or run migrations with higher limits:
Cannot connect to database
Cannot connect to database
Check these common issues:
-
Database server running?
-
Credentials correct?
- Verify
.envsettings - Test with database client
- Verify
-
Firewall blocking?
-
Clear config cache:
Character encoding issues
Character encoding issues
Ensure UTF-8 encoding for proper Spanish character support:MySQL:PostgreSQL:SQLite: UTF-8 by default
Best Practices
- Always backup before migrations: Especially on production
- Test migrations locally first: Run on dev environment before production
- Use transactions: Migrations automatically wrap operations in transactions
- Version control migrations: Never modify existing migrations, create new ones
- Document custom migrations: Add comments explaining complex schema changes
- Regular backups: Automate daily database backups
- Monitor database size: Watch SQLite file size, consider MySQL/PostgreSQL for growth
- Use seeders for initial data: Keep test data consistent across environments
Next Steps
Configuration
Configure database connection settings
User Management
Create users and manage access
Deployment
Deploy your database to production