• Stars
    star
    154
  • Rank 242,095 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dump anonymized PostgreSQL database with a NodeJS CLI

pg-anonymizer

Export your PostgreSQL database anonymized. Replace all sensitive data thanks to faker. Output to a file that you can easily import with psql.

oclif Version Downloads License

Usage

Run this command by giving a connexion string and an output file name (no need to install first thanks to npx):

npx pg-anonymizer postgres://user:secret@localhost:1234/mydb -o dump.sql

โ˜๏ธ This command requires pg_dump. It may already be installed as soon as PostgreSQL is installed.

Output can also be stdout ('-') so you can pipe the output to zip, gz, or to psql:

npx pg-anonymizer postgres://user:secret@localhost:1234/mydb -o - | psql DATABASE_URL

Specify list of columns to anonymize

Use --list option with a comma separated list of column name:

npx pg-anonymizer postgres://localhost/mydb \
  --list=email,firstName,lastName,phone

Specifying another list via --list replace the default automatically anonymized values:

email,name,description,address,city,country,phone,comment,birthdate

You can also specify the table for a column using the dot notation:

public.user.email,public.product.description,email,name

Alternatively use --configFile option to specify a file with a list of column names and optional replacements, one per line:

npx pg-anonymizer postgres://localhost/mydb \
  --configFile /path/to/file

Customize replacements

You can also choose which faker function you want to use to replace data (default is faker.random.word):

npx pg-anonymizer postgres://localhost/mydb \
  --list=firstName:faker.name.firstName,lastName:faker.name.lastName

๐Ÿ‘‰ You don't need to specify faker function since the command will try to find correct function via column name.

You can use plain text too for static replacements:

npx pg-anonymizer postgres://localhost/mydb \
  --list=textcol:hello,jsoncol:{},intcol:12

You can even use your custom replacements function from your own javascript module. Here is a simple example to mask all the email.

npx pg-anonymizer postgres://localhost/mydb \
  --extension ./myExtension.js \
  --list=email:extension.maskEmail
// myExtension.js
module.exports = {
  maskEmail: (email) => {
   const [name, domain] = email.split('@');
   const { length: len } = name;
   const maskedName = name[0] + '...' + name[len - 1];
   const maskedEmail = maskedName + '@' + domain;
   return maskedEmail;
  }
};

Skip tables

Use --skip to skip anonymizing entire tables

npx pg-anonymizer postgres://localhost/mydb --skip public.posts

Ignore NULL values

Use --preserve-null|-n to skip anonymization on fields with NULL values.

npx pg-anonymizer postgres://localhost/mydb --preserve-null

Locale (i18n)

Use -l to change the locale used by faker (default: en)

Import the anonymized file

The anonymized output file is plain SQL text, you can import it with psql.

psql -d mylocaldb < output.sql

Why

There are a bunch of competitors, still I failed to use them:

  • postgresql_anonymizer may be hard to setup and may be cumbersome for simple usage. Still, I guess it's the best solution.
  • pganonymize fails when it does not use public schema or columns have uppercase characters
  • pganonymizer also fails with simple cases. Errors are not explicit and silent.

More Repositories

1

laravel-log-viewer

๐Ÿช Laravel log viewer
PHP
3,041
star
2

fast-excel

๐Ÿฆ‰ Fast Excel import/export for Laravel
PHP
1,784
star
3

vue-picture-swipe

๐Ÿ–ผ Vue Picture Swipe Gallery (a gallery of image with thumbnails, lazy-load and swipe) backed by photoswipe
Vue
383
star
4

similar-text-finder

๐Ÿ PHP Similar Text Finder aka Fuzzy search. `Did you mean "banana"?`
PHP
132
star
5

laravel-stripe-connect

๐Ÿฆ“ Stripe Connect binding for Laravel
PHP
73
star
6

mysql-xplain-xplain

๐Ÿญ Explain Explainer for MySQL Queries.
PHP
53
star
7

laravel-epilog

๐Ÿˆ IP, referer, user ID and more in Laravel logs
PHP
25
star
8

taskz

๐Ÿก Sequential and parallel task list runner for terminal
JavaScript
23
star
9

laravel-prod-server

Install and run a production server for a Laravel application
22
star
10

create-user-command

๐Ÿฆ€ Create User with artisan
PHP
21
star
11

vue-quiz

Create a quiz withย Vue.js
HTML
20
star
12

laravel-credit-card-validator

๐Ÿฅ Laravel Credit Card Validator
PHP
19
star
13

landscape

Procedural landscape
Rust
17
star
14

jacky

๐Ÿ„ HTTP JSON API Client for Laravel & Lumen
PHP
17
star
15

llamassacre

Uncommented-spaghettiesque-dirty code. RUN AWAY.
Rust
15
star
16

remove-stop-words

Remove stop words from a string
PHP
15
star
17

htmltopdf

html to pdf website using wkhtmltopdf
Rust
9
star
18

vue-calendar

HTML
8
star
19

mongodb-anonymizer

Anonymize MongoDB database with a NodeJS CLI
TypeScript
8
star
20

uuid-rule

UUID validation rule for Laravel
PHP
7
star
21

mongodb-elasticsearch-sync

Copy data from MongoDB to Elasticsearch with a NodeJS CLI
TypeScript
6
star
22

voltaire

Proof-reading tool for PHP (spell checker, grammar fixer using LanguageTool)
PHP
6
star
23

facteur

Laravel deployer
Rust
4
star
24

nestor

๐Ÿน Do task, rollback if something goes wrong. Just like database transactions.
PHP
4
star
25

convert-accent-characters

Converts all UTF-8 accent characters to ASCII characters
PHP
4
star
26

midikaos

๐ŸŽท Standard MIDI Files Library website
TypeScript
3
star
27

glitcher-web

๐ŸŽต WAV glitcher, generate broken beats from sample loops
TypeScript
3
star
28

csv-to-associative-array

Get your CSV as an associative array
PHP
3
star
29

ortf

Statistiques de /r/france
TypeScript
2
star
30

react-fairy-tale-emoji

JavaScript
2
star
31

fuzzy-dubstep

Jeu HTML5/JS avec Quintus (+PHP pour generation) : simulation de prรฉparation de mariage
PHP
2
star
32

mynia

Unicorn name generator
Rust
1
star
33

drum-loop-glitcher-sonic-pi

work in progress
Ruby
1
star
34

find-the-cat

Find and click the cat.
JavaScript
1
star
35

indice

Hints for Laravel errors
Blade
1
star
36

420-bot

PHP
1
star
37

create-elasticsearch-dataset

Create a sample dataset for Elasticsearch with one command
TypeScript
1
star
38

drum-beats

Procedural Drum Beats website
Rust
1
star
39

starfield

Rust
1
star