From 8fc269c62a5712efd6a4772dafb41446854b435b Mon Sep 17 00:00:00 2001 From: jackiettran <41605212+jackiettran@users.noreply.github.com> Date: Tue, 25 Nov 2025 17:24:34 -0500 Subject: [PATCH] migration files --- .../20241124000008-create-forum-posts.js | 129 ++++++++++++++++++ .../20241124000009-create-forum-comments.js | 92 +++++++++++++ ...0010-add-accepted-answer-to-forum-posts.js | 25 ++++ .../20241124000011-create-post-tags.js | 43 ++++++ .../20241124000012-create-feedback.js | 50 +++++++ 5 files changed, 339 insertions(+) create mode 100644 backend/migrations/20241124000008-create-forum-posts.js create mode 100644 backend/migrations/20241124000009-create-forum-comments.js create mode 100644 backend/migrations/20241124000010-add-accepted-answer-to-forum-posts.js create mode 100644 backend/migrations/20241124000011-create-post-tags.js create mode 100644 backend/migrations/20241124000012-create-feedback.js diff --git a/backend/migrations/20241124000008-create-forum-posts.js b/backend/migrations/20241124000008-create-forum-posts.js new file mode 100644 index 0000000..ebffb37 --- /dev/null +++ b/backend/migrations/20241124000008-create-forum-posts.js @@ -0,0 +1,129 @@ +"use strict"; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.createTable("ForumPosts", { + id: { + type: Sequelize.UUID, + defaultValue: Sequelize.UUIDV4, + primaryKey: true, + }, + authorId: { + type: Sequelize.UUID, + allowNull: false, + references: { + model: "Users", + key: "id", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }, + title: { + type: Sequelize.STRING, + allowNull: false, + }, + content: { + type: Sequelize.TEXT, + allowNull: false, + }, + category: { + type: Sequelize.ENUM( + "item_request", + "technical_support", + "community_resources", + "general_discussion" + ), + allowNull: false, + defaultValue: "general_discussion", + }, + status: { + type: Sequelize.ENUM("open", "answered", "closed"), + defaultValue: "open", + }, + viewCount: { + type: Sequelize.INTEGER, + defaultValue: 0, + }, + commentCount: { + type: Sequelize.INTEGER, + defaultValue: 0, + }, + zipCode: { + type: Sequelize.STRING, + }, + latitude: { + type: Sequelize.DECIMAL(10, 8), + }, + longitude: { + type: Sequelize.DECIMAL(11, 8), + }, + acceptedAnswerId: { + type: Sequelize.UUID, + allowNull: true, + }, + images: { + type: Sequelize.ARRAY(Sequelize.TEXT), + allowNull: true, + defaultValue: [], + }, + isPinned: { + type: Sequelize.BOOLEAN, + defaultValue: false, + }, + 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, + }, + closedBy: { + type: Sequelize.UUID, + allowNull: true, + references: { + model: "Users", + key: "id", + }, + onUpdate: "CASCADE", + onDelete: "SET NULL", + }, + closedAt: { + type: Sequelize.DATE, + allowNull: true, + }, + createdAt: { + type: Sequelize.DATE, + allowNull: false, + }, + updatedAt: { + type: Sequelize.DATE, + allowNull: false, + }, + }); + + // Add indexes + await queryInterface.addIndex("ForumPosts", ["authorId"]); + await queryInterface.addIndex("ForumPosts", ["category"]); + await queryInterface.addIndex("ForumPosts", ["status"]); + await queryInterface.addIndex("ForumPosts", ["isDeleted"]); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.dropTable("ForumPosts"); + }, +}; diff --git a/backend/migrations/20241124000009-create-forum-comments.js b/backend/migrations/20241124000009-create-forum-comments.js new file mode 100644 index 0000000..b6a5a3d --- /dev/null +++ b/backend/migrations/20241124000009-create-forum-comments.js @@ -0,0 +1,92 @@ +"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"); + }, +}; diff --git a/backend/migrations/20241124000010-add-accepted-answer-to-forum-posts.js b/backend/migrations/20241124000010-add-accepted-answer-to-forum-posts.js new file mode 100644 index 0000000..5348fce --- /dev/null +++ b/backend/migrations/20241124000010-add-accepted-answer-to-forum-posts.js @@ -0,0 +1,25 @@ +"use strict"; + +module.exports = { + up: async (queryInterface, Sequelize) => { + // Add foreign key constraint for acceptedAnswerId + await queryInterface.addConstraint("ForumPosts", { + fields: ["acceptedAnswerId"], + type: "foreign key", + name: "ForumPosts_acceptedAnswerId_fkey", + references: { + table: "ForumComments", + field: "id", + }, + onDelete: "SET NULL", + onUpdate: "CASCADE", + }); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.removeConstraint( + "ForumPosts", + "ForumPosts_acceptedAnswerId_fkey" + ); + }, +}; diff --git a/backend/migrations/20241124000011-create-post-tags.js b/backend/migrations/20241124000011-create-post-tags.js new file mode 100644 index 0000000..8c92067 --- /dev/null +++ b/backend/migrations/20241124000011-create-post-tags.js @@ -0,0 +1,43 @@ +"use strict"; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.createTable("PostTags", { + id: { + type: Sequelize.UUID, + defaultValue: Sequelize.UUIDV4, + primaryKey: true, + }, + postId: { + type: Sequelize.UUID, + allowNull: false, + references: { + model: "ForumPosts", + key: "id", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }, + tagName: { + type: Sequelize.STRING, + allowNull: false, + }, + createdAt: { + type: Sequelize.DATE, + allowNull: false, + }, + updatedAt: { + type: Sequelize.DATE, + allowNull: false, + }, + }); + + // Add indexes + await queryInterface.addIndex("PostTags", ["postId"]); + await queryInterface.addIndex("PostTags", ["tagName"]); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.dropTable("PostTags"); + }, +}; diff --git a/backend/migrations/20241124000012-create-feedback.js b/backend/migrations/20241124000012-create-feedback.js new file mode 100644 index 0000000..22e28bb --- /dev/null +++ b/backend/migrations/20241124000012-create-feedback.js @@ -0,0 +1,50 @@ +"use strict"; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.createTable("Feedbacks", { + id: { + type: Sequelize.UUID, + defaultValue: Sequelize.UUIDV4, + primaryKey: true, + }, + userId: { + type: Sequelize.UUID, + allowNull: false, + references: { + model: "Users", + key: "id", + }, + onUpdate: "CASCADE", + onDelete: "CASCADE", + }, + feedbackText: { + type: Sequelize.TEXT, + allowNull: false, + }, + userAgent: { + type: Sequelize.STRING, + allowNull: true, + }, + url: { + type: Sequelize.STRING(500), + allowNull: true, + }, + createdAt: { + type: Sequelize.DATE, + allowNull: false, + }, + updatedAt: { + type: Sequelize.DATE, + allowNull: false, + }, + }); + + // Add indexes + await queryInterface.addIndex("Feedbacks", ["userId"]); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.dropTable("Feedbacks"); + }, +};