@fork-hu/db-cleaner
v1.0.1
Published
Remove INSERT INTO statements for specified tables from MySQL dump files
Readme
fork-db-cleaner
A lightweight Node.js CLI that processes MySQL dump files and removes INSERT INTO statements for specified tables (e.g. ntakmessages). Uses streaming to handle large dumps without loading the entire file into memory.
Requirements
- Node.js 18+
Install
npm install -g @fork-hu/db-cleanerOr run via npx without installing:
npx @fork-hu/db-cleaner -i dump.sql -o cleaned.sqlUsage
db-cleaner --input <path> --output <path> [--tables table1,table2,...] [--before YYYY-MM-DD] [--created-at-column createdAt]Alias: fdclean (shorthand)
| Option | Short | Required | Default | Description |
|-----------------------|-------|----------|-----------------|--------------------------------------------------------------------------|
| --input | -i | Yes | — | Path to the source MySQL dump file |
| --output | -o | Yes | — | Path to write the cleaned SQL file |
| --tables | -t | No | ntakmessages | Comma-separated table names to process |
| --before | -b | No | — | Cutoff date: keep only rows where createdAt ≥ this date (YYYY-MM-DD) |
| --created-at-column | — | No | createdAt | Column name used for date filtering (when --before is set) |
Examples
Remove only ntakmessages inserts (default):
db-cleaner -i dump.sql -o cleaned.sqlRemove inserts for multiple tables:
db-cleaner -i dump.sql -o cleaned.sql -t ntakmessages,audit_log,sessionsPowerShell users: Quote arguments containing commas, or use multiple -t flags:
db-cleaner -i dump.sql -o cleaned.sql -t "ntakmessages,orderitems" -b 2025-01-01
db-cleaner -i dump.sql -o cleaned.sql -t ntakmessages -t orderitems -b 2025-01-01Keep only recent records (filter by createdAt):
db-cleaner -i dump.sql -o cleaned.sql -b 2025-01-01Output
The tool prints a summary when done:
Done. 1,204,300 lines processed, 98,440 lines removed. Output: cleaned.sqlWith --before, it also reports rows kept vs removed:
Done. 196,701 lines processed, 7,715 lines removed. Rows kept: 9,003, rows removed: 7,179. Output: dump-filtered.sqlThe output file is a valid MySQL dump and can be imported with:
mysql -u user -p database < cleaned.sql