1 | process.on('unhandledRejection', rejection => console.error(rejection));
|
2 |
|
3 | const Cloudant = require('@cloudant/cloudant');
|
4 | const Schema = require('../lib/schema');
|
5 |
|
6 | const args = process.argv.slice(2);
|
7 |
|
8 | if (!args[1]) {
|
9 | throw Error('No db specified');
|
10 | }
|
11 |
|
12 | const dbUrl = args[0];
|
13 | const dbNames = args.slice(1);
|
14 |
|
15 | dbNames.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 | });
|