import { MigrationInterface, QueryRunner } from "typeorm";

export class AddTableEmployeePosition11710330337194 implements MigrationInterface {
    name = 'AddTableEmployeePosition11710330337194'

    public async up(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(`ALTER TABLE \`employeePosLevel\` CHANGE \`employeePosTypeId\` \`posTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosType'`);
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` DROP COLUMN \`employeePosTypeId\``);
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` DROP COLUMN \`employeePosLevelId\``);
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` ADD \`posTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosType'`);
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` ADD \`posLevelId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosLevel'`);
        await queryRunner.query(`ALTER TABLE \`employeePosLevel\` ADD CONSTRAINT \`FK_7fb9ab868f3f46b44f460c984f1\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`employeePosType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` ADD CONSTRAINT \`FK_63e8a14abd222c948e0e175e941\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`employeePosType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` ADD CONSTRAINT \`FK_73da087c2ee4b6e74c9590ae3a2\` FOREIGN KEY (\`posLevelId\`) REFERENCES \`employeePosLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` DROP FOREIGN KEY \`FK_73da087c2ee4b6e74c9590ae3a2\``);
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` DROP FOREIGN KEY \`FK_63e8a14abd222c948e0e175e941\``);
        await queryRunner.query(`ALTER TABLE \`employeePosLevel\` DROP FOREIGN KEY \`FK_7fb9ab868f3f46b44f460c984f1\``);
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` DROP COLUMN \`posLevelId\``);
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` DROP COLUMN \`posTypeId\``);
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` ADD \`employeePosLevelId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosLevel'`);
        await queryRunner.query(`ALTER TABLE \`employeePosDict\` ADD \`employeePosTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosType'`);
        await queryRunner.query(`ALTER TABLE \`employeePosLevel\` CHANGE \`posTypeId\` \`employeePosTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosType'`);
        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`);
    }

}
