migrations/Version20251006095500.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace DoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Add performance indexes to log table for improved query performance
  8.  *
  9.  * These indexes optimize:
  10.  * - User filtering (idx_log_user)
  11.  * - Date range queries (idx_log_created_at)
  12.  * - HTTP method filtering (idx_log_method)
  13.  * - IP address filtering (idx_log_remote_addr)
  14.  * - URI searches (idx_log_uri)
  15.  * - Combined user + date queries (idx_log_user_created)
  16.  */
  17. final class Version20251006095500 extends AbstractMigration
  18. {
  19.     public function getDescription(): string
  20.     {
  21.         return 'Add performance indexes to log table for faster filtering and searching';
  22.     }
  23.     public function up(Schema $schema): void
  24.     {
  25.         // Add indexes for log table to improve query performance
  26.         $this->addSql('CREATE INDEX idx_log_user ON log (user)');
  27.         $this->addSql('CREATE INDEX idx_log_created_at ON log (created_at)');
  28.         $this->addSql('CREATE INDEX idx_log_method ON log (method)');
  29.         $this->addSql('CREATE INDEX idx_log_remote_addr ON log (remote_addr)');
  30.         $this->addSql('CREATE INDEX idx_log_uri ON log (uri(255))');
  31.         $this->addSql('CREATE INDEX idx_log_user_created ON log (user, created_at)');
  32.     }
  33.     public function down(Schema $schema): void
  34.     {
  35.         // Remove log indexes
  36.         $this->addSql('DROP INDEX idx_log_user ON log');
  37.         $this->addSql('DROP INDEX idx_log_created_at ON log');
  38.         $this->addSql('DROP INDEX idx_log_method ON log');
  39.         $this->addSql('DROP INDEX idx_log_remote_addr ON log');
  40.         $this->addSql('DROP INDEX idx_log_uri ON log');
  41.         $this->addSql('DROP INDEX idx_log_user_created ON log');
  42.     }
  43. }