import { MigrationInterface, QueryRunner } from "typeorm";

export class NewDatabaseConnection1788084818324 implements MigrationInterface {
    name = 'NewDatabaseConnection1788084818324'

    public async up(queryRunner: QueryRunner): Promise<void> {
        const hasCol = await queryRunner.hasColumn('attendances', 'checkout_reminder_sent');
        if (!hasCol) {
            await queryRunner.query(`ALTER TABLE \`attendances\` ADD \`checkout_reminder_sent\` tinyint NOT NULL DEFAULT 0`);
        }
        const hasColAt = await queryRunner.hasColumn('attendances', 'checkout_reminder_sent_at');
        if (!hasColAt) {
            await queryRunner.query(`ALTER TABLE \`attendances\` ADD \`checkout_reminder_sent_at\` datetime NULL`);
        }
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        const hasColAt = await queryRunner.hasColumn('attendances', 'checkout_reminder_sent_at');
        if (hasColAt) {
            await queryRunner.query(`ALTER TABLE \`attendances\` DROP COLUMN \`checkout_reminder_sent_at\``);
        }
        const hasCol = await queryRunner.hasColumn('attendances', 'checkout_reminder_sent');
        if (hasCol) {
            await queryRunner.query(`ALTER TABLE \`attendances\` DROP COLUMN \`checkout_reminder_sent\``);
        }
    }

}
