The latest version creates a FK column for each association, including a repeat of the pk...
(function(){
/*
* This file defines the database schema.
*/
var Sequelize = require('./sequelize/lib/sequelize/Sequelize').Sequelize,
sequelize = new Sequelize('marketspace', 'root', 'root', {'disableLogging': true, 'port': 8889});
// generate schema
var _bool = {'type': Sequelize.BOOLEAN, 'default': 0, 'allowNull': false},
User = sequelize.define('user', {
'username': Sequelize.STRING,
'email': Sequelize.STRING,
'password': Sequelize.STRING,
'isDeleted': _bool,
'isSpammer': _bool
}),
Status = sequelize.define('status', {
'text': Sequelize.STRING,
'isDeleted': _bool
}),
Notification = sequelize.define('notification', {
'text': Sequelize.STRING,
'isRead': Sequelize.BOOLEAN,
'isDeleted': _bool
}),
Post = sequelize.define('post', {
'title': Sequelize.STRING,
'slug': Sequelize.STRING,
'description': Sequelize.TEXT,
'price': Sequelize.FLOAT,
'isDeleted': _bool,
'isSpam': _bool
}),
Feature = sequelize.define('feature', {
'position': Sequelize.STRING,
'isDeleted': _bool
}),
Location = sequelize.define('location', {
'title': Sequelize.STRING,
'slug': Sequelize.STRING,
'isDeleted': _bool
}),
Category = sequelize.define('category', {
'title': Sequelize.STRING,
'slug': Sequelize.STRING,
'isDeleted': _bool
});
// set associations
User.hasMany('statuses', Status);
Status.belongsTo('user', User);
User.hasMany('notifications', Notification);
Notification.belongsTo('user', User);
User.hasMany('posts', Post);
Post.belongsTo('user', User);
Location.hasMany('posts', Post);
Post.belongsTo('location', Location);
Location.belongsTo('parent', Location);
Category.hasMany('posts', Post);
Post.belongsTo('category', Category);
Category.belongsTo('parent', Category);
// set exports
exports.User = User;
exports.Status = Status;
exports.Notification = Notification;
exports.Post = Post;
exports.Feature = Feature;
exports.Location = Location;
exports.restore = function()
{
sequelize.drop(function(){
sequelize.sync(function(){
console.log('Database schema restored.');
});
});
};
})();