diff --git a/src/migration/1744973794458-update_and_add_table.ts b/src/migration/1744973794458-update_and_add_table.ts new file mode 100644 index 0000000..1f33527 --- /dev/null +++ b/src/migration/1744973794458-update_and_add_table.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateAndAddTable1744973794458 implements MigrationInterface { + name = 'UpdateAndAddTable1744973794458' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`performance\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`evaluationId\` varchar(40) NOT NULL COMMENT 'Id การทำรายการระบบประเมิน' DEFAULT '00000000-0000-0000-0000-000000000000', \`year\` int NULL COMMENT 'ปีที่ประเมิน', \`type\` varchar(255) NULL COMMENT 'ประเภทที่ร้องขอประเมิน', \`subject\` varchar(255) NULL COMMENT 'ชื่อผลงาน', \`evaluationResult\` varchar(255) NULL COMMENT 'ผลการประเมิน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`performance\` ADD CONSTRAINT \`FK_edf8c1deb31d77afecfc646615a\` FOREIGN KEY (\`evaluationId\`) REFERENCES \`evaluation\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`performance\` DROP FOREIGN KEY \`FK_edf8c1deb31d77afecfc646615a\``); + await queryRunner.query(`DROP TABLE \`performance\``); + } + +}