const env = process.env.NODE_ENV || 'development';

const config = require('../config/config')[env];
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');

let sequelize;

const basename = path.basename(module.filename);
const db = {};

if (config.use_env_variable) {
  sequelize = new Sequelize(process.env[config.use_env_variable]);
} else {
  sequelize = new Sequelize(config.database, config.username, config.password, config);
}

function onlyJSFiles(file) {
  return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
}

function importModel(file) {
  const model = sequelize.import(path.join(__dirname, file));
  db[model.name] = model;
}

function assignAssociations(modelName) {
  if (db[modelName].associate) {
    db[modelName].associate(db);
  }
}

fs
  .readdirSync(__dirname)
  .filter(onlyJSFiles)
  .forEach(importModel);

Object.keys(db).forEach(assignAssociations);

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;

@@ -1,113 +1,32 @@
-const env = process.env.NODE_ENV %7C%7C 'development';%0A%0Aconst config = require('../config/config')%5Benv%5D;%0Aconst fs
+'use strict';%0A%0Avar fs       
  = r
@@ -43,18 +43,21 @@
 ');%0A
-const path
+var path     
  = r
@@ -72,21 +72,19 @@
 path');%0A
-const
+var
  Sequeli
@@ -114,30 +114,11 @@
 ');%0A
-%0Alet sequelize;%0A%0Aconst
+var
  bas
@@ -123,16 +123,17 @@
 asename 
+ 
 = path.b
@@ -162,16 +162,144 @@
 e);%0A
-const db
+var env       = process.env.NODE_ENV %7C%7C 'development';%0Avar config    = require(__dirname + '/../config/config.json')%5Benv%5D;%0Avar db       
  = %7B
@@ -331,24 +331,28 @@
 riable) %7B%0A  
+var 
 sequelize = 
@@ -415,16 +415,20 @@
 lse %7B%0A  
+var 
 sequeliz
@@ -513,27 +513,54 @@
 %7D%0A%0Af
-unction onlyJSFiles
+s%0A  .readdirSync(__dirname)%0A  .filter(function
 (fil
@@ -564,16 +564,18 @@
 file) %7B%0A
+  
   return
@@ -659,31 +659,32 @@
 ');%0A
-%7D%0A%0Afunction importModel
+  %7D)%0A  .forEach(function
 (fil
@@ -694,13 +694,13 @@
 %7B%0A  
-const
+  var
  mod
@@ -717,15 +717,18 @@
 lize
-.
+%5B'
 import
+'%5D
 (pat
@@ -753,16 +753,18 @@
 file));%0A
+  
   db%5Bmod
@@ -785,38 +785,47 @@
 el;%0A
-%7D%0A%0Afunction assignAssocia
+  %7D);%0A%0AObject.keys(db).forEach(func
 tion
-s
 (mod
@@ -909,130 +909,8 @@
  %7D%0A%7D
-%0A%0Afs%0A  .readdirSync(__dirname)%0A  .filter(onlyJSFiles)%0A  .forEach(importModel);%0A%0AObject.keys(db).forEach(assignAssociations
 );%0A%0A

Revert "Apply eslint feedback to models/index.js."