Looking to hire Laravel developers? Try LaraJobs

laravel-staging-sync maintained by n02srt

Description
A Laravel package to automatically sync staging databases with production, including data anonymization.
Last update
2025/04/25 19:05 (dev-main)
License
Links
Downloads
1

Comments
comments powered by Disqus

Laravel Staging Sync

A Laravel package that keeps your staging database in sync with production, safely and selectively. Useful for automated QA environments, pre-release testing, and reducing the overhead of managing up-to-date test data.


🚀 Features

  • Sync data from production to staging
  • Select specific tables to sync or use --all to sync everything
  • Exclude or obfuscate sensitive columns
  • Truncate staging tables before syncing
  • Dry-run mode for safe simulation
  • Batch processing to handle large tables
  • Console command for manual or scheduled syncs

📦 Installation

composer require n02srt/laravel-staging-sync
php artisan vendor:publish --tag=staging-sync-config

⚙️ Configuration

Edit the published config file at config/staging-sync.php:

return [
    'tables' => [
        'users' => [
            'exclude_columns' => ['password', 'email'],
            'obfuscate' => ['email'],
        ],
        'orders',
        'products',
    ],
    'batch_size' => 500,
    'truncate_before_insert' => true,
    'dry_run' => false,
];

Define source/target connections in your .env file:

STAGING_SYNC_SOURCE_DB_CONNECTION=production
STAGING_SYNC_TARGET_DB_CONNECTION=staging

🛠 Usage

Run the Sync

php artisan staging:sync

Options

  • --dry-run — Simulate syncing without writing to the staging DB
  • --all — Sync all tables from the source DB, except those in exclude_tables

Examples

php artisan staging:sync --dry-run
php artisan staging:sync --all

🧪 Advanced Use

Scheduling

Add the command to your App\Console\Kernel.php:

$schedule->command('staging:sync --all')->dailyAt('02:00');

Obfuscation

To protect sensitive data in staging, configure fields under obfuscate. Emails and similar fields will be replaced with hashed dummy values.


🧱 Package Structure

  • src/StagingSyncServiceProvider.php — Service provider
  • src/Console/SyncStagingCommand.php — Artisan command
  • config/staging-sync.php — Configuration file

✅ Roadmap

  • ✅ Initial release with config + Artisan support
  • ✅ --all support for syncing all tables
  • ⏳ Web interface (Filament/Nova)
  • ⏳ Slack/email notifications
  • ⏳ Queue integration for async syncing

🧑‍💻 License

MIT License — free to use, modify, and distribute.


Made with ❤️ to make staging feel less like guesswork.