-- Diagnose-Skript: Prüfe Seasons und Teams auf dem Server
-- Führe diese Queries auf dem Server aus, um das Problem zu identifizieren

-- 1. Prüfe, ob die season-Tabelle existiert und Daten enthält
SELECT '=== SEASONS ===' as info;
SELECT * FROM `season` ORDER BY `id` DESC;

-- 2. Prüfe, ob die club_team-Tabelle existiert und welche season_id verwendet wird
SELECT '=== CLUB_TEAMS ===' as info;
SELECT 
    id, 
    name, 
    club_id, 
    season_id, 
    league_id,
    created_at,
    updated_at
FROM `club_team` 
ORDER BY `id`;

-- 3. Prüfe, ob es Teams gibt, die auf nicht-existierende Seasons verweisen
SELECT '=== TEAMS MIT FEHLENDEN SEASONS ===' as info;
SELECT 
    ct.id,
    ct.name,
    ct.season_id,
    s.season
FROM `club_team` ct
LEFT JOIN `season` s ON ct.season_id = s.id
WHERE s.id IS NULL;

-- 4. Prüfe, ob es Teams gibt, die keine season_id haben
SELECT '=== TEAMS OHNE SEASON_ID ===' as info;
SELECT 
    id,
    name,
    club_id,
    season_id
FROM `club_team`
WHERE season_id IS NULL;

-- 5. Prüfe die Struktur der club_team-Tabelle
SELECT '=== CLUB_TEAM TABELLENSTRUKTUR ===' as info;
DESCRIBE `club_team`;

-- 6. Prüfe die Struktur der season-Tabelle
SELECT '=== SEASON TABELLENSTRUKTUR ===' as info;
DESCRIBE `season`;

-- 7. Prüfe Foreign Key Constraints
SELECT '=== FOREIGN KEYS ===' as info;
SELECT 
    CONSTRAINT_NAME,
    TABLE_NAME,
    COLUMN_NAME,
    REFERENCED_TABLE_NAME,
    REFERENCED_COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = DATABASE()
  AND (TABLE_NAME = 'club_team' OR TABLE_NAME = 'season')
  AND REFERENCED_TABLE_NAME IS NOT NULL;

