The framework includes DBForge for database-level operations. DBForge complements marwa-db by providing commands for managing databases, backups, and optimization.
Database commands accept a --connection option so you can target a non-default connection when your app defines more than one database config.
| Command | Description |
|---|---|
db:create <name> [--connection=...] |
Create a new database |
db:drop <name> [--connection=...] |
Drop a database |
db:list [--tables] [--connection=...] |
List databases or tables |
db:backup [--path=...] [--connection=...] |
Backup database to file |
db:restore <path> [--connection=...] |
Restore from backup file |
db:optimize [--connection=...] |
Optimize all tables |
db:analyze [--connection=...] |
Analyze all tables |
php marwa db:create myapp
# Use a named connection
php marwa db:create myapp --connection=reporting
# List databases
php marwa db:list
# List tables in current database
php marwa db:list --tables
# Inspect a named connection
php marwa db:list --connection=reporting
# Default: saves to database/backups/backup_YYYYMMDD_HHMMSS.sql
php marwa db:backup
# Custom path
php marwa db:backup --path=/path/to/backup.sql
# Target a named connection
php marwa db:backup --connection=reporting
php marwa db:restore backup.sql
php marwa db:restore backup.sql --connection=reporting
php marwa db:optimize
OPTIMIZE TABLE on all tablesVACUUMVACUUMphp marwa db:analyze
ANALYZE TABLE on all tablesANALYZEphp marwa db:drop myapp --force
use Marwa\Framework\Facades\DatabaseForge;
// Create database
DatabaseForge::createDatabase('myapp');
// List tables
$tables = DatabaseForge::listTables();
// Backup to file
DatabaseForge::backup('/path/to/backup.sql');
// Optimize
DatabaseForge::optimize();
mysqldump for MySQL and pg_dump for PostgreSQL (must be installed)config/database.php