-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgfilter.js
executable file
·52 lines (49 loc) · 1.88 KB
/
pgfilter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
import yargs from 'yargs/yargs'
import { hideBin } from 'yargs/helpers'
import input from './lib/input.js'
import { validJSONFile, validBackupFile, validBuffer } from './lib/utils.js'
const pgfilter = yargs(hideBin(process.argv))
.scriptName('pgfilter')
.env('PGFILTER')
.version()
.option('f', {
alias: 'file',
describe: 'Path to the filtering/transformation JSON file. env: PGFILTER_FILE',
type: 'string',
demandOption: true,
normalize: true,
coerce: (f) => validJSONFile(f, 'file')
})
.option('b', {
alias: 'buffer-length',
describe: 'Set internal stream transformation buffer size. There is no limit by default. If set, process will throw an error as soon the buffer exceed the limit. Use --skip to avoid exit the whole process. env: PGFILTER_BUFFER_LENGTH',
type: 'number',
default: undefined,
coerce: (b) => validBuffer(b, 'buffer')
})
.option('s', {
alias: 'skip-overflow',
describe: 'If set, the line that exceed the internal buffer will be ignored and the process will not exit. env: PGFILTER_SKIP_OVERFLOW',
type: 'boolean',
default: false
})
.option('v', {
alias: 'verbose',
describe: 'Show debug messages in STDERR',
type: 'boolean',
default: false
})
.usage('$0 [backup_file]', 'Filter/Transform rows during restore process for Postgres databases. For more detailed information check: https://github.com/rebelstackio/pgfilter', (yargs) => {
yargs.positional('backup_file', {
describe: 'Path to the Postgres Backup file.',
type: 'string',
default: null,
defaultDescription: 'null. pgfilter Use STDIN by default',
normalize: true,
coerce: (b) => validBackupFile(b, 'backup_file')
}).example([
['$0 -f ~/config.json mydb.dump | psql -p "$PGPORT" --dbname=mydb', 'Restore an anonymized version of the database']
])
}).argv
input(pgfilter)