<?php
declare(strict_types=1);
namespace PPSDKDoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20220329135117_DisplayedNotifications extends AbstractMigration
{
public function getDescription(): string
{
return 'Recalculates the displayed_notifications_count field for Notifications';
}
public function up(Schema $schema): void
{
$this->addSql("
UPDATE
notifications
SET
displayed_notifications_count = GREATEST(
displayed_notifications_count,
(SELECT COUNT(id) FROM notification_view WHERE notification_id = notifications.id)
);
");
}
public function down(Schema $schema): void
{
// empty
}
}