<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add performance indexes to log table for improved query performance
*
* These indexes optimize:
* - User filtering (idx_log_user)
* - Date range queries (idx_log_created_at)
* - HTTP method filtering (idx_log_method)
* - IP address filtering (idx_log_remote_addr)
* - URI searches (idx_log_uri)
* - Combined user + date queries (idx_log_user_created)
*/
final class Version20251006095500 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add performance indexes to log table for faster filtering and searching';
}
public function up(Schema $schema): void
{
// Add indexes for log table to improve query performance
$this->addSql('CREATE INDEX idx_log_user ON log (user)');
$this->addSql('CREATE INDEX idx_log_created_at ON log (created_at)');
$this->addSql('CREATE INDEX idx_log_method ON log (method)');
$this->addSql('CREATE INDEX idx_log_remote_addr ON log (remote_addr)');
$this->addSql('CREATE INDEX idx_log_uri ON log (uri(255))');
$this->addSql('CREATE INDEX idx_log_user_created ON log (user, created_at)');
}
public function down(Schema $schema): void
{
// Remove log indexes
$this->addSql('DROP INDEX idx_log_user ON log');
$this->addSql('DROP INDEX idx_log_created_at ON log');
$this->addSql('DROP INDEX idx_log_method ON log');
$this->addSql('DROP INDEX idx_log_remote_addr ON log');
$this->addSql('DROP INDEX idx_log_uri ON log');
$this->addSql('DROP INDEX idx_log_user_created ON log');
}
}