mirror of
https://github.com/wassname/talk.git
synced 2026-06-28 15:23:50 +08:00
4fb9910221
- removed -c,--config flag in favor of env only or .env files - loads .env always if found - scripts re-written to call cli-serve directly
50 lines
1.5 KiB
JavaScript
Executable File
50 lines
1.5 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Module dependencies.
|
|
*/
|
|
|
|
const program = require('commander');
|
|
const mongoose = require('../services/mongoose');
|
|
const util = require('./util');
|
|
const databaseVerifications = require('./verifications/database');
|
|
|
|
// Register the shutdown criteria.
|
|
util.onshutdown([
|
|
() => mongoose.disconnect()
|
|
]);
|
|
|
|
async function database({fix = false, limit = Infinity, batch = 1000}) {
|
|
try {
|
|
for (const verification of databaseVerifications) {
|
|
await verification({fix, limit, batch});
|
|
}
|
|
} catch (err) {
|
|
console.error(`Failed to process all the ${databaseVerifications.length} verifications`, err);
|
|
util.shutdown(1);
|
|
return;
|
|
}
|
|
|
|
util.shutdown();
|
|
}
|
|
|
|
//==============================================================================
|
|
// Setting up the program command line arguments.
|
|
//==============================================================================
|
|
|
|
program
|
|
.command('db')
|
|
.description('verifies the database integrity')
|
|
.option('-f, --fix', 'fix the problems found with database inconsistencies')
|
|
.option('-l, --limit [size]', 'limit the amount of documents to process in a single pass, this will ensure only a maximum number of batch operations are issued [default: inf]', parseInt)
|
|
.option('-b, --batch [size]', 'batch size to process verifications and repairs of documents [default: 1000]', parseInt)
|
|
.action(database);
|
|
|
|
program.parse(process.argv);
|
|
|
|
// If there is no command listed, output help.
|
|
if (!process.argv.slice(2).length) {
|
|
program.outputHelp();
|
|
util.shutdown();
|
|
}
|