<commit_before>/**
 * Created by deefactorial on 28/01/16.
 */


if(typeof process.env.COUCHBASE_ADMIN_USERNAME == 'undefined'){
    console.error("Did you forget to set the COUCHBASE_ADMIN_USERNAME environment variable?");
}
if(typeof process.env.COUCHBASE_ADMIN_PASSWORD == 'undefined'){
    console.error("Did you forget to set the COUCHBASE_ADMIN_PASSWORD environment variable?");
}

var couchbase = require('couchbase'),
    serverAddress = '127.0.0.1',
    cluster = new couchbase.Cluster('couchbase://' + serverAddress),
    clusterManager = cluster.manager(process.env.COUCHBASE_ADMIN_USERNAME, process.env.COUCHBASE_ADMIN_PASSWORD),
    //N1qlQuery = couchbase.N1qlQuery,
    async = require('async'),
    tasks = {},
    openmoney_global = null,
    model = require('./installData');

tasks.create_bucket_oauth2Server = function(callback){
    //Create the bucket
    clusterManager.createBucket('oauth2Server', {}, function(err, results){
        if(err){
            callback("CREATE oauth2Server BUCKET ERROR: (Check that there is free ram into create a bucket by manually creating a bucket through the admin interface. Does this bucket already exist ?) :" + err, null);
        } else {
            callback(null,"Successfully created oauth2Server bucket.");
        }
    });
};

// tasks.create_index_oauth2Server = function(callback){
//     //give couchbase a couple seconds to initialize the db.
//     setTimeout(function(){
//
//         //Open the bucket
//         var oauth2Server = cluster.openBucket('oauth2Server');
//         oauth2Server.enableN1ql(['http://' + serverAddress + ':8093/']);
//
//         Create the primary index on the bucket to query the bucket for model.dump
//         var queryString = "CREATE PRIMARY INDEX `#primary` ON `oauth2Server` USING GSI;";
//         var query = N1qlQuery.fromString(queryString);
//         oauth2Server.query(query, function(err, doc){
//             if(err) {
//                 callback("CREATE PRIMARY INDEX ERROR:" + err, null);
//             } else {
//                 callback(null, "Successfully created index.");
//             }
//         });
//     }, 3000);
// };

tasks.create_bucket_openmoney_global = function(callback){
    //Create the bucket
    clusterManager.createBucket('openmoney_global', {}, function(err, results){
        if(err){
            callback("CREATE openmoney_global BUCKET ERROR:" + err, null);
        } else {
            callback(null,"Successfully created openmoney_global bucket.");
        }
    });
};

// tasks.create_index_openmoney_global = function(callback){
//     //give couchbase a couple seconds to initialize the db.
//     setTimeout(function(){
//
//         //Open the bucket
//         openmoney_global = cluster.openBucket('openmoney_global');
//         openmoney_global.enableN1ql(['http://' + serverAddress + ':8093/']);
//
//         Create the primary index on the bucket to query the bucket for model.dump
//         var queryString = "CREATE PRIMARY INDEX `#primary` ON `openmoney_global` USING GSI;";
//         var query = N1qlQuery.fromString(queryString);
//         openmoney_global.query(query, function(err, doc){
//             if(err) {
//                 callback("CREATE PRIMARY INDEX ERROR:" + err, null);
//             } else {
//                 callback(null, "Successfully created index.");
//             }
//         });
//     }, 3000);
// };

tasks.create_bucket_openmoney_stewards = function(callback){
    //Create the bucket
    clusterManager.createBucket('openmoney_stewards', {}, function(err, results){
        if(err){
            callback("CREATE openmoney_stewards BUCKET ERROR:" + err, null);
        } else {
            callback(null,"Successfully created openmoney_stewards bucket.");
        }
    });
};

// tasks.create_index_openmoney_stewards = function(callback){
//     //give couchbase a couple seconds to initialize the db.
//     setTimeout(function(){
//
//         //Open the bucket
//         var openmoney_stewards = cluster.openBucket('openmoney_stewards');
//         openmoney_stewards.enableN1ql(['http://' + serverAddress + ':8093/']);
//
//         Create the primary index on the bucket to query the bucket for model.dump
//         var queryString = "CREATE PRIMARY INDEX `#primary` ON `openmoney_stewards` USING GSI;";
//         var query = N1qlQuery.fromString(queryString);
//         openmoney_stewards.query(query, function(err, doc){
//             if(err) {
//                 callback("CREATE PRIMARY INDEX ERROR:" + err, null);
//             } else {
//                 callback(null, "Successfully created index.");
//             }
//         });
//     }, 3000);
// };

tasks.insert_initial_data = function(callback){

    //give some time for the buckets to initialize
    setTimeout(function(){
      if(openmoney_global == null){
          openmoney_global = cluster.openBucket('openmoney_global');
      }
      var insertTasks = {};

      Object.keys(model).forEach(function (key) {
          var value = model[key];
          insertTasks[value.id] = function(cb){
              openmoney_global.insert(value.id, value, function(err, res) {
                  if(err) {
                      cb(err, null);
                  } else {
                      cb(null, res);
                  }
              });
          }
      });

      async.parallel(insertTasks, function(err, res){
          if(err){
              callback(err, null);
          } else {
              callback(null, res);
          }
      });
    }, 10000);
};

async.series(tasks, function(err, results){
    if(err){
        console.log(err);
    } else {
        console.log("successfully installed");
        console.log(results);
    }
    process.exit();
});
<commit_msg>update error message to be more helpful<commit_after>/**
 * Created by deefactorial on 28/01/16.
 */


