import { MigrationInterface, QueryRunner } from "typeorm";

export class AddTablePosMaster31706697236690 implements MigrationInterface {
    name = 'AddTablePosMaster31706697236690'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_0564eef8bec8347d6b782a67537\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_685b7779aa6d8897d5f3c899bf2\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_838fef6a73e9cc70147b8f85bf7\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild2\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild3OrgChild3Id\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild4\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`posMasterNo\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`posMasterNo\` int NULL COMMENT 'เลขที่ตำแหน่ง เป็นตัวเลข'`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_a0a64249023284376a480fc27ef\` FOREIGN KEY (\`orgChild2Id\`) REFERENCES \`orgChild2\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_25526f064b7ea43dd443954646b\` FOREIGN KEY (\`orgChild3Id\`) REFERENCES \`orgChild3\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_5d11d2c4513d606c8db997e5e65\` FOREIGN KEY (\`orgChild4Id\`) REFERENCES \`orgChild4\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_5d11d2c4513d606c8db997e5e65\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_25526f064b7ea43dd443954646b\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_a0a64249023284376a480fc27ef\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`posMasterNo\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`posMasterNo\` varchar(16) NULL COMMENT 'เลขที่ตำแหน่ง เป็นตัวเลข' DEFAULT 'string'`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild4\` varchar(36) NULL`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild3OrgChild3Id\` varchar(36) NULL`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild2\` varchar(36) NULL`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_838fef6a73e9cc70147b8f85bf7\` FOREIGN KEY (\`orgChild3OrgChild3Id\`) REFERENCES \`orgChild3\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_685b7779aa6d8897d5f3c899bf2\` FOREIGN KEY (\`orgChild2\`) REFERENCES \`orgChild2\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_0564eef8bec8347d6b782a67537\` FOREIGN KEY (\`orgChild4\`) REFERENCES \`orgChild4\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

}
