Files
PetitTeton/models/index.js
Wynne Crisman 0a7cff6672 Merged PetitTeton webapp with the inventory tracking app; Moved the database configuration out of git and added an example configuration; Added migrations to the mix so that we can easily update the production database and roll back changes to the database (from the command line install migrations [may not be necessary?]:
npm install -g sequelize-cli

To update the database after updating the app from git (on the command line in the webapp base directory):
sequelize db:migrate

To undo the last migrations:
sequelize db:migrate:undo
2016-06-13 11:54:12 -07:00

32 lines
899 B
JavaScript

"use strict";
var fs = require("fs");
var path = require("path");
var Sequelize = require("sequelize");
var env = process.env.NODE_ENV || "development";
//var config = require(__dirname + '/../config/config.json')[env];
var configDB = require('./../config/database.js');
//var sequelize = new Sequelize(config.database, config.username, config.password, config);
var sequelize = new Sequelize(configDB.url);
var db = {};
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);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;