vendor/plna-penezenka/pp-sdk-bundle/migrations/Version20220329135117_DisplayedNotifications.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace PPSDKDoctrineMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. final class Version20220329135117_DisplayedNotifications extends AbstractMigration
  7. {
  8.     public function getDescription(): string
  9.     {
  10.         return 'Recalculates the displayed_notifications_count field for Notifications';
  11.     }
  12.     public function up(Schema $schema): void
  13.     {
  14.         $this->addSql("
  15.             UPDATE 
  16.                 notifications 
  17.             SET 
  18.                 displayed_notifications_count = GREATEST(
  19.                     displayed_notifications_count, 
  20.                     (SELECT COUNT(id) FROM notification_view WHERE notification_id = notifications.id)
  21.                 );
  22.         ");
  23.     }
  24.     public function down(Schema $schema): void
  25.     {
  26.         // empty
  27.     }
  28. }