spatie/db-dumper
PHP library to create database dumps via native CLI tools. Supports MySQL, MariaDB, PostgreSQL, SQLite, and MongoDB, wrapping mysqldump/mariadb-dump/pg_dump/sqlite3/mongodump with a simple fluent API.
Pros:
setDbName(), skipAutoIncrement(), etc.) integrate seamlessly with Laravel’s fluent query builder patterns, reducing cognitive load for developers..env configuration (via setDatabaseUrl()) and service container, enabling dependency injection and configuration management.Cons:
mysqldump, pg_dump, etc.), introducing OS-level dependencies and potential security risks (e.g., command injection if not sanitized).dumping:start, dumping:completed), which could be useful for logging, notifications, or pre/post-processing.config/database.php structure (e.g., DB_CONNECTION, DB_DATABASE).php artisan db:dump) for CLI-driven workflows.DatabaseMigrations, RefreshDatabase) by providing controlled dump/restore cycles.php artisan db:dump --env=testing).DatabaseUrl or environment variables.escapeshellarg() or process builders). The package abstracts this but requires validation.mongodump may behave differently in production vs. development (e.g., oplog size, sharding).--single-transaction (MySQL) or pg_dump --jobs (PostgreSQL).column_statistics or require --skip-lock-tables.pg_dump) may need path adjustments on Windows.includeTables(), excludeTablesData(), or doNotCreateTables().--column-statistics=0.)mysqldump/pg_dump across environments?setDatabaseUrl() suffice, or is a dedicated secrets manager needed?filesystem disk.AppServiceProvider for global access:
$this->app->singleton(Dumper::class, function ($app) {
return MySql::create()
->setDatabaseUrl(env('DATABASE_URL'))
->setDumpBinaryPath(config('database.dump_binary_path'));
});
config/db-dumper.php for centralized settings:
return [
'binary_paths' => [
'mysql' => '/usr/local/bin/mysqldump',
'postgres' => '/usr/local/bin/pg_dump',
],
'compression' => 'gzip',
'default_options' => [
'mysql' => ['--skip-triggers'],
'postgres' => ['--no-owner'],
],
];
php artisan make:command DbDumpCommand
public function handle() {
$dumper = app(Dumper::class);
$dumper->dumpToFile(storage_path('app/dump.sql'));
}
DbDumpJob::dispatch($databaseName, $outputPath)
->onConnection('database-backups');
shouldQueue() and handle() with progress tracking.doNotDumpData()) for testing.mysqldump scripts with the package’s fluent API.setDatabaseUrl() for Laravel’s .env compatibility.mongodump is installed and accessible. Test with --oplog for replication.spatie/db-dumper supports PHP 7.4+.mysqldump, pg_dump) are in the container’s PATH.C:\Program Files\MySQL\mysql-8.0\bin\mysqldump).mysqldump, cron jobs).php artisan db:restore).How can I help you explore Laravel packages today?