-- Korrigiertes Cleanup-Script für MySQL Keys
-- Verwendet die wahrscheinlich korrekten Tabellennamen

USE trainingsdiary;

-- 1. Alle überflüssigen INDEX entfernen
-- Diese entfernen die meisten Keys, die das Limit überschreiten

-- User-Tabelle (wahrscheinlich 'user')
DROP INDEX IF EXISTS idx_user_email ON user;
DROP INDEX IF EXISTS idx_user_created_at ON user;
DROP INDEX IF EXISTS idx_user_updated_at ON user;

-- Clubs-Tabelle (wahrscheinlich 'clubs')
DROP INDEX IF EXISTS idx_clubs_name ON clubs;
DROP INDEX IF EXISTS idx_clubs_created_at ON clubs;
DROP INDEX IF EXISTS idx_clubs_updated_at ON clubs;

-- User_Club-Tabelle (wahrscheinlich 'user_club')
DROP INDEX IF EXISTS idx_user_club_approved ON user_club;
DROP INDEX IF EXISTS idx_user_club_created_at ON user_club;
DROP INDEX IF EXISTS idx_user_club_updated_at ON user_club;

-- Member-Tabelle (wahrscheinlich 'member')
DROP INDEX IF EXISTS idx_member_hashed_id ON member;
DROP INDEX IF EXISTS idx_member_first_name ON member;
DROP INDEX IF EXISTS idx_member_last_name ON member;
DROP INDEX IF EXISTS idx_member_birth_date ON member;
DROP INDEX IF EXISTS idx_member_active ON member;
DROP INDEX IF EXISTS idx_member_created_at ON member;
DROP INDEX IF EXISTS idx_member_updated_at ON member;

-- Log-Tabelle (wahrscheinlich 'log')
DROP INDEX IF EXISTS idx_log_activity ON log;
DROP INDEX IF EXISTS idx_log_created_at ON log;
DROP INDEX IF EXISTS idx_log_updated_at ON log;

-- Diary_Dates-Tabelle (wahrscheinlich 'diary_dates')
DROP INDEX IF EXISTS idx_diary_dates_date ON diary_dates;
DROP INDEX IF EXISTS idx_diary_dates_created_at ON diary_dates;
DROP INDEX IF EXISTS idx_diary_dates_updated_at ON diary_dates;

-- Participants-Tabelle (wahrscheinlich 'participants')
DROP INDEX IF EXISTS idx_participant_created_at ON participants;
DROP INDEX IF EXISTS idx_participant_updated_at ON participants;

-- Activities-Tabelle (wahrscheinlich 'activities')
DROP INDEX IF EXISTS idx_activity_created_at ON activities;
DROP INDEX IF EXISTS idx_activity_updated_at ON activities;

-- Member_Notes-Tabelle (wahrscheinlich 'member_notes')
DROP INDEX IF EXISTS idx_member_note_created_at ON member_notes;
DROP INDEX IF EXISTS idx_member_note_updated_at ON member_notes;

-- Diary_Notes-Tabelle (wahrscheinlich 'diary_notes')
DROP INDEX IF EXISTS idx_diary_note_created_at ON diary_notes;
DROP INDEX IF EXISTS idx_diary_note_updated_at ON diary_notes;

-- Diary_Tags-Tabelle (wahrscheinlich 'diary_tags')
DROP INDEX IF EXISTS idx_diary_tag_created_at ON diary_tags;
DROP INDEX IF EXISTS idx_diary_tag_updated_at ON diary_tags;

-- Member_Diary_Tags-Tabelle (wahrscheinlich 'member_diary_tags')
DROP INDEX IF EXISTS idx_member_diary_tag_created_at ON member_diary_tags;
DROP INDEX IF EXISTS idx_member_diary_tag_updated_at ON member_diary_tags;

-- Diary_Date_Tags-Tabelle (wahrscheinlich 'diary_date_tags')
DROP INDEX IF EXISTS idx_diary_date_tag_created_at ON diary_date_tags;
DROP INDEX IF EXISTS idx_diary_date_tag_updated_at ON diary_date_tags;

-- Diary_Member_Notes-Tabelle (wahrscheinlich 'diary_member_notes')
DROP INDEX IF EXISTS idx_diary_member_note_created_at ON diary_member_notes;
DROP INDEX IF EXISTS idx_diary_member_note_updated_at ON diary_member_notes;

