<commit_before>#!/usr/bin/env node
'use strict';

process.chdir(__dirname + '/../../');

var thinky = require(__dirname + '/../../util/thinky.js');
var Config = require(__dirname + '/../../models/config.js');
var config = require('config');
var r = thinky.r;

var settings = {
  id: 1
};

var checkStatus = () => {
  Config.filter({id: 1}).then(function (result) {
    if (!result || result.length < 1) {
      getOldConfig();
    } else {
      console.log('No migration necessary.');
      process.exit(0);
    }
  }).error((error) => {
    console.log(error);
    console.log('ERROR: Failed to check migration status. Aborting.');
    process.exit(1);
  });
};

var getOldConfig = () => {
  let oldKeys = ['sessionSecret', 'encryptionSecret'];
  let count = 0;
  console.log('Loading old config values...');
  for (var key in oldKeys) {
    (function (key) {
      r.db(config.get('dbConfig.dbName')).table('config').filter({key: oldKeys[key]}).then(function (result) {
        console.log('Loaded value for key \'' + oldKeys[key] + '\'.');
        settings[oldKeys[key]] = result[0].value;
        count++;
        if (count >= oldKeys.length) saveNewConfig();
      })
    })(key)
  }
};

var saveNewConfig = () => {
  if (Object.keys(settings).length < 2) {
    console.log('ERROR: Could not load all config values! Aborting.');
    process.exit(1);
  }
  settings.maxFileSize = 1e+7;
  settings.maxQuota = 1e+8;
  settings.mimeList = '';
  settings.mimeListType = true;
  console.log('Saving new config...');
  var newConfig = new Config(settings);
  newConfig.save().then((result) => {
    console.log('Config saved.');
    console.log('Deleting old values...');
    r.db(config.get('dbConfig.dbName')).table('config').filter((arg) => {
      return r.not(arg('id').eq(1));
    }).delete().then((result) => {
      console.log('Done!');<commit_msg>Fixed migration script 000-100<commit_after>#!/usr/bin/env node
'use strict';

process.chdir(__dirname + '/../../');

var thinky = require(__dirname + '/../../util/thinky.js');
var Config = require(__dirname + '/../../models/config.js');
var config = require('config');
var r = thinky.r;

var settings = {
  id: 1
};

var checkStatus = () => {
  Config.filter({id: 1}).then(function (result) {
    if (!result || result.length < 1) {
      getOldConfig();
    } else {
      console.log('No migration necessary.');
      process.exit(0);
    }
  }).error((error) => {
    console.log(error);
    console.log('ERROR: Failed to check migration status. Aborting.');
    process.exit(1);
  });
};

var getOldConfig = () => {
  let oldKeys = ['sessionSecret', 'encryptionSecret'];
  let count = 0;
  console.log('Loading old config values...');
  for (var key in oldKeys) {
    (function (key) {
      r.db(config.get('dbConfig.dbName')).table('config').filter({key: oldKeys[key]}).then(function (result) {
        console.log('Loaded value for key \'' + oldKeys[key] + '\'.');
        settings[oldKeys[key]] = result[0].value;
        count++;
        if (count >= oldKeys.length) saveNewConfig();
      })
    })(key)
  }
};

var saveNewConfig = () => {
  if (Object.keys(settings).length < 2) {
    console.log('ERROR: Could not load all config values! Aborting.');
    process.exit(1);
  }
  settings.maxFileSize = 1e+7;
  settings.maxQuota = 1e+8;
  settings.mimeList = [];
  settings.mimeListType = true;
  console.log('Saving new config...');
  var newConfig = new Config(settings);
  newConfig.save().then((result) => {
    console.log('Config saved.');
    console.log('Deleting old values...');
    r.db(config.get('dbConfig.dbName')).table('config').filter((arg) => {
      return r.not(arg('id').eq(1));
    }).delete().then((result) => {
      console.log('Done!');
{'fraction_non_alphanumeric': 0.20622150710646286, 'fraction_numerical': 0.009117725931885224, 'mean_word_length': 3.158305462653289, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '2869853', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1225, 'n_words': 248}