고병후

Create post,comment DB

const Sequelize = require('sequelize');
module.exports = class Comment extends Sequelize.Model {
static init(sequelize) {
return super.init({
comment:{
type: Sequelize.TEXT,
allowNull: false,
},
created_at:{
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW,
},
},{
sequelize,
timestamps:false,
underscored:false,
modelName: 'Comment',
tableName:'comments',
paranoid:false,
charset:'utf8',
collate:'utf8_general_ci',
});
}
static associate(db) {}
};
\ No newline at end of file
......@@ -3,6 +3,8 @@ const Sequelize = require('sequelize');
//table(모델)과 연결
const User = require("./user.js");
const Comment = require("./comment.js");
const Post = require("./post.js");
const env = process.env.NODE_ENV || 'development'; //개발버전
const config = require('../config/config.json')[env];
......@@ -14,8 +16,16 @@ const sequelize = new Sequelize(config.database, config.username, config.passwor
db.sequelize = sequelize;
db.User = User;
db.Comment = Comment;
db.Post = Post;
User.init(sequelize);
Comment.init(sequelize);
Post.init(sequelize);
User.associate(db);
Comment.associate(db);
Post.associate(db);
module.exports = db;
......
const Sequelize = require('sequelize');
module.exports = class Post extends Sequelize.Model {
static init(sequelize) {
return super.init({
title:{
type: Sequelize.TEXT,
allowNull: false,
},
post:{
type: Sequelize.TEXT,
allowNull: false,
},
status:{
type: Sequelize.BOOLEAN,
allowNull: false,
},
created_at:{
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.NOW,
},
},{
sequelize,
timestamps:false,
underscored:false,
modelName: 'Post',
tableName:'posts',
paranoid:false,
charset:'utf8',
collate:'utf8_general_ci',
});
}
static associate(db) {}
};
\ No newline at end of file