<commit_before>'use strict';


const util    = require('util');
const fs      = require('fs');
const path    = require('path');

const _       = require('lodash');
const async   = require('async');
const winston = require('winston');

const config  = require('../config');
const plugins = require('../plugins');

let db;

module.exports.init = function(_db) {
  db = _db;
  if (process.env.AUTO_MIGRATE === 'true') {
    module.exports.migrate(function() {});
  }
};

//
module.exports.initmigrations = function(callback) {
  var create = 'CREATE TABLE IF NOT EXISTS `__db_migrations` (' + '`id` INTEGER NOT NULL AUTO_INCREMENT, ' + '`file` VARCHAR(100), ' + '`success` TINYINT(1), ' + '`err` VARCHAR(255), ' + '`creation` DATETIME, ' + 'PRIMARY KEY (`id`) ' + ') ENGINE=InnoDB DEFAULT CHARSET=utf8';
  db.query(create, callback);
};

//
module.exports.list = function(callback) {
  module.exports.initmigrations(function() {
    var sql = 'SELECT * FROM `__db_migrations` ORDER BY `id` DESC';
    db.query(sql, callback);
  });
};<commit_msg>Use config to auto migrate db<commit_after>'use strict';


const util    = require('util');
const fs      = require('fs');
const path    = require('path');

const _       = require('lodash');
const async   = require('async');
const winston = require('winston');

const config  = require('../config');
const plugins = require('../plugins');

let db;

module.exports.init = function(_db) {
  db = _db;
  if (config.auto_migrate) {
    module.exports.migrate(function() {});
  }
};

//
module.exports.initmigrations = function(callback) {
  var create = 'CREATE TABLE IF NOT EXISTS `__db_migrations` (' + '`id` INTEGER NOT NULL AUTO_INCREMENT, ' + '`file` VARCHAR(100), ' + '`success` TINYINT(1), ' + '`err` VARCHAR(255), ' + '`creation` DATETIME, ' + 'PRIMARY KEY (`id`) ' + ') ENGINE=InnoDB DEFAULT CHARSET=utf8';
  db.query(create, callback);
};

//
module.exports.list = function(callback) {
  module.exports.initmigrations(function() {
    var sql = 'SELECT * FROM `__db_migrations` ORDER BY `id` DESC';
    db.query(sql, callback);
  });
};
{'fraction_non_alphanumeric': 0.1840843720038351, 'fraction_numerical': 0.007670182166826462, 'mean_word_length': 4.127764127764128, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4186461', 'n_tokens_mistral': 737, 'n_tokens_neox': 709, 'n_words': 164}