-- MSIN-diag — Diagnostic compte / hub après import prod
-- Exécuter en entier (F5) sur AVANT (backup local) puis sur APRÈS (serveur dev).
-- Modifier @com_login si besoin. Noter le nom de la connexion pour chaque exécution.

SET @com_login = 'stephan@progiweb.ca';

SELECT @com_id := com_id
FROM inscriptions_comptes
WHERE com_login = @com_login
LIMIT 1;

SELECT 'META' AS section, 'com_login' AS clef, @com_login AS valeur
UNION ALL SELECT 'META', 'com_id', IFNULL(CAST(@com_id AS CHAR), 'INTROUVABLE')
UNION ALL SELECT 'META', 'executed_at', NOW();

-- A — Accès V2 (déclenche routage hub si > 0 pour ce compte)
SELECT 'A_eve_acces_tous_comptes' AS section, com_id, COUNT(*) AS nb,
       GROUP_CONCAT(eve_id ORDER BY eve_id) AS eve_ids
FROM inscriptions_eve_acces
WHERE ea_statut = 'actif'
  AND (ea_expires_at IS NULL OR ea_expires_at > NOW())
GROUP BY com_id
ORDER BY com_id;

SELECT 'A_eve_acces_mon_compte' AS section, ea_id, com_id, eve_id, role_id, ea_statut, ea_expires_at
FROM inscriptions_eve_acces
WHERE com_id = @com_id
ORDER BY eve_id;

-- B — Page hub CMS
SELECT 'B_page_hub' AS section, pag_code, pag_actif, pag_titre_fr, pag_maj
FROM inscriptions_pages
WHERE pag_code = 'compte_promoteur_hub';

-- C — Volume legacy com_eve_promoteur
SELECT 'C_compte_promoteur' AS section, com_id, com_login,
       LENGTH(com_eve_promoteur) AS len_champ,
       CASE
         WHEN TRIM(IFNULL(com_eve_promoteur, '')) = '' THEN 0
         ELSE LENGTH(com_eve_promoteur) - LENGTH(REPLACE(com_eve_promoteur, ',', '')) + 1
       END AS nb_eve_estime,
       LEFT(com_eve_promoteur, 120) AS debut_champ
FROM inscriptions_comptes
WHERE com_id = @com_id OR com_login = @com_login;

-- D — Variable legacy site
SELECT 'D_variables' AS section, var_nom, var_valeur
FROM variables
WHERE var_nom IN ('promoteur_legacy_actif');

-- E — Info poubelle + clés hub
SELECT 'E_info_poubelle' AS section, COUNT(*) AS nb_lignes
FROM info
WHERE info_texte = info_clef;

SELECT 'E_info_hub' AS section, info_clef, info_langue, info_actif, LEFT(info_texte, 60) AS extrait
FROM info
WHERE info_clef LIKE 'promoteur_hub_%'
ORDER BY info_clef, info_langue;

-- F — Tables admin (sync static a pu les écraser)
SELECT 'F_adm_counts' AS section, 'adm_menus' AS tbl, COUNT(*) AS nb FROM adm_menus
UNION ALL SELECT 'F_adm_counts', 'adm_forms', COUNT(*) FROM adm_forms
UNION ALL SELECT 'F_adm_counts', 'adm_labels', COUNT(*) FROM adm_labels
UNION ALL SELECT 'F_adm_counts', 'variables', COUNT(*) FROM variables
UNION ALL SELECT 'F_adm_counts', 'info', COUNT(*) FROM info;

-- G — Rôles V2
SELECT 'G_eve_roles' AS section, role_id, role_code, role_actif
FROM inscriptions_eve_roles
ORDER BY role_id;
