Migration_20221028_105818.php
3 months ago
Migration_20221110_151621.php
3 years ago
Migration_20230111_120000.php
2 years ago
Migration_20230111_130000.php
3 years ago
Migration_20230215_050813.php
3 months ago
Migration_20230221_200520.php
3 years ago
Migration_20230421_135915.php
3 years ago
Migration_20230503_210945.php
3 years ago
Migration_20230605_174836.php
3 years ago
Migration_20230703_105957.php
3 years ago
Migration_20230716_130221_Db.php
2 years ago
Migration_20230824_054259_Db.php
2 years ago
Migration_20230831_124214_Db.php
2 years ago
Migration_20230831_143755_Db.php
1 year ago
Migration_20240119_113943_Db.php
2 years ago
Migration_20240617_122847_Db.php
2 years ago
Migration_20240725_182318_Db.php
2 years ago
Migration_20241007_170437_Db.php
1 year ago
Migration_20241108_103249_Db.php
3 months ago
Migration_20250903_151331_Db.php
11 months ago
Migration_20250926_153050_Db.php
10 months ago
Migration_20260415_090055_Db.php
3 months ago
Migration_20260427_100000.php
3 months ago
Migration_20260428_120000.php
3 months ago
Migration_20260430_103000_Db.php
3 months ago
Migration_20260430_120000.php
3 months ago
Migration_20260504_120000_Db.php
3 months ago
Migration_20260514_120000_Db.php
3 months ago
Migration_20260609_120000_Db.php
2 months ago
Migration_20260610_120000_Db.php
1 month ago
Migration_20260622_120000_Db.php
1 month ago
Migration_20260709_120000_Db.php
1 month ago
Migration_20260715_100000_Db.php
1 month ago
index.php
3 years ago
Migration_20260622_120000_Db.php
44 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Migrations\Db; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Entities\SubscriberEntity; |
| 9 | use MailPoet\Migrator\DbMigration; |
| 10 | |
| 11 | class Migration_20260622_120000_Db extends DbMigration { |
| 12 | public function run(): void { |
| 13 | $subscribersTable = $this->getTableName(SubscriberEntity::class); |
| 14 | |
| 15 | $alterations = []; |
| 16 | |
| 17 | // Denormalized count of the subscriber's subscribed memberships in |
| 18 | // non-deleted segments. It powers the "Subscribers without a list" filter |
| 19 | // and its per-status counts: those used to run an anti-join over the whole |
| 20 | // subscribers table (tens of minutes on large installs). With this column |
| 21 | // the count becomes `WHERE segments_count = 0`. Defaults to 0; the real |
| 22 | // values are populated by the SubscribersSegmentsCountSync worker and kept |
| 23 | // in sync by SegmentsCountRecalculator. Reads only trust the column once the |
| 24 | // backfill has completed (see SegmentSubscribersRepository::isSegmentsCountColumnReady()). |
| 25 | if (!$this->columnExists($subscribersTable, 'segments_count')) { |
| 26 | $alterations[] = 'ADD COLUMN `segments_count` INT UNSIGNED NOT NULL DEFAULT 0'; |
| 27 | } |
| 28 | |
| 29 | // Range on segments_count = 0, then status and deleted_at cover the |
| 30 | // per-status breakdown so the count query stays index-only. |
| 31 | if (!$this->indexExists($subscribersTable, 'segments_count_status_deleted_at')) { |
| 32 | $alterations[] = 'ADD INDEX `segments_count_status_deleted_at` (`segments_count`, `status`, `deleted_at`)'; |
| 33 | } |
| 34 | |
| 35 | if ($alterations === []) { |
| 36 | return; |
| 37 | } |
| 38 | |
| 39 | $this->connection->executeStatement( |
| 40 | "ALTER TABLE `{$subscribersTable}` " . implode(', ', $alterations) |
| 41 | ); |
| 42 | } |
| 43 | } |
| 44 |