-- MSIN-4328 — Stocker entry_id ChronoTrack sur resultats_participants + libellé bouton fiche
-- Prérequis : sql/MSIN-4328-chronotrack-last-push-at.sql (config sync)
-- Idempotent. Exécuter avant déploiement PHP (bouton fiche + backfill).

SET @db := DATABASE();

SET @col_ce := (
    SELECT COUNT(*) FROM information_schema.COLUMNS
    WHERE TABLE_SCHEMA = @db AND TABLE_NAME = 'resultats_participants' AND COLUMN_NAME = 'ct_entry_id'
);
SET @sql_ce := IF(
    @col_ce = 0,
    'ALTER TABLE resultats_participants ADD COLUMN ct_entry_id BIGINT UNSIGNED NULL DEFAULT NULL COMMENT ''MSIN-4328 — ChronoTrack entry_id'' AFTER par_id_original',
    'SELECT ''ct_entry_id already exists'' AS note'
);
PREPARE stmt_ce FROM @sql_ce;
EXECUTE stmt_ce;
DEALLOCATE PREPARE stmt_ce;

DELETE FROM info
WHERE info_prg = 'compte.php'
  AND info_clef = 'inscr_gestion_btn_chronotrack';

INSERT INTO info (info_clef, info_langue, info_texte, info_aide, info_prg, info_description, info_trie, info_actif, info_option1, info_option2, info_option3, info_creation) VALUES
('inscr_gestion_btn_chronotrack', 'fr', 'Voir dans ChronoTrack', '', 'compte.php', 'MSIN-4328 — lien fiche CT (superadmin)', 0, 1, '', '', '', NOW()),
('inscr_gestion_btn_chronotrack', 'en', 'View in ChronoTrack', '', 'compte.php', 'MSIN-4328 — CT entry link (superadmin)', 0, 1, '', '', '', NOW());
