UNPKG

703 BJavaScriptView Raw
1process.on('unhandledRejection', rejection => console.error(rejection));
2
3const Cloudant = require('@cloudant/cloudant');
4const Schema = require('../lib/schema');
5
6const args = process.argv.slice(2);
7
8if (!args[1]) {
9 throw Error('No db specified');
10}
11
12const dbUrl = args[0];
13const dbNames = args.slice(1);
14
15dbNames.forEach(async (dbName) => {
16 const db = new Cloudant({
17 url: dbUrl,
18 plugins: ['promises', 'retry'],
19 }).db.use(dbName);
20
21 const clientConfig = await db.get('config');
22
23 const schema = new Schema({
24 db: {
25 url: args[0],
26 name: dbName,
27 },
28 });
29
30 await schema.updateEntityIndex(clientConfig.schemas);
31
32 console.log(`${dbName} --> entity index updated`);
33});