<commit_before>var fs = require('fs'),
  path = require('path'),
  Sequelize = require('sequelize'),
  lodash = require('lodash'),
  config = require('../../config/config'),
  db = {};

var sequelize = new Sequelize(config.db, config.username, config.password);

fs.readdirSync(__dirname).filter(function (file) {
  return (file.indexOf('.') !== 0) && (file !== 'index.js');
}).forEach(function (file) {
  var model = sequelize.import(path.join(__dirname, file));
  db[model.name] = model;
});

Object.keys(db).forEach(function (modelName) {
  if ('associate' in db[modelName]) {
    db[modelName].associate(db);
  }
});

module.exports = lodash.extend({
  sequelize: sequelize,
  Sequelize: Sequelize
}, db);<commit_msg>refactor to find all models in model folders<commit_after>var fs        = require('fs')
  , path      = require('path')
  , Sequelize = require('sequelize')
  , lodash    = require('lodash')
  , config    = require('../../config/config')
  , glob      = require('glob')
  , root      = path.normalize(__dirname + '/../..')
  , db        = {};

var sequelize = new Sequelize(config.db, config.username, config.password, {
    dialect : 'postgres'
  , host    : 'localhost'
  , port    : 5433
});

/*
 * get all models files from model folders
 */
var modules = glob.sync('app/modules/**/model/*.js');
modules.forEach(function(module){
    var modelName  = path.basename(module)
      , modelPath  = path.join(root, module)
      , model      = sequelize.import(modelPath);
    db[model.name] = model;
});

Object.keys(db).forEach(function (modelName) {
  if ('associate' in db[modelName]) {
    db[modelName].associate(db);
  }
});

module.exports = lodash.extend({
  sequelize: sequelize,
  Sequelize: Sequelize
}, db);
{'fraction_non_alphanumeric': 0.1810344827586207, 'fraction_numerical': 0.0028735632183908046, 'mean_word_length': 3.581578947368421, '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': '307942', 'n_tokens_mistral': 591, 'n_tokens_neox': 578, 'n_words': 116}