marwa-framework

Database Management (DBForge)

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.

Quick Reference

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

Usage

Create a Database

php marwa db:create myapp

# Use a named connection
php marwa db:create myapp --connection=reporting

List Databases or Tables

# 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

Backup Database

# 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

Restore from Backup

php marwa db:restore backup.sql

php marwa db:restore backup.sql --connection=reporting

Optimize Tables

php marwa db:optimize

Analyze Tables

php marwa db:analyze

Drop a Database

php marwa db:drop myapp --force

Programmatic Usage

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();

Supported Drivers

Notes