<?php
$db = new mysqli('localhost', 'root', '', 'siakad');
if ($db->connect_error) {
    die("Connection failed: " . $db->connect_error);
}

$base_cols = [
    'id', 'user_id', 'prodi_id', 'nim', 'nama_lengkap', 'tempat_lahir', 
    'tanggal_lahir', 'jenis_kelamin', 'agama', 'kewarganegaraan', 'nik', 
    'alamat', 'no_hp', 'jalur_masuk', 'status_mahasiswa', 'created_at', 
    'updated_at'
];

$res = $db->query("SHOW COLUMNS FROM `mahasiswa`");
if ($res) {
    while ($row = $res->fetch_assoc()) {
        $col = $row['Field'];
        if (!in_array($col, $base_cols)) {
            try {
                $db->query("ALTER TABLE `mahasiswa` DROP COLUMN `$col`");
                echo "Dropped $col\n";
            } catch (Exception $e) {
                echo "Failed to drop $col: " . $e->getMessage() . "\n";
            }
        }
    }
}

echo "Cleanup done.\n";
