UNPKG

pg-anon

Version:

CLI to anonymize PostgreSQL data using Faker.js or Falso

58 lines (42 loc) 1.45 kB
# pg-anon CLI to anonymize PostgreSQL data using Faker.js or Falso. A configuration file-driven tool to iterate over the rows in tables in a PostgreSQL database, replacing specified columns with random / anonymized values generated by [Faker](https://fakerjs.dev), [Falso](https://ngneat.github.io/falso/) or any a custom function (so basically any tool). It runs in batches—by default of 100 rows—and commits after each batch. You can disable batching by setting the batch size to 0 in the config. The seed capabilities of Faker and Falso are used so that the generated values are stable for each row and column. ## Config See [pg-anon.config.js](./pg-anon.config.js) for an example config file. `pg-anon` looks for this file in your current working directory. See [types.ts](./src/types.ts) for the type-definition of the config file, and documentation of the properties. Here's a very basic example to whet your appetite: ```javascript /** * @type {import('pg-anon').PgAnonConfig} */ const config = { connectionString: 'postgres://user:password@host:port/database', tables: [ { name: 'table1', idColumn: 'id', columns: { name: { faker: 'person.fullName', }, } }, ], } export default config ``` ## Usage To run `pg-anon` using a `pg-anon.config.js` in your current working directory: ```shell npx pg-anon ``` Or to specify the path to the config file: ```shell npx pg-anon <path to config file> ```