diff --git a/dbInit/index.js b/dbInit/index.js new file mode 100644 index 0000000..7db0768 --- /dev/null +++ b/dbInit/index.js @@ -0,0 +1,95 @@ +// dbInit/index.js + +"use strict" + +const dbInit = {}; + +const bulkData = [ + { "index" : { "_index" : "changelog" } }, + { "author" : "John Ripper { + + console.log( "Index 'changelog' created with success."); + + // seed if flag ok + if( ! seed ){ return true; }; + this.client.bulk({ + index: "changelog", + body: this.bulkData + + + }).then( (r) => { + console.log( "bulk insert OK"); + }, (r) => { + console.log( "bulk insert ERROR! : ",r); + }); + },( result ) => { + console.log( "Index 'changelog' already exists, skipping."); + }); + + this.client.indices.create({ + index : "changelog-trash", + body: { + mappings: this.mappings + } + }).then( (result) => { + + console.log( "Index 'changelog-trash' created with success."); + },( result ) => { + console.log( "Index changelog-trash exists, skipping."); + }); + + +}; + +module.exports = dbInit; + +// EOF \ No newline at end of file diff --git a/index.js b/index.js index 82c7654..b453b21 100644 --- a/index.js +++ b/index.js @@ -24,6 +24,12 @@ curl -X PUT 'http://localhost:9200/changelog' -d ' const authorizationToken = process.env.AUTH_TOKEN || "hello"; const port = process.env.APP_PORT || 3000; +const dbInit = require("./dbInit"); +dbInit.init({ + seed : process.env.DB_SEED +}); + +console.log( "exit") const express = require('express'); const app = express();