定制 n02srt/laravel-staging-sync 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-25