migrations/Version20251002111716.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.  * Inserta datos iniciales para Rate Limiting de SearchLLM
  8.  *
  9.  * Configuración:
  10.  * - 10 peticiones por minuto
  11.  * - 3 bloqueos temporales antes de bloqueo permanente
  12.  * - 15 minutos de duración de bloqueo temporal
  13.  */
  14. final class Version20251002111716 extends AbstractMigration
  15. {
  16.     public function getDescription(): string
  17.     {
  18.         return 'Inserta configuración inicial de rate limiting para endpoint /api/v1/SearchLLM/search';
  19.     }
  20.     public function up(Schema $schema): void
  21.     {
  22.         // Insertar TipoSeccion para SearchLLM
  23.         $this->addSql("
  24.             INSERT INTO tipo_seccion (endpoint, nombre, created_at, updated_at)
  25.             VALUES ('/api/v1/SearchLLM/search', 'SearchLLM', NOW(), NOW())
  26.         ");
  27.         // Insertar RateLimit asociado
  28.         // 10 peticiones/60 segundos, 3 bloqueos temporales, 15 minutos de bloqueo
  29.         $this->addSql("
  30.             INSERT INTO rate_limit (tipo_seccion_id, intentos, ventana, bloqueos, tiempo_bloqueo, created_at, updated_at)
  31.             SELECT id, 10, 60, 3, 15, NOW(), NOW()
  32.             FROM tipo_seccion
  33.             WHERE nombre = 'SearchLLM'
  34.             LIMIT 1
  35.         ");
  36.     }
  37.     public function down(Schema $schema): void
  38.     {
  39.         // Eliminar en orden inverso (FK constraint)
  40.         $this->addSql("
  41.             DELETE rl FROM rate_limit rl
  42.             INNER JOIN tipo_seccion ts ON rl.tipo_seccion_id = ts.id
  43.             WHERE ts.nombre = 'SearchLLM'
  44.         ");
  45.         $this->addSql("
  46.             DELETE FROM tipo_seccion
  47.             WHERE nombre = 'SearchLLM'
  48.         ");
  49.     }
  50. }