combine.fm/models/index.js
Jonathan Cremin 7bb0497ff4 Migrate all the things
* Migrates from Mongo to Postgres.
* Migrates from JSPM to Webpack.
* Migrates from React to Vuejs.
* Migrates from Bootstrap to Bulma.

Also:
* Fixes rendering of meta data in the document head tag.
2016-10-23 21:36:23 +01:00

35 lines
745 B
JavaScript

import fs from 'fs';
import path from 'path';
import Sequelize from 'sequelize';
import debugname from 'debug';
const debug = debugname('match.audio:models');
const config = {
dialect: 'postgres',
protocol: 'postgres',
logging: debug,
};
const sequelize = new Sequelize(process.env.DATABASE_URL, config);
const db = {};
fs
.readdirSync(__dirname)
.filter(file => (file.indexOf('.') !== 0) && (file !== 'index.js'))
.forEach((file) => {
const model = sequelize.import(path.join(__dirname, file));
db[model.name] = model;
});
Object.keys(db).forEach((modelName) => {
if ('associate' in db[modelName]) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
export default db;