Skip to content

Commit

Permalink
Merge c088d5f into 87652d1
Browse files Browse the repository at this point in the history
  • Loading branch information
danprocoder authored Mar 5, 2019
2 parents 87652d1 + c088d5f commit 065f4ef
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export default {
up(queryInterface, Sequelize) {
return queryInterface.createTable('ArticleComments', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
articleId: {
type: Sequelize.INTEGER,
allowNull: false,
},
userId: {
type: Sequelize.INTEGER,
allowNull: false,
},
comment: {
type: Sequelize.STRING,
allowNull: false,
},
totalLikes: {
type: Sequelize.INTEGER,
defaultValue: 0,
allowNull: false,
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
}
});
},
down(queryInterface, Sequelize) {
return queryInterface.dropTable('ArticleComments');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export default {
up(queryInterface, Sequelize) {
return queryInterface.createTable('ArticleCommentLikes', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
articleId: {
type: Sequelize.INTEGER,
allowNull: false,
},
commentId: {
type: Sequelize.INTEGER,
allowNull: false,
},
userId: {
type: Sequelize.INTEGER,
allowNull: false,
},
createdAt: {
allowNull: false,
type: Sequelize.DATE,
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE,
}
});
},
down(queryInterface, Sequelize) {
return queryInterface.dropTable('ArticleCommentLikes');
}
};
3 changes: 3 additions & 0 deletions server/database/models/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default (sequelize, DataTypes) => {
Article.belongsTo(models.User, {
foreignKey: 'userId',
});
Article.hasMany(models.ArticleComment, {
foreignKey: 'id',
});
};
return Article;
};
17 changes: 17 additions & 0 deletions server/database/models/articlecomment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default (sequelize, DataTypes) => {
const ArticleComment = sequelize.define('ArticleComment', {
articleId: DataTypes.INTEGER,
userId: DataTypes.INTEGER,
comment: DataTypes.STRING,
totalLikes: DataTypes.INTEGER
}, {});
ArticleComment.associate = (models) => {
ArticleComment.belongsTo(models.User, {
foreignKey: 'userId',
});
ArticleComment.belongsTo(models.Article, {
foreignKey: 'articleId',
});
};
return ArticleComment;
};
16 changes: 16 additions & 0 deletions server/database/models/articlecommentlike.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default (sequelize, DataTypes) => {
const ArticleCommentLike = sequelize.define('ArticleCommentLike', {
articleId: DataTypes.INTEGER,
commentId: DataTypes.INTEGER,
userId: DataTypes.INTEGER
}, {});
ArticleCommentLike.associate = (models) => {
ArticleCommentLike.belongsTo(models.User, {
foreignKey: 'userId',
});
ArticleCommentLike.belongsTo(models.ArticleComment, {
foreignKey: 'commentId',
});
};
return ArticleCommentLike;
};
7 changes: 7 additions & 0 deletions server/database/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ export default (sequelize, DataTypes) => {
as: 'followers'
});

// Relations for articles.
User.hasMany(models.Article, {
foreignKey: 'id',
});
User.hasMany(models.ArticleComment, {
foreignKey: 'id',
});
User.hasMany(models.ArticleCommentLike, {
foreignKey: 'id',
});
};
return User;
};

0 comments on commit 065f4ef

Please sign in to comment.