-- Script para crear tabla certificaciones
USE escuela_futbol;

CREATE TABLE IF NOT EXISTS certificaciones (
    id bigint unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
    deportista_id bigint unsigned NOT NULL,
    tipo_certificacion varchar(255) NOT NULL,
    descripcion longtext,
    fecha_expedicion date NOT NULL,
    fecha_vencimiento date,
    numero_certificado varchar(255) NOT NULL UNIQUE,
    archivo varchar(255),
    estado enum('activa','vencida','cancelada') NOT NULL DEFAULT 'activa',
    registrado_por bigint unsigned,
    created_at timestamp NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    FOREIGN KEY (deportista_id) REFERENCES deportistas(id) ON DELETE CASCADE,
    FOREIGN KEY (registrado_por) REFERENCES users(id) ON DELETE SET NULL,
    INDEX idx_deportista_id (deportista_id),
    INDEX idx_tipo_certificacion (tipo_certificacion),
    INDEX idx_estado (estado)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Registrar migración como ejecutada
INSERT INTO migrations (migration, batch) VALUES ('2026_01_12_create_certificaciones_simple', 1)
ON DUPLICATE KEY UPDATE batch=1;
