Skip to content

Commit

Permalink
feat(test): add more testing tool and fix common errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jegj committed Aug 12, 2022
1 parent e5452ae commit b2241d9
Show file tree
Hide file tree
Showing 10 changed files with 21,252 additions and 18,411 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = tab
indent_style = space
indent_size = 2

[{vagrant}/**.{yml}]
Expand All @@ -18,7 +18,7 @@ indent_size = 2

; Choose between lf or rf on "end_of_line" property
[*]
indent_style = tab
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
Expand Down
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

42 changes: 2 additions & 40 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"plugins": [],
"extends": [
"eslint:recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"indent": [
"error",
"tab",
{
"SwitchCase": 1
}
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single",
{
"allowTemplateLiterals": true
}
],
"semi": [
"error",
"always"
]
}
"root": true,
"extends": "standard"
}
23 changes: 23 additions & 0 deletions .markdownlint-cli2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://github.com/DavidAnson/markdownlint-cli2
config:
# Disable all rules by default.
default: false

# Enforce line length.
MD013:
line_length: 80
code_block_line_length: 120
headers: false
tables: false
strict: false
stern: false

globs:
- '**/*.md'

ignores:
- 'node_modules/**'
- 'test/**/*.md'
- 'CHANGELOG.md'

noProgress: true
41 changes: 33 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
# pgfilter

CLI to filter or transform data during the restoration process for Postgres databases.
It uses a JSON file to define which tables and columns should be anonymized or filtered with various methods, protecting your sensitive data and making a skinny version of your database for third-party resources involved in your development/QA process.
It uses a JSON file to define which tables and columns should be anonymized or
filtered with various methods, protecting your sensitive data and making a
skinny version of your database for third-party resources involved in your
development/QA process.

## Installation
```bash
Expand Down Expand Up @@ -47,10 +50,16 @@ Options:
-v, --verbose Show debug messages in STDERR [boolean]
```

__NOTE__ For more information about `--buffer-length` and `--skip-overflow` check [Considerations section](#considerations)
__NOTE__ For more information about `--buffer-length` and `--skip-overflow`
check [Considerations section](#considerations)
## pgfilter-file

A JSON file that you must define based on the tables and rows that you want to filter or transform. Keys represent table names and the subdocument represent the target columns on the table, each column must have a [filtering/transformation function](./docs/Functions.md) as value. The function determine what kind of filtering or transformation will be applied to the column.
A JSON file that you must define based on the tables and rows that you want to filter
or transform.Keys represent table names and the subdocument represent the
target columns on the table, each column must have
a [filtering/transformation function](./docs/Functions.md) as value.
The function determine what kind of filtering or transformation
will be applied to the column.

```json
{
Expand Down Expand Up @@ -85,7 +94,9 @@ CREATE TABLE public.requests (
);
```

To transform or anonymize the columns `name`,`lastname`,`addr1`, `email` on table `users` and filter the table `requests` to keep only requests in the last 60 days, the pgfilter-file will be the following:
To transform or anonymize the columns `name`,`lastname`,`addr1`, `email`
on table `users` and filter the table `requests` to keep only requests in
the last 60 days, the pgfilter-file will be the following:

```javascript
// myconfig.json
Expand All @@ -107,7 +118,8 @@ pgfilter -f myconfig.json mybackup.dump > mybackup.transformed.dump
```
## Filtering/Transformation builtin functions

Go to section [Filtering/Transformation builtin functions](./docs/Functions.md) for more information.
Go to section [Filtering/Transformation builtin functions](./docs/Functions.md)
for more information.
## Common Usage

- Anonymized a backup file
Expand Down Expand Up @@ -160,15 +172,28 @@ Go to section [Filtering/Transformation builtin functions](./docs/Functions.md)
```
## Considerations

* `pgfilter` use internal streams buffers to store partial data from the backup. By default, there is no limit, but you can use `--skip-overflow` and `--buffer-length` options to set limitations to the internal buffer. This behavior is inherent due to [split2 npm package](https://www.npmjs.com/package/split2) which is used internally to detect lines in the stream for analysis. These combinations of options is useful when there are tables with bytea or really long text columns. This will speed up the process on this scenario but also may cause data lose, **use with caution**.
* `pgfilter` use internal streams buffers to store partial data from the backup.
By default, there is no limit, but you can use `--skip-overflow`
and `--buffer-length` options to set limitations to the internal buffer.
This behavior is inherent due to [split2 npm package](https://www.npmjs.com/package/split2)
which is used internally to detect lines in the stream for analysis.
These combinations of options is useful when there are tables
with bytea or really long text columns. This will speed up the process
on this scenario but also may cause data lose, **use with caution**.

* Your databases must be normalized to maintain relation between tables.

## Why

- There are several competitors ( [PostgreSQL Anonymizer](https://postgresql-anonymizer.readthedocs.io/en/stable/), [pgantomizer](https://github.com/asgeirrr/pgantomizer),...etc) but we have not found one that let you filter information.
- There are several competitors (
[PostgreSQL Anonymizer](https://postgresql-anonymizer.readthedocs.io/en/stable/),
[pgantomizer](https://github.com/asgeirrr/pgantomizer),...etc
) but we have not found one that let you filter information.

- Most of them requires a direct connection to the databases which is very helpful for remote databases but pgfilter's focus is to use the local tooling like `pgdump` or `pg_restore` and use Linux amazing piping features
- Most of them requires a direct connection to the databases which is very helpful
for remote databases but pgfilter's focus is to use the
local tooling like `pgdump` or `pg_restore` and
use Linux amazing piping features

## Development

Expand Down
5 changes: 4 additions & 1 deletion docs/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ Replace the current value of the column by an empty array
#### filter
##### `pgfilter.filter.fnow-<dur>`

Evaluate the column value against the `dur` argument. If column value match the duration, the row is allowed to restore. Otherwise, the whole row is ignored and won't be included in the restore.
Evaluate the column value against the `dur` argument.
If column value match the duration, the row is allowed
to restore. Otherwise, the whole row is ignored and
won't be included in the restore.

- Column type: `timestamp`

Expand Down
194 changes: 0 additions & 194 deletions jest.config.js

This file was deleted.

Loading

0 comments on commit b2241d9

Please sign in to comment.