5) { $statements[] = $stmt; } $currentStatement = ''; } } // Add any remaining statement if (!empty(trim($currentStatement))) { $statements[] = trim($currentStatement); } foreach ($statements as $statement) { if (empty(trim($statement))) { continue; } try { $db->exec($statement); } catch (\PDOException $e) { // Skip jika error karena table/column sudah ada $errorMsg = $e->getMessage(); if (strpos($errorMsg, 'already exists') !== false || strpos($errorMsg, 'Duplicate column') !== false || strpos($errorMsg, 'Duplicate key name') !== false) { echo " ⚠️ Sudah ada: " . substr($errorMsg, 0, 100) . "\n"; } else { echo " ❌ Error: " . $errorMsg . "\n"; throw $e; } } } echo " ✅ Selesai: {$migrationFile}\n\n"; } echo "=== Migration Selesai ===\n"; // Verifikasi tabel echo "\n=== Verifikasi Tabel ===\n"; $requiredTables = ['audit_logs', 'hourly_summary', 'realtime_events']; foreach ($requiredTables as $table) { try { $stmt = $db->query("SHOW TABLES LIKE '{$table}'"); $exists = $stmt->fetch() !== false; if ($exists) { echo " ✅ Tabel '{$table}' ada\n"; } else { echo " ❌ Tabel '{$table}' tidak ada\n"; } } catch (PDOException $e) { echo " ❌ Error cek tabel '{$table}': " . $e->getMessage() . "\n"; } } // Cek field camera di gates echo "\n=== Verifikasi Field Camera di Gates ===\n"; try { $stmt = $db->query("SHOW COLUMNS FROM gates LIKE 'camera'"); $exists = $stmt->fetch() !== false; if ($exists) { echo " ✅ Field 'camera' ada di tabel gates\n"; } else { echo " ❌ Field 'camera' tidak ada di tabel gates\n"; } } catch (PDOException $e) { echo " ❌ Error cek field camera: " . $e->getMessage() . "\n"; } } catch (PDOException $e) { echo "❌ Error: " . $e->getMessage() . "\n"; exit(1); }