hrms-api-org/src/migration/1710220097101-add_table_employees.ts
2024-03-12 12:14:18 +07:00

24 lines
5.4 KiB
TypeScript

import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableEmployees1710220097101 implements MigrationInterface {
name = 'AddTableEmployees1710220097101'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`employeePosType\` (\`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', \`posTypeName\` varchar(255) NULL COMMENT 'ชื่อกลุ่มงาน', \`posTypeRank\` int NOT NULL COMMENT 'ระดับของกลุ่มงาน', \`posTypeShortName\` varchar(255) NULL COMMENT 'ชื่อย่อกลุ่มงาน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`employeePosDict\` (\`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', \`posDictName\` varchar(255) NULL COMMENT 'ชื่อตำแหน่ง', \`employeePosTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosType', \`employeePosLevelId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosLevel', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`employeePosLevel\` (\`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', \`posLevelName\` varchar(255) NULL COMMENT 'ชื่อระดับชั้นงาน', \`posLevelRank\` int NOT NULL COMMENT 'ระดับของระดับชั้นงาน', \`employeePosTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosType', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`employeePosDict\` ADD CONSTRAINT \`FK_73ad56ef383399f567d58b213e2\` FOREIGN KEY (\`employeePosTypeId\`) REFERENCES \`employeePosType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`employeePosDict\` ADD CONSTRAINT \`FK_28d45cec912604b7d6f3dfac39a\` FOREIGN KEY (\`employeePosLevelId\`) REFERENCES \`employeePosLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`employeePosLevel\` ADD CONSTRAINT \`FK_a822851af7b58288be65debfdd5\` FOREIGN KEY (\`employeePosTypeId\`) REFERENCES \`employeePosType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`employeePosLevel\` DROP FOREIGN KEY \`FK_a822851af7b58288be65debfdd5\``);
await queryRunner.query(`ALTER TABLE \`employeePosDict\` DROP FOREIGN KEY \`FK_28d45cec912604b7d6f3dfac39a\``);
await queryRunner.query(`ALTER TABLE \`employeePosDict\` DROP FOREIGN KEY \`FK_73ad56ef383399f567d58b213e2\``);
await queryRunner.query(`DROP TABLE \`employeePosLevel\``);
await queryRunner.query(`DROP TABLE \`employeePosDict\``);
await queryRunner.query(`DROP TABLE \`employeePosType\``);
}
}