pittacusw / database
Generate Laravel seeders from existing MySQL tables and backup or restore database tables
Requires
- php: ^8.0.2
- laravel/framework: ^9.26|^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- mockery/mockery: ^1.6
- phpunit/phpunit: ^8.5|^9.6|^10.5|^11.5
README
pittacusw/database is a Laravel package for:
- generating seeders from existing table data
- exporting each MySQL table to a gzipped SQL dump
- restoring SQL dump files back into a MySQL database
The package is intended for Laravel applications and targets Laravel 9.x through 13.x.
Requirements
- PHP
^8.0.2 - Laravel
^9.26|^10.0|^11.0|^12.0|^13.0 - MySQL client binaries available on the host machine for
db:backupanddb:restoremysqldumpmysql
Installation
composer require pittacusw/database
Laravel package discovery will register the service provider and the Iseed facade automatically.
Commands
php artisan iseed
Generate seeders from one or more tables.
php artisan iseed users php artisan iseed users,posts --force php artisan iseed users --exclude=password,remember_token --orderby=id --direction=DESC php artisan iseed audit_logs --max=1000 --chunksize=250 --dumpauto=0
Important options:
--force: overwrite existing seed files without confirmation--clean: clear the managed#iseedsection insidedatabase/seeders/DatabaseSeeder.php--database=: choose a Laravel database connection--max=: limit exported rows--chunksize=: split inserts into smaller batches--exclude=: omit comma-separated columns--noindex: remove numeric indexes from exported arrays--classnameprefix=and--classnamesuffix=: customize the generated seeder class name
Generated files are written to database/seeders.
php artisan db:iseed
Generate seeders for all tables except a small built-in ignore list:
migrationspassword_resetsfailed_jobsgithub_webhook_callsjobs
Examples:
php artisan db:iseed php artisan db:iseed users php artisan db:iseed --database=legacy --chunksize=100
php artisan db:backup
Create a gzipped SQL dump per table in database/sql by default.
php artisan db:backup
php artisan db:backup --database=legacy --path=storage/backups/sql
php artisan db:backup --mysqldump-binary="C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump.exe"
Notes:
- this command is MySQL-only
- dumps are executed through
mysqldumpusing Symfony Process, not through a shell string - output files are created as
*.sql.gz - one file is generated per table
- dump output is streamed directly into gzip files, so large tables are not buffered fully in PHP memory
- the database password is passed through
MYSQL_PWDinstead of a--password=CLI argument - the command uses
--single-transaction,--quick,--skip-lock-tables, and--hex-blob --gzip-level=accepts values from0to9and defaults to6
php artisan db:restore
Restore .sql and .sql.gz files from database/sql by default.
php artisan db:restore
php artisan db:restore --database=legacy --path=storage/backups/sql
php artisan db:restore --mysql-binary="C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe"
Notes:
- this command is MySQL-only
- files are restored in filename order
- SQL input is wrapped with
SET FOREIGN_KEY_CHECKS=0/1for safer restores .sqland.sql.gzfiles are streamed intomysql, so restore does not fully decompress a backup into memory first--chunk-size=controls the per-read streaming size and defaults to1048576bytes
DatabaseSeeder markers
If you want iseed to manage a dedicated section inside DatabaseSeeder, add markers like this:
public function run() { #iseed_start #iseed_end }
When the markers are present, generated seeders are inserted between them. Otherwise the package appends the seeder call inside run().
Compatibility notes
- The package assumes Laravel's standard
database/seederspath. - Seeder generation works through Laravel's database connection layer.
- Backup and restore commands require a MySQL connection configured in
config/database.php. - On Windows and Linux, the MySQL client binaries only need to be available on
PATH, or you can pass explicit paths with--mysqldump-binaryand--mysql-binary.
Testing
vendor/bin/phpunit