-- ══════════════════════════════════════════════════════════════════
--  reset_data.sql — czyści wszystkie dane w kunstlopapp_results
--  Zostawia: schemat tabel i widoki. Kasuje: wszystkie wiersze.
--
--  Uruchomienie (na VPS):
--    cd /var/www/api-nor
--    mysql -u vipro -ppolpop kunstlopapp_results < reset_data.sql
-- ══════════════════════════════════════════════════════════════════

USE kunstlopapp_results;


-- Tabele wyników (najgłębsze najpierw)
TRUNCATE TABLE `result_elements`;
TRUNCATE TABLE `result_components`;
TRUNCATE TABLE `result_deductions`;
TRUNCATE TABLE `unit_results`;
TRUNCATE TABLE `cumulative_results`;
TRUNCATE TABLE `registrations`;
TRUNCATE TABLE `team_members`;
TRUNCATE TABLE `event_units`;
TRUNCATE TABLE `phases`;

-- Tabele "rodziców"
TRUNCATE TABLE `events`;
TRUNCATE TABLE `teams`;
TRUNCATE TABLE `athletes`;
TRUNCATE TABLE `competitions`;
TRUNCATE TABLE `organisations`;
TRUNCATE TABLE `import_log`;


-- Weryfikacja — wszystkie liczby powinny być 0
SELECT 'competitions'       AS tbl, COUNT(*) AS rows_left FROM competitions
UNION ALL SELECT 'events',             COUNT(*) FROM events
UNION ALL SELECT 'event_units',        COUNT(*) FROM event_units
UNION ALL SELECT 'phases',             COUNT(*) FROM phases
UNION ALL SELECT 'athletes',           COUNT(*) FROM athletes
UNION ALL SELECT 'teams',              COUNT(*) FROM teams
UNION ALL SELECT 'team_members',       COUNT(*) FROM team_members
UNION ALL SELECT 'registrations',      COUNT(*) FROM registrations
UNION ALL SELECT 'unit_results',       COUNT(*) FROM unit_results
UNION ALL SELECT 'cumulative_results', COUNT(*) FROM cumulative_results
UNION ALL SELECT 'result_elements',    COUNT(*) FROM result_elements
UNION ALL SELECT 'result_components',  COUNT(*) FROM result_components
UNION ALL SELECT 'result_deductions',  COUNT(*) FROM result_deductions
UNION ALL SELECT 'organisations',      COUNT(*) FROM organisations
UNION ALL SELECT 'import_log',         COUNT(*) FROM import_log;
