Database Overview
Ecom uses Laravel’s database abstraction layer and supports multiple database systems. The database configuration is defined inconfig/database.php with environment-specific values from .env.
Supported Database Systems
Ecom supports the following database systems (defined inconfig/database.php:34):
MySQL
Default and recommended database system
PostgreSQL
Advanced open-source database
SQLite
Lightweight file-based database
SQL Server
Microsoft SQL Server support
Database Configuration
MySQL Setup (Recommended)
MySQL is the default database connection (config/database.php:16):
MySQL Configuration Details
MySQL connection settings fromconfig/database.php:42:
Ecom uses
utf8mb4 charset for full Unicode support, including emojis and special characters.PostgreSQL Setup
PostgreSQL configuration fromconfig/database.php:57:
PostgreSQL settings:
SQLite Setup
SQLite configuration fromconfig/database.php:36:
SQLite is suitable for development and testing but not recommended for production.
Database Migrations
Ecom uses Laravel migrations to manage database schema. Migration table is tracked inmigrations table (config/database.php:94).
Running Migrations
Core Database Tables
Ecom creates the following core tables:Users Table
Defined indatabase/migrations/2014_10_12_000000_create_users_table.php:16:
id- Unique user identifiername- User full nameemail- Unique email addressemail_verified_at- Email verification timestamppassword- Hashed passwordremember_token- Remember me tokencreated_at,updated_at- Timestamps
Password Resets Table
Defined indatabase/migrations/2014_10_12_100000_create_password_resets_table.php:
Personal Access Tokens Table
For Laravel Sanctum API authentication (database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php):
Product Queries Table
Defined indatabase/migrations/2022_06_29_075906_create_product_queries_table.php:16:
id- Query identifiercustomer_id- Customer who askedseller_id- Seller who repliedproduct_id- Related productquestion- Customer questionreply- Seller replycreated_at,updated_at- Timestamps
Products Table Updates
The products table includes hover image support (database/migrations/2026_03_02_000001_add_thumbnail_hover_img_to_products_table.php:16):
Migration Commands
Database Seeding
Seeding populates your database with test data:database/seeds/ (defined in composer.json:60).
Redis Configuration
Redis is configured for caching and queues (config/database.php:107):
predis client for Redis operations.
Setting Up Redis
.env
Database Optimization
Indexing
Ensure proper indexes for better performance:Query Optimization
- Enable Query Logging
- Use Query Builder
- Eager Loading
Backup & Restore
Backup Database
Ecom includes Spatie DB Dumper package:Restore Database
Troubleshooting
Connection Refused
Connection Refused
Error:
SQLSTATE[HY000] [2002] Connection refusedSolutions:- Verify database server is running
- Check DB_HOST and DB_PORT in
.env - Ensure firewall allows database connections
- Test connection:
mysql -u username -p
Access Denied
Access Denied
Error:
SQLSTATE[HY000] [1045] Access deniedSolutions:- Verify DB_USERNAME and DB_PASSWORD
- Check user has proper privileges
- Recreate user with correct permissions
Database Not Found
Database Not Found
Error:
SQLSTATE[HY000] [1049] Unknown databaseSolutions:- Create the database:
CREATE DATABASE database_name; - Verify DB_DATABASE value in
.env
Migration Failed
Migration Failed
Error: Migration errors during
php artisan migrateSolutions:- Check migration status:
php artisan migrate:status - Review error message for specific table/column issues
- Rollback and retry:
php artisan migrate:rollback - Check database user has CREATE, ALTER, DROP privileges
Character Encoding Issues
Character Encoding Issues
Error: Special characters not displaying correctlySolutions:
- Ensure database uses
utf8mb4charset - Set collation to
utf8mb4_unicode_ci - Update my.cnf/my.ini:
Next Steps
Environment Setup
Configure environment variables
Deployment
Deploy to production