import { MigrationInterface, QueryRunner } from "typeorm";

export class AddTableWorkflow31728465477520 implements MigrationInterface {
    name = 'AddTableWorkflow31728465477520'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP FOREIGN KEY \`FK_bef7391c37f03a3b809406beebf\``);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`stateOperatorId\``);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`type\``);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`operator\` varchar(255) NULL COMMENT 'ผู้ดำเนินการ'`);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`refId\` varchar(255) NULL COMMENT 'ผู้ดำเนินการ'`);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`workflowId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง workflow'`);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD CONSTRAINT \`FK_9499ff9ae0444f59f19800aca05\` FOREIGN KEY (\`workflowId\`) REFERENCES \`workflow\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP FOREIGN KEY \`FK_9499ff9ae0444f59f19800aca05\``);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`workflowId\``);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`refId\``);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` DROP COLUMN \`operator\``);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`type\` varchar(255) NULL`);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD \`stateOperatorId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง stateOperator'`);
        await queryRunner.query(`ALTER TABLE \`stateOperatorUser\` ADD CONSTRAINT \`FK_bef7391c37f03a3b809406beebf\` FOREIGN KEY (\`stateOperatorId\`) REFERENCES \`stateOperator\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

}
