n02srt/laravel-staging-sync

A Laravel package to automatically sync staging databases with production, including data anonymization.

dev-main 2025-04-25 17:05 UTC

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