if(typeof process.env.COUCHBASE_ADMIN_USERNAME == 'undefined'){
    console.error("Did you forget to set the COUCHBASE_ADMIN_USERNAME environment variable?");
}
if(typeof process.env.COUCHBASE_ADMIN_PASSWORD == 'undefined'){
    console.error("Did you forget to set the COUCHBASE_ADMIN_PASSWORD environment variable?");
}

var couchbase = require('couchbase'),
    serverAddress = '127.0.0.1',
    cluster = new couchbase.Cluster('couchbase://' + serverAddress),
    clusterManager = cluster.manager(process.env.COUCHBASE_ADMIN_USERNAME, process.env.COUCHBASE_ADMIN_PASSWORD),
    //N1qlQuery = couchbase.N1qlQuery,
    async = require('async'),
    tasks = {},
    openmoney_global = null,
    model = require('./installData');

tasks.create_bucket_oauth2Server = function(callback){
    //Create the bucket
    clusterManager.createBucket('oauth2Server', {}, function(err, results){
        if(err){
            callback("CREATE oauth2Server BUCKET ERROR: (Check that there is free ram to create a bucket; By manually creating a bucket through the admin interface. If the bucket exists you may have setup the bucket already, check through the admin interface, if it failed through the installation process you can restart by deleting the buckets and running the command `node install`.) :" + err, null);
        } else {
            callback(null,"Successfully created oauth2Server bucket.");
        }
    });
};

// tasks.create_index_oauth2Server = function(callback){
//     //give couchbase a couple seconds to initialize the db.
//     setTimeout(function(){
//
//         //Open the bucket
//         var oauth2Server = cluster.openBucket('oauth2Server');
//         oauth2Server.enableN1ql(['http://' + serverAddress + ':8093/']);
//
//         Create the primary index on the bucket to query the bucket for model.dump
//         var queryString = "CREATE PRIMARY INDEX `#primary` ON `oauth2Server` USING GSI;";
//         var query = N1qlQuery.fromString(queryString);
//         oauth2Server.query(query, function(err, doc){
//             if(err) {
//                 callback("CREATE PRIMARY INDEX ERROR:" + err, null);
//             } else {
//                 callback(null, "Successfully created index.");
//             }
//         });
//     }, 3000);
// };

tasks.create_bucket_openmoney_global = function(callback){
    //Create the bucket
    clusterManager.createBucket('openmoney_global', {}, function(err, results){
        if(err){
            callback("CREATE openmoney_global BUCKET ERROR:" + err, null);
        } else {
            callback(null,"Successfully created openmoney_global bucket.");
        }
    });
};

// tasks.create_index_openmoney_global = function(callback){
//     //give couchbase a couple seconds to initialize the db.
//     setTimeout(function(){
//
//         //Open the bucket
//         openmoney_global = cluster.openBucket('openmoney_global');
//         openmoney_global.enableN1ql(['http://' + serverAddress + ':8093/']);
//
//         Create the primary index on the bucket to query the bucket for model.dump
//         var queryString = "CREATE PRIMARY INDEX `#primary` ON `openmoney_global` USING GSI;";
//         var query = N1qlQuery.fromString(queryString);
//         openmoney_global.query(query, function(err, doc){
//             if(err) {
//                 callback("CREATE PRIMARY INDEX ERROR:" + err, null);
//             } else {
//                 callback(null, "Successfully created index.");
//             }
//         });
//     }, 3000);
// };

tasks.create_bucket_openmoney_stewards = function(callback){
    //Create the bucket
    clusterManager.createBucket('openmoney_stewards', {}, function(err, results){
        if(err){
            callback("CREATE openmoney_stewards BUCKET ERROR:" + err, null);
        } else {
            callback(null,"Successfully created openmoney_stewards bucket.");
        }
    });
};

// tasks.create_index_openmoney_stewards = function(callback){
//     //give couchbase a couple seconds to initialize the db.
//     setTimeout(function(){
//
//         //Open the bucket
//         var openmoney_stewards = cluster.openBucket('openmoney_stewards');
//         openmoney_stewards.enableN1ql(['http://' + serverAddress + ':8093/']);
//
//         Create the primary index on the bucket to query the bucket for model.dump
//         var queryString = "CREATE PRIMARY INDEX `#primary` ON `openmoney_stewards` USING GSI;";
//         var query = N1qlQuery.fromString(queryString);
//         openmoney_stewards.query(query, function(err, doc){
//             if(err) {
//                 callback("CREATE PRIMARY INDEX ERROR:" + err, null);
//             } else {
//                 callback(null, "Successfully created index.");
//             }
//         });
//     }, 3000);
// };

tasks.insert_initial_data = function(callback){

    //give some time for the buckets to initialize
    setTimeout(function(){
      if(openmoney_global == null){
          openmoney_global = cluster.openBucket('openmoney_global');
      }
      var insertTasks = {};

      Object.keys(model).forEach(function (key) {
          var value = model[key];
          insertTasks[value.id] = function(cb){
              openmoney_global.insert(value.id, value, function(err, res) {
                  if(err) {
                      cb(err, null);
                  } else {
                      cb(null, res);
                  }
              });
          }
      });

      async.parallel(insertTasks, function(err, res){
          if(err){
              callback(err, null);
          } else {
              callback(null, res);
          }
      });
    }, 10000);
};

async.series(tasks, function(err, results){
    if(err){
        console.log(err);
    } else {
        console.log("successfully installed");
        console.log(results);
    }
    process.exit();
});

{'fraction_non_alphanumeric': 0.13291946594098136, 'fraction_numerical': 0.010034866910451568, 'mean_word_length': 2.308947664603264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1909244', 'n_tokens_mistral': 3394, 'n_tokens_neox': 3247, 'n_words': 791}