"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnsureAttendanceDateColumn1788110000000 = void 0;
class EnsureAttendanceDateColumn1788110000000 {
    constructor() {
        this.name = 'EnsureAttendanceDateColumn1788110000000';
    }
    async up(queryRunner) {
        const hasDateColumn = await queryRunner.query(`SELECT * FROM \`INFORMATION_SCHEMA\`.\`COLUMNS\` WHERE \`TABLE_SCHEMA\` = DATABASE() AND \`TABLE_NAME\` = 'attendances' AND \`COLUMN_NAME\` = 'date'`);
        if (!hasDateColumn || hasDateColumn.length === 0) {
            await queryRunner.query(`ALTER TABLE \`attendances\` ADD \`date\` date NOT NULL DEFAULT (CURRENT_DATE)`);
        }
        const hasIndex = await queryRunner.query(`SELECT * FROM \`INFORMATION_SCHEMA\`.\`STATISTICS\` WHERE \`TABLE_SCHEMA\` = DATABASE() AND \`TABLE_NAME\` = 'attendances' AND \`INDEX_NAME\` = 'IDX_attendances_member_date'`);
        if (!hasIndex || hasIndex.length === 0) {
            try {
                await queryRunner.query(`ALTER TABLE \`attendances\` ADD UNIQUE INDEX \`IDX_attendances_member_date\` (\`member_id\`, \`date\`)`);
            }
            catch (e) {
            }
        }
    }
    async down(queryRunner) {
        const hasDateColumn = await queryRunner.query(`SELECT * FROM \`INFORMATION_SCHEMA\`.\`COLUMNS\` WHERE \`TABLE_SCHEMA\` = DATABASE() AND \`TABLE_NAME\` = 'attendances' AND \`COLUMN_NAME\` = 'date'`);
        if (hasDateColumn && hasDateColumn.length > 0) {
            await queryRunner.query(`ALTER TABLE \`attendances\` DROP COLUMN \`date\``);
        }
    }
}
exports.EnsureAttendanceDateColumn1788110000000 = EnsureAttendanceDateColumn1788110000000;
//# sourceMappingURL=1788110000000-EnsureAttendanceDateColumn.js.map