Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Clone Db Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The package excels at non-destructive, dependency-aware database cloning—ideal for Laravel applications requiring realistic staging/dev environments (e.g., e-commerce, SaaS, or analytics platforms with medium/large DBs).
  • Laravel Native: Leverages Laravel’s Artisan command system, making it a seamless fit for Laravel-centric workflows (e.g., php artisan clone-db).
  • Foreign Key Handling: Automatically resolves table dependencies (parent-child relationships) to prevent constraint errors, critical for complex schemas (e.g., ERP, CMS, or multi-table applications).
  • Memory Efficiency: Mitigates PHP/MySQL memory limits via batch inserts (configurable chunk sizes), addressing a common pain point in CI/CD pipelines or local dev setups.

Integration Feasibility

  • Minimal Boilerplate: Requires zero custom code for basic use (just config + Artisan command). Extensible via service providers or custom commands for advanced scenarios.
  • Database Agnostic: Supports MySQL/MariaDB (via PDO) but lacks explicit support for PostgreSQL/SQLite. Risk: May need wrapper logic for non-MySQL DBs.
  • Laravel Ecosystem Synergy:
    • Integrates with Laravel’s database configuration (config/database.php).
    • Can be triggered via Laravel events (e.g., database.cloned) or scheduler (e.g., schedule:run).
    • Compatible with Laravel Forge/Vapor for cloud deployments.

Technical Risk

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).

Key Questions

  1. Database Size/Complexity:
    • What’s the largest table and total DB size? (Package targets "medium-size"; test with --chunk=500 for 10M+ rows.)
    • Are there mutually dependent tables (e.g., usersuser_roles)? If yes, how will you handle them?
  2. Environment Constraints:
    • What’s the PHP/MySQL memory limit? (Adjust memory_limit in php.ini if needed.)
    • Is the target DB writable? (Package requires full permissions.)
  3. Data Sensitivity:
    • Does the clone need masking (e.g., PII)? (Package doesn’t support this; consider post-clone scripts.)
    • Are there soft-deleted records in Eloquent? (Package clones raw data; use --soft-deletes flag if supported.)
  4. CI/CD Integration:
    • How will this fit into deployment pipelines? (Example: Trigger on git push to staging.)
    • Do you need rollback capability? (Package is destructive; backup target DB first.)

Integration Approach

Stack Fit

  • Laravel Core: Native Artisan integration requires Laravel 8+ (composer autoloading).
  • Database Layer:
    • Primary: MySQL/MariaDB (tested).
    • Secondary: PostgreSQL/SQLite (untested; may need PDO adapters or custom queries).
  • Dependencies:
    • PDO (for DB connectivity).
    • Laravel’s DB Facade (for config resolution).
  • Extensions:
    • Laravel Events: Dispatch DatabaseCloned event post-clone.
    • Laravel Scout: Rebuild indexes if using full-text search.
    • Laravel Cashier: Sync subscriptions if cloning SaaS data.

Migration Path

  1. Pilot Phase:
    • Install package: composer require inigopascall/clone-db.
    • Configure in config/database.php (or publish config with php artisan vendor:publish).
    • Test with --dry-run:
      php artisan clone-db --source=live_db --target=staging_db --dry-run
      
  2. Validation:
    • Verify data integrity (count rows in critical tables).
    • Check foreign keys (no constraint errors).
    • Benchmark execution time (adjust --chunk if slow).
  3. Automation:
    • Option 1: Manual trigger via CLI.
    • Option 2: Laravel Scheduler (e.g., nightly sync):
      // app/Console/Kernel.php
      $schedule->command('clone-db --source=prod --target=staging')->daily();
      
    • Option 3: API endpoint (for on-demand cloning):
      Route::post('/clone-db', function () {
          Artisan::call('clone-db', ['--source' => 'live', '--target' => 'dev']);
      });
      

Compatibility

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.

Sequencing

  1. Pre-Clone:
    • Backup: mysqldump --single-transaction live_db > backup.sql.
    • Schema Sync: Ensure target DB schema matches source (use php artisan schema:dump).
    • Permissions: Grant SELECT on source, INSERT/UPDATE on target.
  2. Clone Execution:
    • Order: Clone reference tables first (e.g., categories, users).
    • Batch Size: Start with --chunk=1000, adjust based on memory.
    • Exclusions: Skip large logs or sessions tables if irrelevant:
      php artisan clone-db --exclude-tables=logs,sessions
      
  3. Post-Clone:
    • Data Masking: Run scripts to anonymize PII (e.g., UPDATE users SET email = REPLACE(email, '@', '[REDACTED]@')).
    • Index Rebuild: For PostgreSQL, run REINDEX TABLE table_name.
    • Cache Warmup: Clear Laravel cache (php artisan cache:clear) and warm queues.

Operational Impact

Maintenance

  • Package Updates:
    • Monitor for new releases (currently 0.6 score; low activity).
    • Fork if critical: Customize for PostgreSQL or add masking features.
  • Configuration Drift:
    • Track --chunk, --exclude-tables, and --ignore-errors in config/clone-db.php.
    • Document environment-specific overrides (e.g., staging vs. dev).
  • Dependency Management:
    • Pin version in composer.json to avoid breaking changes:
      "inigopascall/clone-db": "dev-main"
      

Support

  • Troubleshooting:
    • Logs: Enable Laravel debugging (APP_DEBUG=true) and check storage/logs/laravel.log.
    • Common Issues:
      • Foreign Key Errors: Run with --ignore-errors to identify problematic tables.
      • Timeouts: Increase max_execution_time in php.ini or split into smaller batches.
      • Memory Issues: Use --chunk=500 and monitor php -r "echo memory_get_usage();".
    • Community: Limited (0 stars); rely on GitHub issues or Stack Overflow ([laravel] clone-db).
  • SLA Impact:
    • **Downtime
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager