<commit_before>'use strict';

const helper = require('./database/helper');

return helper.connectToDatabase()
  .then((db) => db.createCollection('users_duplications'))
  .then((collection) => collection.drop())
  .then((result) => {
    console.log('Got result from drop users_duplications:', result);
    return helper.connectToDatabase()
      .then((db) => db.createCollection('users_migrated'))
      .then((collection) => collection.drop())
      .then(() => {
        console.log('Got result from drop users_migrated:', result);
        return helper.connectToDatabase()
          .then((db) => db.collection('users'))
          .then((coll) => coll.mapReduce(function() {
            emit(this.username.toLowerCase().replace(/[|\s&;$%&§\{\[\]\}@"<>()+,!?\-._~\=\*\+\#\;\\/]/g, ''), this);
          },
            function(key, values) {
              if (values.length === undefined || values.length === null || values.length < 1)
                values = [values];<commit_msg>[SWIK-1280_username_case_insensitive] migration code now makes emails to lowercase. Also added small data error handling in migration code<commit_after>'use strict';

const helper = require('./database/helper');

return helper.connectToDatabase()
  .then((db) => db.createCollection('users_duplications'))
  .then((collection) => collection.drop())
  .then((result) => {
    console.log('Got result from drop users_duplications:', result);
    return helper.connectToDatabase()
      .then((db) => db.createCollection('users_migrated'))
      .then((collection) => collection.drop())
      .then(() => {
        console.log('Got result from drop users_migrated:', result);
        return helper.connectToDatabase()
          .then((db) => db.collection('users'))
          .then((coll) => coll.mapReduce(function() {
            if (!this.username || !this.email)
              return;

            this.email = this.email.toLowerCase();
            emit(this.username.toLowerCase().replace(/[|\s&;$%&§\{\[\]\}@"<>()+,!?\-._~\=\*\+\#\;\\/]/g, ''), this);
          },
            function(key, values) {
              if (values.length === undefined || values.length === null || values.length < 1)
                values = [values];
{'fraction_non_alphanumeric': 0.19657348963029755, 'fraction_numerical': 0.002705139765554554, 'mean_word_length': 2.8861646234676006, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '394026', 'n_tokens_mistral': 641, 'n_tokens_neox': 631, 'n_words': 121}