import { MigrationInterface, QueryRunner } from "typeorm";

export class CreateAuthTables1763027698763 implements MigrationInterface {
    name = 'CreateAuthTables1763027698763'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`CREATE TABLE \`TokenBlacklist\` (\`id\` varchar(36) NOT NULL, \`token\` varchar(1000) NOT NULL, \`userId\` varchar(255) NOT NULL, \`expiresAt\` timestamp NOT NULL, \`reason\` varchar(255) NULL, \`created_at\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, INDEX \`IDX_28ba9c02cf4223e3500cfac9a2\` (\`token\`), PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
        await queryRunner.query(`CREATE TABLE \`RefreshToken\` (\`id\` varchar(36) NOT NULL, \`token\` varchar(1000) NOT NULL, \`userId\` varchar(255) NOT NULL, \`expiresAt\` timestamp NOT NULL, \`isRevoked\` tinyint NOT NULL DEFAULT 0, \`createdByIp\` varchar(255) NULL, \`created_at\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, \`updated_at\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
        await queryRunner.query(`ALTER TABLE \`Disclaimer\` DROP COLUMN \`image\``);
        await queryRunner.query(`ALTER TABLE \`countries\` DROP COLUMN \`country_name\``);
        await queryRunner.query(`ALTER TABLE \`countries\` ADD \`country_name\` varchar(255) NOT NULL`);
        await queryRunner.query(`ALTER TABLE \`states\` DROP COLUMN \`state_name\``);
        await queryRunner.query(`ALTER TABLE \`states\` ADD \`state_name\` varchar(255) NOT NULL`);
        await queryRunner.query(`ALTER TABLE \`cities\` DROP COLUMN \`city_name\``);
        await queryRunner.query(`ALTER TABLE \`cities\` ADD \`city_name\` varchar(255) NOT NULL`);
        await queryRunner.query(`ALTER TABLE \`Testimonials\` CHANGE \`isActive\` \`isActive\` tinyint NOT NULL DEFAULT 1`);
        await queryRunner.query(`ALTER TABLE \`HowItWorksSteps\` CHANGE \`isActive\` \`isActive\` tinyint NOT NULL DEFAULT 1`);
        await queryRunner.query(`ALTER TABLE \`EducationCourses\` CHANGE \`isActive\` \`isActive\` tinyint NOT NULL DEFAULT 1`);
        await queryRunner.query(`ALTER TABLE \`Disclaimer\` DROP COLUMN \`content\``);
        await queryRunner.query(`ALTER TABLE \`Disclaimer\` ADD \`content\` text NOT NULL`);
        await queryRunner.query(`ALTER TABLE \`Disclaimer\` CHANGE \`isActive\` \`isActive\` tinyint NOT NULL DEFAULT 1`);
        await queryRunner.query(`ALTER TABLE \`RefreshToken\` ADD CONSTRAINT \`FK_3a4d068289fa6c2038fb2101e5b\` FOREIGN KEY (\`userId\`) REFERENCES \`User\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE \`RefreshToken\` DROP FOREIGN KEY \`FK_3a4d068289fa6c2038fb2101e5b\``);
        await queryRunner.query(`ALTER TABLE \`Disclaimer\` CHANGE \`isActive\` \`isActive\` tinyint(1) NOT NULL DEFAULT '1'`);
        await queryRunner.query(`ALTER TABLE \`Disclaimer\` DROP COLUMN \`content\``);
        await queryRunner.query(`ALTER TABLE \`Disclaimer\` ADD \`content\` longtext CHARACTER SET "utf8mb4" COLLATE "utf8mb4_unicode_ci" NULL`);
        await queryRunner.query(`ALTER TABLE \`EducationCourses\` CHANGE \`isActive\` \`isActive\` tinyint(1) NOT NULL DEFAULT '1'`);
        await queryRunner.query(`ALTER TABLE \`HowItWorksSteps\` CHANGE \`isActive\` \`isActive\` tinyint(1) NOT NULL DEFAULT '1'`);
        await queryRunner.query(`ALTER TABLE \`Testimonials\` CHANGE \`isActive\` \`isActive\` tinyint(1) NOT NULL DEFAULT '1'`);
        await queryRunner.query(`ALTER TABLE \`cities\` DROP COLUMN \`city_name\``);
        await queryRunner.query(`ALTER TABLE \`cities\` ADD \`city_name\` varchar(30) CHARACTER SET "utf8" COLLATE "utf8_unicode_ci" NOT NULL`);
        await queryRunner.query(`ALTER TABLE \`states\` DROP COLUMN \`state_name\``);
        await queryRunner.query(`ALTER TABLE \`states\` ADD \`state_name\` varchar(30) CHARACTER SET "utf8" COLLATE "utf8_unicode_ci" NOT NULL`);
        await queryRunner.query(`ALTER TABLE \`countries\` DROP COLUMN \`country_name\``);
        await queryRunner.query(`ALTER TABLE \`countries\` ADD \`country_name\` varchar(30) CHARACTER SET "utf8" COLLATE "utf8_general_ci" NOT NULL`);
        await queryRunner.query(`ALTER TABLE \`Disclaimer\` ADD \`image\` text NULL`);
        await queryRunner.query(`DROP TABLE \`RefreshToken\``);
        await queryRunner.query(`DROP INDEX \`IDX_28ba9c02cf4223e3500cfac9a2\` ON \`TokenBlacklist\``);
        await queryRunner.query(`DROP TABLE \`TokenBlacklist\``);
    }

}
