inigopascall/clone-db
Laravel artisan command to clone medium/large MySQL databases between connections. Chunks data to avoid memory/packet limits and orders tables by foreign-key dependencies to reduce constraint errors—useful for syncing live data to staging/dev.
php artisan clone-db).config/database.php).database.cloned) or scheduler (e.g., schedule:run).| Risk | Mitigation |
|---|---|
| Foreign Key Loops | Package explicitly disallows mutually dependent tables (e.g., circular FKs). Workaround: Pre-process schema or use --ignore-errors. |
| Performance Bottlenecks | Batch size (--chunk) must be tuned per DB size. Test with --dry-run first. |
| Data Truncation | Large TEXT/BLOB fields may fail. Filter tables or use --exclude-tables. |
| Transaction Safety | No ACID guarantees across batches. Wrap in transactions if critical (requires custom logic). |
| Schema Mismatches | Target DB must have identical schema (or compatible). Validate schema first (e.g., php artisan schema:diff). |
--chunk=500 for 10M+ rows.)users ↔ user_roles)? If yes, how will you handle them?memory_limit in php.ini if needed.)--soft-deletes flag if supported.)git push to staging.)DatabaseCloned event post-clone.composer require inigopascall/clone-db.config/database.php (or publish config with php artisan vendor:publish).--dry-run:
php artisan clone-db --source=live_db --target=staging_db --dry-run
--chunk if slow).// app/Console/Kernel.php
$schedule->command('clone-db --source=prod --target=staging')->daily();
Route::post('/clone-db', function () {
Artisan::call('clone-db', ['--source' => 'live', '--target' => 'dev']);
});
| Component | Compatibility | Workaround |
|---|---|---|
| Laravel Version | 8.x, 9.x, 10.x (untested on 7.x) | Downgrade or fork package. |
| PHP Version | 8.0+ (PHP 7.x may fail due to typed properties) | Upgrade PHP or patch package. |
| MySQL Version | 5.7+, 8.0+ (tested) | Use --skip-foreign-keys if unsupported. |
| Schema Differences | Target DB must match source schema (columns, types, constraints) | Use php artisan migrate post-clone if needed. |
| Custom Data Types | ENUM, SET, or custom types may fail |
Cast to strings or pre-process data. |
| Stored Procedures | Not cloned (package focuses on tables) | Script separately or exclude. |
mysqldump --single-transaction live_db > backup.sql.php artisan schema:dump).SELECT on source, INSERT/UPDATE on target.categories, users).--chunk=1000, adjust based on memory.logs or sessions tables if irrelevant:
php artisan clone-db --exclude-tables=logs,sessions
UPDATE users SET email = REPLACE(email, '@', '[REDACTED]@')).REINDEX TABLE table_name.php artisan cache:clear) and warm queues.--chunk, --exclude-tables, and --ignore-errors in config/clone-db.php.staging vs. dev).composer.json to avoid breaking changes:
"inigopascall/clone-db": "dev-main"
APP_DEBUG=true) and check storage/logs/laravel.log.--ignore-errors to identify problematic tables.max_execution_time in php.ini or split into smaller batches.--chunk=500 and monitor php -r "echo memory_get_usage();".[laravel] clone-db).How can I help you explore Laravel packages today?