import { MigrationInterface, QueryRunner } from "typeorm";

export class AddTablePosMaster21706696231054 implements MigrationInterface {
    name = 'AddTablePosMaster21706696231054'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild2\` varchar(36) NULL`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild3OrgChild3Id\` varchar(36) NULL`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild4\` varchar(36) NULL`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgRootId\` \`orgRootId\` varchar(40) NULL`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild1Id\` \`orgChild1Id\` varchar(40) NULL`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild2Id\` \`orgChild2Id\` varchar(40) NULL`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild3Id\` \`orgChild3Id\` varchar(40) NULL`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild4Id\` \`orgChild4Id\` varchar(40) NULL`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_7da46fc341b77ebd43f28a8cf47\` FOREIGN KEY (\`orgRootId\`) REFERENCES \`orgRoot\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_7e3ee4640d067c5563c060e2c6b\` FOREIGN KEY (\`orgChild1Id\`) REFERENCES \`orgChild1\`(\`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_838fef6a73e9cc70147b8f85bf7\` FOREIGN KEY (\`orgChild3OrgChild3Id\`) REFERENCES \`orgChild3\`(\`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`);
    }

    public async down(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_838fef6a73e9cc70147b8f85bf7\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_685b7779aa6d8897d5f3c899bf2\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_7e3ee4640d067c5563c060e2c6b\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_7da46fc341b77ebd43f28a8cf47\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild4Id\` \`orgChild4Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild3Id\` \`orgChild3Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild2Id\` \`orgChild2Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild1Id\` \`orgChild1Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgRootId\` \`orgRootId\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild4\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild3OrgChild3Id\``);
        await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild2\``);
    }

}
