This is a tool to backup and restore small Knex-based databases. Note that this is using only in-memory JSON-blocks and does not use streaming. Thus it is not suitable for huge databases.
In the directory containing a knexfile.js
, you can save all data to the dump file:
knex-dump --file dump.json dump
Then it can be restored to the database
knex-dump --file dump.json restore
In a project using Knex, you can make seed data managament easy. Add a script
"scripts": {
...
"save": "knex-dump --file seeds/data.json restore"
},
to your package.json
. Then you can dump the current state of the database as seed data
by running
npm run save
Then you need only one seed file, for example seeds/load-database.js
, having
exports.seed = function(knex, Promise) {
return require('knex-dump').load(__dirname + '/../knexfile.js', __dirname + '/data.json');
};
- 1.0.0 Simple dumping and restoring on a file.
- 1.0.1 Canonical sorting for all columns.
- 1.0.2 An interface for using
neat-dump
as a Node-module. - 1.0.3 Avoid crash if data is missing.
- 1.0.4 Load data in chunks to avoid sqlite limitations.
- 1.0.5 MSSQL support.
- 1.0.6 Postgres support.