n02srt / laravel-staging-sync
A Laravel package to automatically sync staging databases with production, including data anonymization.
Requires
- php: ^8.0
- illuminate/database: ^8.0|^9.0|^10.0
- illuminate/support: ^8.0|^9.0|^10.0
This package is auto-updated.
Last update: 2025-05-25 17:17:45 UTC
README
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 inexclude_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 providersrc/Console/SyncStagingCommand.php
โ Artisan commandconfig/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.