<commit_before>/*eslint no-console:0 */
"use strict";
import AdminDbClient from "./db/AdminDbClient.js";
import Migration from "./migration/Migration";
var argv = require("yargs").argv;

let migrateDb = (dbName, token) => {
    console.log("migrating db...");
    let migrationInstance = Migration.instance(dbName, token);
    migrationInstance.start().then(() => {
        console.log("migration complete.");
    }).catch(error => {
        console.log("error while migrating db.", error);
    });
};

let setPermissions = (dbInstance, userName, dbName) => {
    console.log("setting permissions...");
    dbInstance.setPermissions(userName, dbName).then(() => {
        console.log("user permissions are set to database");
        migrateDb(dbName, dbInstance.accessToken);
    }).catch(error => {
        console.log(`set permissions failed with error ${error}`);
    });
};

let createDb = (dbInstance, userName, dbName) => {
    console.log("creating user database...");
    dbInstance.createDb(dbName).then(() => {
        console.log("created user db.");
        setPermissions(dbInstance, userName, dbName);
    }).catch(error => {
        console.log(`database creation failed with error ${error}`);
    });
};

console.log("usage:: node dist/server/src/createUser.js --admin_user_name='username' --admin_password='password' --user_name='userName'");
if(!argv.admin_user_name || !argv.admin_password || !argv.user_name) {
    throw new Error("admin user name, password and user name can not be blank");
}
console.log("User creation started.");
AdminDbClient.instance(argv.admin_user_name, argv.admin_password, argv.user_name).then(dbInstance => {
    let userName = argv.user_name, password = Math.random().toString("36").slice("-8"), dbName = argv.user_name;
    console.log("creating user...");
    dbInstance.createUser(userName, password).then(() => {
        console.log(`created user: ${userName} with password: ${password}`);
        createDb(dbInstance, userName, dbName);
    }).catch(error => {
        console.log(`user creation failed with error ${error}`);
    });
<commit_msg>[Rav] added password input for user creation<commit_after>/*eslint no-console:0 */
"use strict";
import AdminDbClient from "./db/AdminDbClient.js";
import Migration from "./migration/Migration";
var argv = require("yargs").argv;

let migrateDb = (dbName, token) => {
    console.log("migrating db...");
    let migrationInstance = Migration.instance(dbName, token);
    migrationInstance.start().then(() => {
        console.log("migration complete.");
    }).catch(error => {
        console.log("error while migrating db.", error);
    });
};

let setPermissions = (dbInstance, userName, dbName) => {
    console.log("setting permissions...");
    dbInstance.setPermissions(userName, dbName).then(() => {
        console.log("user permissions are set to database");
        migrateDb(dbName, dbInstance.accessToken);
    }).catch(error => {
        console.log(`set permissions failed with error ${error}`);
    });
};

let createDb = (dbInstance, userName, dbName) => {
    console.log("creating user database...");
    dbInstance.createDb(dbName).then(() => {
        console.log("created user db.");
        setPermissions(dbInstance, userName, dbName);
    }).catch(error => {
        console.log(`database creation failed with error ${error}`);
    });
};

console.log("usage:: node dist/server/src/createUser.js --admin_user_name='username' --admin_password='password' --user_name='userName' --user_password='password'");
if(!argv.admin_user_name || !argv.admin_password || !argv.user_name) {
    throw new Error("admin user name, password and user name can not be blank");
}
console.log("User creation started.");
AdminDbClient.instance(argv.admin_user_name, argv.admin_password, argv.user_name).then(dbInstance => {
    let userName = argv.user_name, password = argv.user_password || Math.random().toString("36").slice("-8"), dbName = argv.user_name;
    console.log("creating user...");
    dbInstance.createUser(userName, password).then(() => {
        console.log(`created user: ${userName} with password: ${password}`);
        createDb(dbInstance, userName, dbName);
    }).catch(error => {
        console.log(`user creation failed with error ${error}`);
    });

{'fraction_non_alphanumeric': 0.1697054698457223, 'fraction_numerical': 0.0018700327255726976, 'mean_word_length': 3.946820809248555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3794704', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1247, 'n_words': 278}