-- Predefined_Activities-Tabelle (wahrscheinlich 'predefined_activities')
DROP INDEX IF EXISTS idx_predefined_activity_created_at ON predefined_activities;
DROP INDEX IF EXISTS idx_predefined_activity_updated_at ON predefined_activities;

-- Diary_Date_Activities-Tabelle (wahrscheinlich 'diary_date_activities')
DROP INDEX IF EXISTS idx_diary_date_activity_created_at ON diary_date_activities;
DROP INDEX IF EXISTS idx_diary_date_activity_updated_at ON diary_date_activities;

-- Matches-Tabelle (wahrscheinlich 'matches')
DROP INDEX IF EXISTS idx_match_created_at ON matches;
DROP INDEX IF EXISTS idx_match_updated_at ON matches;

-- Leagues-Tabelle (wahrscheinlich 'leagues')
DROP INDEX IF EXISTS idx_league_created_at ON leagues;
DROP INDEX IF EXISTS idx_league_updated_at ON leagues;

-- Teams-Tabelle (wahrscheinlich 'teams')
DROP INDEX IF EXISTS idx_team_created_at ON teams;
DROP INDEX IF EXISTS idx_team_updated_at ON teams;

-- Seasons-Tabelle (wahrscheinlich 'seasons')
DROP INDEX IF EXISTS idx_season_created_at ON seasons;
DROP INDEX IF EXISTS idx_season_updated_at ON seasons;

-- Locations-Tabelle (wahrscheinlich 'locations')
DROP INDEX IF EXISTS idx_location_created_at ON locations;
DROP INDEX IF EXISTS idx_location_updated_at ON locations;

-- Groups-Tabelle (wahrscheinlich 'groups')
DROP INDEX IF EXISTS idx_group_created_at ON `groups`;
DROP INDEX IF EXISTS idx_group_updated_at ON `groups`;

-- Group_Activities-Tabelle (wahrscheinlich 'group_activities')
DROP INDEX IF EXISTS idx_group_activity_created_at ON group_activities;
DROP INDEX IF EXISTS idx_group_activity_updated_at ON group_activities;

-- Tournaments-Tabelle (wahrscheinlich 'tournaments')
DROP INDEX IF EXISTS idx_tournament_created_at ON tournaments;
DROP INDEX IF EXISTS idx_tournament_updated_at ON tournaments;

-- Tournament_Groups-Tabelle (wahrscheinlich 'tournament_groups')
DROP INDEX IF EXISTS idx_tournament_group_created_at ON tournament_groups;
DROP INDEX IF EXISTS idx_tournament_group_updated_at ON tournament_groups;

-- Tournament_Members-Tabelle (wahrscheinlich 'tournament_members')
DROP INDEX IF EXISTS idx_tournament_member_created_at ON tournament_members;
DROP INDEX IF EXISTS idx_tournament_member_updated_at ON tournament_members;

-- Tournament_Matches-Tabelle (wahrscheinlich 'tournament_matches')
DROP INDEX IF EXISTS idx_tournament_match_created_at ON tournament_matches;
DROP INDEX IF EXISTS idx_tournament_match_updated_at ON tournament_matches;

-- Tournament_Results-Tabelle (wahrscheinlich 'tournament_results')
DROP INDEX IF EXISTS idx_tournament_result_created_at ON tournament_results;
DROP INDEX IF EXISTS idx_tournament_result_updated_at ON tournament_results;

-- Accidents-Tabelle (wahrscheinlich 'accidents')
DROP INDEX IF EXISTS idx_accident_created_at ON accidents;
DROP INDEX IF EXISTS idx_accident_updated_at ON accidents;

-- User_Tokens-Tabelle (wahrscheinlich 'user_tokens')
DROP INDEX IF EXISTS idx_user_token_created_at ON user_tokens;
DROP INDEX IF EXISTS idx_user_token_updated_at ON user_tokens;

-- 2. Status anzeigen
SELECT 
    TABLE_NAME,
    COUNT(*) as key_count
FROM INFORMATION_SCHEMA.STATISTICS 
WHERE TABLE_SCHEMA = 'trainingsdiary' 
GROUP BY TABLE_NAME
ORDER BY key_count DESC;

-- 3. Gesamtanzahl der Keys anzeigen
SELECT 
    COUNT(*) as total_keys
FROM INFORMATION_SCHEMA.STATISTICS 
WHERE TABLE_SCHEMA = 'trainingsdiary';
