1.1.0 • Published 5 years ago
@eidellev/json-migrate v1.1.0
@eidellev/json-migrate
A data migration tool for your JSON files.
Installation
# globally
npm i -g @eidellev/json-migrate
#or
yarn global add @eidellev/json-migrate
# locally
npm i @eidellev/json-migrate
#or
yarn add @eidellev/json-migrateBasic CLI Usage
Usage: migrate [options] [command]
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
init Initialize json-migrate and generate default configuration
new [name] Create a new migration script
run Run all migrations
help [command] display help for commandThe run command
Usage: migrate run [options]
Run all migrations
Options:
F, --fresh Ignore history and re-run all migrations
-h, --help display help for commandConfiguration
{
"migrationsPath": "./migrations",
"dataPaths": "data/**/*.json"
}migrationsPath (string)- The directory wherejson-migartewill look for migration scripts.dataPaths (string or string array)- Glob expression(s). Wherejson-migrateshould look for data files.
Migrations history
json-migarte will keep a list of migrations that had been previously run in .migrations-history.json and will not run the same migration again. If you wish re-run a specific migration, simply delete it from the file.
Migration Script Example
/**
* Migration function
* @param {object} originalJson The original json
* @return {object} Transformed
*/
module.exports = function migrate(originalJson) {
// Transform original json data and return
// new object that will be saved in its place
return originalJson;
};