create attachment file table
This commit is contained in:
38
backend/migrations/20240316200815-create-attachments.js
Normal file
38
backend/migrations/20240316200815-create-attachments.js
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up (queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('attachments', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
title: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
detail: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
path: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
async down (queryInterface, Sequelize) {
|
||||
await queryInterface.dropTable('attachments');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.createTable("caseAttachments", {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
caseId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: "cases",
|
||||
key: "id",
|
||||
},
|
||||
onUpdate: "CASCADE",
|
||||
onDelete: "CASCADE",
|
||||
},
|
||||
attachmentId: {
|
||||
type: Sequelize.INTEGER,
|
||||
references: {
|
||||
model: "attachments",
|
||||
key: "id",
|
||||
},
|
||||
onUpdate: "CASCADE",
|
||||
onDelete: "CASCADE",
|
||||
},
|
||||
createdAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
updatedAt: {
|
||||
type: Sequelize.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
await queryInterface.addIndex("caseAttachments", ["caseId", "attachmentId"], {
|
||||
unique: true,
|
||||
});
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.dropTable("caseAttachments");
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user