USE certimine; INSERT IGNORE INTO frm_standard (code, name_en, name_es, sort_order, doc_url, description_en, description_es) VALUES ('FRM_CONFINED', 'FRM - Confined Spaces', 'FRM - Espacios confinados', 10, NULL, 'Consultation standard — link to corporate library.', 'Estándar de consulta — enlace a biblioteca corporativa.'), ('FRM_BARRICADAS', 'FRM - Barricades and Exclusion Zones', 'FRM - Barricadas y Zonas de Exclusión', 20, NULL, NULL, NULL), ('FRM_TERRENO', 'FRM - Surface Ground Control', 'FRM - Control de Terreno Superficial', 30, NULL, NULL, NULL), ('FRM_ENERGIA', 'FRM - Stored Energy Management', 'FRM - Gestión de Energía Almacenada', 40, NULL, NULL, NULL), ('FRM_GRUAS', 'FRM - Cranes and Lifting', 'FRM - Grúas y Levantamiento', 50, NULL, NULL, NULL), ('FRM_SALUD', 'FRM - Health and Hygiene (site exposures)', 'FRM - Salud e Higiene por exposiciones en sitio', 60, NULL, NULL, NULL), ('FRM_MATPEL', 'FRM - Hazardous Materials', 'FRM - Materiales Peligrosos', 70, NULL, NULL, NULL), ('FRM_ELEC', 'FRM - Electrical Safety', 'FRM - Seguridad Eléctrica', 80, NULL, NULL, NULL), ('FRM_ALTURAS', 'FRM - Work at Heights', 'FRM - Trabajo en Alturas', 90, NULL, NULL, NULL), ('FRM_VEHICULOS', 'FRM - Vehicles and Driving', 'FRM - Vehículos y Manejo', 100, NULL, NULL, NULL), ('FRM_AVIACION', 'FRM - Loss of Aviation Control', 'FRM - Perdida de Control de Aviación', 110, NULL, NULL, NULL); INSERT IGNORE INTO nom_competency (code, name_en, name_es, sort_order) VALUES ('NOM-001', 'Buildings, premises and facilities', 'Edificios, locales e instalaciones', 1), ('NOM-002', 'Fire prevention and protection', 'Prevención y protección contra incendios', 2), ('NOM-004', 'Safety systems and devices in machinery', 'Sistemas y dispositivos de seguridad en maquinaria', 4), ('NOM-005', 'Handling, transport and storage of hazardous substances', 'Manejo, transporte y almacenamiento de sustancias peligrosas', 5), ('NOM-006', 'Handling and storage of materials', 'Manejo y almacenamiento de materiales', 6), ('NOM-009', 'Working at heights', 'Trabajos en altura', 9), ('NOM-010', 'Chemical pollutants', 'Contaminantes por sustancias químicas', 10), ('NOM-011', 'Noise', 'Ruido', 11), ('NOM-012', 'Conditions and risks from ionizing radiation', 'Condiciones y Riesgos por Exposición a Fuentes de Radiación Ionizante', 12), ('NOM-013', 'Non-ionizing radiation', 'Radiaciones no ionizantes', 13), ('NOM-015', 'High or low temperature conditions', 'Condiciones térmicas elevadas o abatidas', 15), ('NOM-017', 'Personal protective equipment', 'Equipo de protección personal', 17), ('NOM-018', 'Hazard and risk identification (chemical)', 'Identificación de peligros y riesgos por sustancias químicas', 18), ('NOM-019', 'Safety and hygiene committees', 'Comisiones de seguridad e higiene', 19), ('NOM-020', 'Pressure vessels and boilers', 'Recipientes sujetos a presión y calderas', 20), ('NOM-022', 'Static electricity', 'Electricidad estática', 22), ('NOM-023', 'Work in underground and open-pit mines', 'Trabajos en minas subterráneas y a cielo abierto', 23), ('NOM-024', 'Vibrations', 'Vibraciones', 24), ('NOM-025', 'Lighting', 'Iluminación', 25), ('NOM-026', 'Colors and safety signs', 'Colores y señales de seguridad', 26), ('NOM-027', 'Welding and cutting', 'Soldadura y corte', 27), ('NOM-029', 'Maintenance of electrical installations', 'Mantenimiento de instalaciones eléctricas', 29), ('NOM-030', 'Preventive safety and health services', 'Servicios preventivos de seguridad y salud', 30); INSERT IGNORE INTO frm_nom_map (frm_id, nom_id) SELECT f.id, n.id FROM frm_standard f JOIN nom_competency n ON ( (f.code = 'FRM_ALTURAS' AND n.code = 'NOM-009') OR (f.code = 'FRM_CONFINED' AND n.code = 'NOM-001') OR (f.code = 'FRM_MATPEL' AND n.code = 'NOM-005') OR (f.code = 'FRM_ELEC' AND n.code = 'NOM-029') ); INSERT IGNORE INTO public_documents (title_en, title_es, url, frm_id, sort_order) SELECT 'FRM overview — Penasquito library', 'Resumen FRM — biblioteca Penasquito', 'https://www.gob.mx/stps', id, sort_order FROM frm_standard WHERE code = 'FRM_ALTURAS' LIMIT 1; INSERT IGNORE INTO courses (title_en, title_es, url, sort_order) VALUES ('Height work orientation', 'Inducción trabajos en altura', 'https://example.org/course/alturas', 1), ('Confined space entry', 'Acceso a espacios confinados', 'https://example.org/course/confinados', 2), ('Electrical safety basics', 'Bases de seguridad eléctrica', 'https://example.org/course/electrico', 3); INSERT IGNORE INTO course_requirement (course_id, nom_id) SELECT c.id, n.id FROM courses c JOIN nom_competency n ON ( (c.title_en = 'Height work orientation' AND n.code = 'NOM-009') OR (c.title_en = 'Confined space entry' AND n.code = 'NOM-001') OR (c.title_en = 'Electrical safety basics' AND n.code = 'NOM-029') ); INSERT INTO users_cache (mobiliseme_id, employee_number, display_name, person_type, green_license_flag) VALUES ('demo-employee-1', '10001', 'Demo Employee', 'employee', 1), ('demo-contractor-1', 'C-5001', 'Demo Contractor SA', 'contractor', 0) ON DUPLICATE KEY UPDATE display_name=VALUES(display_name), employee_number=VALUES(employee_number), person_type=VALUES(person_type), green_license_flag=VALUES(green_license_flag); INSERT IGNORE INTO certificates (mobiliseme_id, nom_id, frm_id, title, issued_at, expires_at, status, external_ref) SELECT 'demo-employee-1', n.id, f.id, CONCAT('DC3 ', n.code), DATE_SUB(CURDATE(), INTERVAL 30 DAY), DATE_ADD(CURDATE(), INTERVAL 335 DAY), 'valid', CONCAT('EXT-', n.code) FROM nom_competency n LEFT JOIN frm_standard f ON f.code = 'FRM_ALTURAS' WHERE n.code IN ('NOM-009','NOM-017'); INSERT IGNORE INTO contractor_authorizations (mobiliseme_id, frm_id, valid_until, source) SELECT 'demo-contractor-1', id, DATE_ADD(CURDATE(), INTERVAL 180 DAY), 'seed' FROM frm_standard WHERE code IN ('FRM_ALTURAS','FRM_CONFINED'); INSERT IGNORE INTO certificates (mobiliseme_id, nom_id, frm_id, title, issued_at, expires_at, status, external_ref) SELECT 'demo-contractor-1', n.id, NULL, CONCAT('DC3 ', n.code), CURDATE(), DATE_ADD(CURDATE(), INTERVAL 300 DAY), 'valid', CONCAT('DC3-C-', n.code) FROM nom_competency n WHERE n.code IN ('NOM-009','NOM-001');