#!/usr/bin/env php
<?php
/**
 * Optimize Database
 * Optimizes all tables for better performance
 */

require_once __DIR__ . '/../config/config.php';
require_once __DIR__ . '/../config/database.php';

$pdo = getDB();
echo "Optimizing database tables...\n";

// Get all tables
$stmt = $pdo->query("SHOW TABLES");
$tables = $stmt->fetchAll(PDO::FETCH_COLUMN);

foreach ($tables as $table) {
    echo "Optimizing: $table... ";
    
    // Analyze table
    $pdo->exec("ANALYZE TABLE `$table`");
    
    // Optimize table
    $pdo->exec("OPTIMIZE TABLE `$table`");
    
    echo "✓\n";
}

echo "Database optimization completed.\n";