{"size": 1552, "ext": "js", "max_stars_repo_path": "server/models/index.js", "max_stars_repo_name": "Imater/auction", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/models/index.js", "max_issues_repo_name": "Imater/auction", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/models/index.js", "max_forks_repo_name": "Imater/auction", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.8769230769, "max_line_length": 72, "alphanum_fraction": 0.5753865979}
'use strict';
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var excludeFiles = ['index.js'];
var config = require('../config');
var logger = require('../config/logger');

var Sequelize = require('sequelize');

var sequelize = new Sequelize(
    config.db.name,
    config.db.username,
    config.db.password, {
        host: config.db.host,
        port: config.db.port,
        logging: (['test1', 'development'].indexOf(config.env) !== -1) ?
            false : logger.db_log,
        dialect: config.db.dialect,
        pool: {
            max: 200
        }
    }
);

var db = {};

var indexOf = [].indexOf || function(item) {
    for (var i = 0, l = this.length; i < l; i++) {
        if (i in this && this[i] === item) {
            return i;
        }
    }
    return -1;
};

fs.readdirSync(__dirname).filter(function(file) {
    return (file.indexOf('.') !== 0) &&
        (indexOf.call(excludeFiles, file) < 0) &&
        (file.slice(-3) === ".js");
}).forEach(function(file) {
    var model;
    model = sequelize["import"](path.join(__dirname, file));
    logger.trace("| Update db model: " + model.name);
    db[model.name] = model;
    return model;
});

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

sequelize.sync().then(function() {
    logger.trace('sync tables finished');
});


export default _.extend({
    sequelize: sequelize,
    Sequelize: Sequelize,
    models: db
});
