Skip to content

Add anonymization support with --anonymize flag #29

Merged
dcblogdev merged 1 commit into
mainfrom
add-ability-to-anonymize-data
Mar 16, 2026
Merged

Add anonymization support with --anonymize flag #29
dcblogdev merged 1 commit into
mainfrom
add-ability-to-anonymize-data

Conversation

@dcblogdev
Copy link
Copy Markdown
Owner

  1. Configuration (config/dbsync.php)
    Added anonymize config array with examples showing how to map tables and columns to Faker methods
    Supports special syntax like bcrypt:password for hashed passwords

  2. Command Flag (src/Console/DbSyncCommand.php)
    Added --anonymize (or -A) flag to the command signature
    Feature is off by default (opt-in only)

  3. Anonymization Logic (src/Console/DbSyncCommand.php)
    New anonymizeData() method processes configured tables after import
    Uses Laravel's Faker library for realistic fake data
    Progress bar shows which table is being anonymized
    Error handling for each table (continues if one fails)
    Updates records individually to ensure proper data generation

Usage Example

// In config/dbsync.php
'anonymize' => [
    'users' => [
        'email' => 'safeEmail',
        'name' => 'name',
        'phone' => 'phoneNumber',
        'password' => 'bcrypt:password',
    ],
    'customers' => [
        'email' => 'safeEmail',
        'first_name' => 'firstName',
        'last_name' => 'lastName',
    ],
],
# Sync with anonymization
php artisan db:production-sync --anonymize

# Or use shorthand
php artisan db:production-sync -A

@dcblogdev dcblogdev merged commit 6d10075 into main Mar 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant