n02srt/laravel-staging-sync
Composer 安装命令:
composer require n02srt/laravel-staging-sync
包简介
A Laravel package to automatically sync staging databases with production, including data anonymization.
README 文档
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
--allto 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
- ✅
--allsupport 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.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-25