93 lines
2.1 KiB
JavaScript
93 lines
2.1 KiB
JavaScript
"use strict";
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await queryInterface.createTable("ForumComments", {
|
|
id: {
|
|
type: Sequelize.UUID,
|
|
defaultValue: Sequelize.UUIDV4,
|
|
primaryKey: true,
|
|
},
|
|
postId: {
|
|
type: Sequelize.UUID,
|
|
allowNull: false,
|
|
references: {
|
|
model: "ForumPosts",
|
|
key: "id",
|
|
},
|
|
onUpdate: "CASCADE",
|
|
onDelete: "CASCADE",
|
|
},
|
|
authorId: {
|
|
type: Sequelize.UUID,
|
|
allowNull: false,
|
|
references: {
|
|
model: "Users",
|
|
key: "id",
|
|
},
|
|
onUpdate: "CASCADE",
|
|
onDelete: "CASCADE",
|
|
},
|
|
parentCommentId: {
|
|
type: Sequelize.UUID,
|
|
allowNull: true,
|
|
references: {
|
|
model: "ForumComments",
|
|
key: "id",
|
|
},
|
|
onUpdate: "CASCADE",
|
|
onDelete: "SET NULL",
|
|
},
|
|
content: {
|
|
type: Sequelize.TEXT,
|
|
allowNull: false,
|
|
},
|
|
images: {
|
|
type: Sequelize.ARRAY(Sequelize.TEXT),
|
|
allowNull: true,
|
|
defaultValue: [],
|
|
},
|
|
isDeleted: {
|
|
type: Sequelize.BOOLEAN,
|
|
defaultValue: false,
|
|
},
|
|
deletedBy: {
|
|
type: Sequelize.UUID,
|
|
allowNull: true,
|
|
references: {
|
|
model: "Users",
|
|
key: "id",
|
|
},
|
|
onUpdate: "CASCADE",
|
|
onDelete: "SET NULL",
|
|
},
|
|
deletedAt: {
|
|
type: Sequelize.DATE,
|
|
allowNull: true,
|
|
},
|
|
deletionReason: {
|
|
type: Sequelize.TEXT,
|
|
allowNull: true,
|
|
},
|
|
createdAt: {
|
|
type: Sequelize.DATE,
|
|
allowNull: false,
|
|
},
|
|
updatedAt: {
|
|
type: Sequelize.DATE,
|
|
allowNull: false,
|
|
},
|
|
});
|
|
|
|
// Add indexes
|
|
await queryInterface.addIndex("ForumComments", ["postId"]);
|
|
await queryInterface.addIndex("ForumComments", ["authorId"]);
|
|
await queryInterface.addIndex("ForumComments", ["parentCommentId"]);
|
|
await queryInterface.addIndex("ForumComments", ["isDeleted"]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.dropTable("ForumComments");
|
|
},
|
|
};
|