Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support to specify tables in list of columns #13

Merged
merged 4 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ Specifying another list via `--list` replace the default automatically anonymize
email,name,description,address,city,country,phone,comment,birthdate
```

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

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

#### Customize replacements

You can also choose which faker function you want to use to replace data (default is `faker.random.word`):
Expand Down Expand Up @@ -70,10 +76,6 @@ module.exports = {
};
```

### Memory limit

Use `-m` to change `pg_dump` output memory limit (e.g: `512`)

rap2hpoutre marked this conversation as resolved.
Show resolved Hide resolved
### Locale (i18n)

Use `-l` to change the locale used by faker (default: `en`)
Expand Down
14 changes: 10 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class PgAnonymizer extends Command {
}),
pgDumpOutputMemory: flags.string({
char: "m",
description: "max memory used to get output from pg_dump in MB",
default: "256",
description: "Obsolete, not needed any more: max memory used to get output from pg_dump in MB",
default: "0",
}),
};

Expand Down Expand Up @@ -112,7 +112,8 @@ class PgAnonymizer extends Command {
.map((e) => e.toLowerCase());

indices = cols.reduce((acc: Number[], value, key) => {
if (list.find((l) => l.col === value)) acc.push(key);
if (list.find((l) => l.col === value)) acc.push(key)
else if (list.find((l) => l.col === table + '.' + value)) acc.push(key);
return acc;
}, []);

Expand All @@ -127,9 +128,14 @@ class PgAnonymizer extends Command {
.split("\t")
.map((v, k) => {
if (indices.includes(k)) {
const replacement = list.find(
let replacement = list.find(
(l) => l.col === cols[k]
)?.replacement;
if (!replacement) {
replacement = list.find(
(l) => l.col === table + '.' + cols[k]
)?.replacement;
}
if (replacement) {
if (replacement.startsWith("faker.")) {
const [_one, two, three] = replacement.split(".");
Expand Down