migrations/Version20220902142443.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.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20220902142443 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $this->addSql('ALTER TABLE scans ADD needs_retry TINYINT(1) DEFAULT 0 NOT NULL');
  19.         $this->addSql('ALTER TABLE targets ADD retry_count INT DEFAULT 0 NOT NULL');
  20.         $this->addSql('
  21.             UPDATE scans us, (
  22.                 SELECT
  23.                     t.version,
  24.                     sq.id,
  25.                     sq.status
  26.                 FROM
  27.                     targets t
  28.                 JOIN (  
  29.                     SELECT
  30.                         s.id,
  31.                         s.target_id,
  32.                         s.status
  33.                     FROM
  34.                         scans s
  35.                     WHERE
  36.                         s.updated = (
  37.                             SELECT
  38.                                 MAX(updated)
  39.                             FROM
  40.                                 scans ss
  41.                             WHERE
  42.                                 ss.target_id = s.target_id
  43.                         )
  44.                     GROUP BY
  45.                         s.target_id
  46.                 ) sq
  47.                 ON sq.target_id = t.id
  48.             ) uq
  49.             SET us.target_version = uq.version, us.needs_retry = IF(uq.status = 2, 1, 0)
  50.             WHERE us.id = uq.id
  51.         ');
  52.     }
  53.     public function down(Schema $schema): void
  54.     {
  55.         // this down() migration is auto-generated, please modify it to your needs
  56.         $this->addSql('ALTER TABLE scans DROP needs_retry');
  57.         $this->addSql('ALTER TABLE targets DROP retry_count');
  58.     }
  59. }