-- Finales Cleanup-Script für die verbleibenden Problem-Tabellen
-- Entfernt weitere INDEX aus member, diary_tags und season

USE trainingsdiary;

-- 1. Status vor dem finalen Cleanup
SELECT '=== STATUS VOR FINALEM CLEANUP ===' as info;
SELECT 
    TABLE_NAME,
    COUNT(*) as key_count
FROM INFORMATION_SCHEMA.STATISTICS 
WHERE TABLE_SCHEMA = 'trainingsdiary' 
GROUP BY TABLE_NAME
ORDER BY key_count DESC;

-- 2. Alle INDEX der Problem-Tabellen anzeigen
SELECT '=== MEMBER TABELLE INDEX ===' as info;
SHOW INDEX FROM member;

SELECT '=== DIARY_TAGS TABELLE INDEX ===' as info;
SHOW INDEX FROM diary_tags;

SELECT '=== SEASON TABELLE INDEX ===' as info;
SHOW INDEX FROM season;

-- 3. Spezifische INDEX entfernen (basierend auf den echten Namen)
-- Diese INDEX sind wahrscheinlich überflüssig und können entfernt werden

-- Member-Tabelle: Weitere INDEX entfernen
SELECT '=== ENTFERNE WEITERE MEMBER INDEX ===' as info;

-- Versuche, INDEX zu entfernen, die wahrscheinlich überflüssig sind
-- (Diese Namen basieren auf typischen Sequelize-Konventionen)

-- Häufige überflüssige INDEX-Namen
DROP INDEX IF EXISTS member_hashed_id_unique ON member;
DROP INDEX IF EXISTS member_first_name_index ON member;
DROP INDEX IF EXISTS member_last_name_index ON member;
DROP INDEX IF EXISTS member_birth_date_index ON member;
DROP INDEX IF EXISTS member_active_index ON member;
DROP INDEX IF EXISTS member_created_at_index ON member;
DROP INDEX IF EXISTS member_updated_at_index ON member;

-- Alternative INDEX-Namen
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;

-- Diary_Tags-Tabelle: Weitere INDEX entfernen
SELECT '=== ENTFERNE WEITERE DIARY_TAGS INDEX ===' as info;

DROP INDEX IF EXISTS diary_tags_name_index ON diary_tags;
DROP INDEX IF EXISTS diary_tags_created_at_index ON diary_tags;
DROP INDEX IF EXISTS diary_tags_updated_at_index ON member;

-- Alternative INDEX-Namen
DROP INDEX IF EXISTS idx_diary_tags_name ON diary_tags;
DROP INDEX IF EXISTS idx_diary_tags_created_at ON diary_tags;
DROP INDEX IF EXISTS idx_diary_tags_updated_at ON diary_tags;

-- Season-Tabelle: Weitere INDEX entfernen
SELECT '=== ENTFERNE WEITERE SEASON INDEX ===' as info;

DROP INDEX IF EXISTS season_name_index ON season;
DROP INDEX IF EXISTS season_start_date_index ON season;
DROP INDEX IF EXISTS season_end_date_index ON season;
DROP INDEX IF EXISTS season_created_at_index ON season;
DROP INDEX IF EXISTS season_updated_at_index ON season;

-- Alternative INDEX-Namen
DROP INDEX IF EXISTS idx_season_name ON season;
DROP INDEX IF EXISTS idx_season_start_date ON season;
DROP INDEX IF EXISTS idx_season_end_date ON season;
DROP INDEX IF EXISTS idx_season_created_at ON season;
DROP INDEX IF EXISTS idx_season_updated_at ON season;

-- 4. Status nach dem finalen Cleanup
SELECT '=== STATUS NACH FINALEM CLEANUP ===' as info;
SELECT 
    TABLE_NAME,
    COUNT(*) as key_count
FROM INFORMATION_SCHEMA.STATISTICS 
WHERE TABLE_SCHEMA = 'trainingsdiary' 
GROUP BY TABLE_NAME
ORDER BY key_count DESC;

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

-- 6. Zusammenfassung
SELECT '=== ZUSAMMENFASSUNG ===' as info;
SELECT 
    'Finales Cleanup abgeschlossen. Überprüfen Sie die Anzahl der Keys oben.' as message;
