migrations/Version20260616010000.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. final class Version20260616010000 extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Extend operation log for audit timeline';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql("ALTER TABLE operation_log ADD type VARCHAR(30) DEFAULT 'operation' NOT NULL, ADD username VARCHAR(180) DEFAULT NULL, ADD operator_type VARCHAR(30) DEFAULT NULL, ADD user_agent LONGTEXT DEFAULT NULL, ADD result VARCHAR(20) DEFAULT 'success' NOT NULL, ADD failure_reason LONGTEXT DEFAULT NULL");
  15.         $this->addSql('CREATE INDEX idx_operation_log_created_at ON operation_log (created_at)');
  16.         $this->addSql('CREATE INDEX idx_operation_log_type_created_at ON operation_log (type, created_at)');
  17.         $this->addSql('CREATE INDEX idx_operation_log_action_created_at ON operation_log (action, created_at)');
  18.         $this->addSql('CREATE INDEX idx_operation_log_result_created_at ON operation_log (result, created_at)');
  19.         $this->addSql('CREATE INDEX idx_operation_log_username_created_at ON operation_log (username, created_at)');
  20.         $this->addSql('CREATE INDEX idx_operation_log_ip_created_at ON operation_log (ip, created_at)');
  21.         $this->addSql('CREATE INDEX idx_operation_log_operator_created_at ON operation_log (operator_id, created_at)');
  22.         $this->addSql('CREATE INDEX idx_operation_log_resource ON operation_log (resource_type, resource_id)');
  23.     }
  24.     public function down(Schema $schema): void
  25.     {
  26.         $this->addSql('DROP INDEX idx_operation_log_created_at ON operation_log');
  27.         $this->addSql('DROP INDEX idx_operation_log_type_created_at ON operation_log');
  28.         $this->addSql('DROP INDEX idx_operation_log_action_created_at ON operation_log');
  29.         $this->addSql('DROP INDEX idx_operation_log_result_created_at ON operation_log');
  30.         $this->addSql('DROP INDEX idx_operation_log_username_created_at ON operation_log');
  31.         $this->addSql('DROP INDEX idx_operation_log_ip_created_at ON operation_log');
  32.         $this->addSql('DROP INDEX idx_operation_log_operator_created_at ON operation_log');
  33.         $this->addSql('DROP INDEX idx_operation_log_resource ON operation_log');
  34.         $this->addSql('ALTER TABLE operation_log DROP type, DROP username, DROP operator_type, DROP user_agent, DROP result, DROP failure_reason');
  35.     }
  36. }