SELECT CASE WHEN COUNT(*) = 7 THEN 1 ELSE 0 END AS ok
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
  AND TABLE_NAME = 'ado_s1_dashboard_rebuild_job'
  AND COLUMN_NAME IN ('current_stage','stage_index','stage_total','progress_percent','progress_message','last_progress_at','failed_stage');

SELECT CASE WHEN COUNT(*) = 0 THEN 1 ELSE 0 END AS ok
FROM ado_s1_dashboard_rebuild_job
WHERE progress_percent < 0 OR progress_percent > 100
   OR stage_index < 0 OR stage_index > stage_total
   OR stage_total <> 5
   OR (status = 'SUCCESS' AND progress_percent <> 100);

SELECT CASE WHEN COUNT(*) >= 1 THEN 1 ELSE 0 END AS ok
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
  AND TABLE_NAME = 'ado_s1_dashboard_rebuild_job'
  AND INDEX_NAME = 'ix_s1_rebuild_scope';
