<?php
require_once 'includes/db.php';

$keep = [
    'dashboards', 
    'line_stages', 
    'machinery', 
    'roles', 
    'skills', 
    'task_statuses', 
    'users', 
    'workflow_stages', 
    'workflow_statuses',
    'companies',
    'branches'
];

try {
    global $pdo;
    $pdo->exec('SET FOREIGN_KEY_CHECKS = 0');
    
    $stmt = $pdo->query('SHOW TABLES');
    $tables = $stmt->fetchAll(PDO::FETCH_COLUMN);
    
    foreach ($tables as $table) {
        if (!in_array($table, $keep)) {
            echo "Truncating $table...\n";
            $pdo->exec("TRUNCATE TABLE `$table` ");
        }
    }
    
    $pdo->exec('SET FOREIGN_KEY_CHECKS = 1');
    echo "Database cleanup completed successfully.\n";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
