-- 创建邀请码申请表
CREATE TABLE IF NOT EXISTS `admin_invite_code_applications` (
    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `email` VARCHAR(255) NOT NULL COMMENT '申请邮箱',
    `reason` TEXT COMMENT '申请理由',
    `status` VARCHAR(20) NOT NULL DEFAULT 'pending' COMMENT '申请状态:pending-待处理,approved-已通过,rejected-已拒绝',
    `invite_code_id` INT UNSIGNED COMMENT '关联的邀请码ID',
    `reject_reason` TEXT COMMENT '拒绝理由',
    `approved_at` DATETIME COMMENT '审批时间',
    `approved_by` VARCHAR(64) COMMENT '审批人',
    `email_sent_at` DATETIME COMMENT '邮件发送时间',
    `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
    `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
    `deleted_at` DATETIME COMMENT '软删除时间',
    PRIMARY KEY (`id`),
    INDEX `idx_email` (`email`),
    INDEX `idx_status` (`status`),
    INDEX `idx_deleted_at` (`deleted_at`),
    CONSTRAINT `fk_invite_code_id` FOREIGN KEY (`invite_code_id`) REFERENCES `admin_invite_codes`(`id`) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='邀请码申请表';