0.2.0 • Published 6 years ago
@itexpert-dev/keyvalue-cli v0.2.0
KeyValueStore Migration Tool
Getting started
- Install via npm
$ npm install --global @itexpert-dev/keyvalue-cli
- Run
kvs --help
in terminal for help - To use most of the commands you need config-file.
./kvs.json
is used by default. You can change the path with--config
option. For the list of available options see Config section below.
Features
See
kvs --help
for the list of available commands. Seekvs <command> --help
for additional information about the command.
- run - Runs migration scripts in specified directory
- test - Checks if specified service can execute without errors. If JSON Schema provided with the script, test also checks if produced result match the schema.
- sample - Prints random value from given set.
- show - Prints all keys in given set or key-value if full key is specified
- history-down - Removes all set migration history after specified version (exclusive).
- history-show - Shows migration history of a given set.
Config
Available options:
- host (required) - KeyValueStore service address
- auth (required) - KeyValueStore authentication method
- schema - HTTP authentication schema (e.g.
Bearer
orBasic
) - value - HTTP authentication value (e.g. token or basic credentials)
- schema - HTTP authentication schema (e.g.
{
"host": "http://localhost:6480",
"auth": {
"schema": "Bearer",
"value": "token"
}
}
Samples
Basic script
// Script is executed in Node environment,
// so no `export` syntax, use `module.exports` instead.
module.exports.view = {
// Migrated set name
set: 'view',
// Script version
version: '0.1.0',
// Function to transform one key-value from specified set.
// If same key-value, null or undefined returned, key-value stays in the store stays the same.
// If if `{key, value: null}` is returned, key-value is removed from the store.
map({key, value}) {
return {key, value};
}
};
JSON Schema for validation
const stringField = {type: 'string'};
module.exports.view = {
set: 'view',
version: '0.1.0',
map({key, value}) {
value = {'a': 123};
return {key, value};
},
schema: {
type: 'object',
required: ['data'],
properties: {
data: {
type: 'object',
properties: {
id: stringField,
name: stringField,
isShared: {type: 'boolean'},
fields: {
type: 'array',
item: stringField
}
}
}
},
additionalProperties: true
}
};