<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20220902142443 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE scans ADD needs_retry TINYINT(1) DEFAULT 0 NOT NULL');
$this->addSql('ALTER TABLE targets ADD retry_count INT DEFAULT 0 NOT NULL');
$this->addSql('
UPDATE scans us, (
SELECT
t.version,
sq.id,
sq.status
FROM
targets t
JOIN (
SELECT
s.id,
s.target_id,
s.status
FROM
scans s
WHERE
s.updated = (
SELECT
MAX(updated)
FROM
scans ss
WHERE
ss.target_id = s.target_id
)
GROUP BY
s.target_id
) sq
ON sq.target_id = t.id
) uq
SET us.target_version = uq.version, us.needs_retry = IF(uq.status = 2, 1, 0)
WHERE us.id = uq.id
');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE scans DROP needs_retry');
$this->addSql('ALTER TABLE targets DROP retry_count');
}
}