A module for seeding the master data for the micro services.
Node
and npm
should be available.
- Install exframe-seeding module in your micro service.
npm install exframe-seeding --save
-
Create a folder for your DB scripts and specify it in the environment variable
DB_SCRIPTS_PATH
(relative path from the root folder for your application). The module looks for a folder db_scripts in the root folder of your micro service by default. -
The module reads the files in the specified folder sequentially and executes the up method in them. The template for a DB script file is:
const mongoose = require('exframe-seeding').get();
module.exports = {
up: () => {
return new Promise((resolve, reject) => {
// Modifications in your DB with the provided instance of mongoose
});
}
}
- After the DB scripts have been set up, connect to Mongo DB from your micro service.
const exframeSeeding = require('exframe-seeding');
exframeSeeding.connect(MONGO_URL, (err) => {
if (err) {
// Handle error
}
});
After the connection has been made, the module runs the DB scripts provided and implicitly manages the versioning.
- The micro service has to be started with npm, as the package gets the fetches the name of the micro service from
package.json
.
- Collection Name:
seedversion
- Structure:
{
service_name: <name of the micro service from package.json>,
increments: <number of up scripts executed>
}
Note: The down scripts have to be run as Mongo Shell scripts and the
increments
field has to be decremented for each down script which was run. This is required in order to properly execute the up scripts on further intializations of the micro service.