| @@ -8,8 +8,10 @@ | ||
| 8 | 8 | |
| 9 | 9 | public static string $tableName = "fct_subscriptions"; |
| 10 | 10 | |
| 11 | 11 | |
| 12 | + const CUSTOMER_RECOVERY_INDEX = 'idx_subscriptions_customer_recovery'; | |
| 13 | + | |
| 12 | 14 | public static function getSqlSchema(): string |
| 13 | 15 | { |
| 14 | 16 | $indexPrefix = static::getDbPrefix() . 'fct_index_'; |
| 15 | 17 | |
| @@ -47,19 +49,43 @@ | ||
| 47 | 49 | `created_at` DATETIME NULL, |
| 48 | 50 | `updated_at` DATETIME NULL, |
| 49 | 51 | |
| 50 | 52 | INDEX `{$indexPrefix}_order_subscription_idx` (`parent_order_id` ASC), |
| 51 | - INDEX `{$indexPrefix}_expiry_scan_idx` (`status`, `next_billing_date`, `id`)"; | |
| 53 | + INDEX `{$indexPrefix}vendor_subscription_id_idx` (`vendor_subscription_id` ASC), | |
| 54 | + INDEX `{$indexPrefix}_expiry_scan_idx` (`status`, `next_billing_date`, `id`), | |
| 55 | + INDEX `{$indexPrefix}collection_method_idx` (`collection_method`), | |
| 56 | + INDEX `" . self::CUSTOMER_RECOVERY_INDEX . "` (`customer_id` ASC, `id` ASC)"; | |
| 52 | 57 | } |
| 53 | 58 | |
| 54 | 59 | public static function migrated() |
| 55 | 60 | { |
| 61 | + static::addCustomerRecoveryIndex(); | |
| 56 | 62 | static::addUuidColumn(); |
| 57 | 63 | static::renameInitialAmountToSignupFee(); |
| 58 | 64 | static::backfillEmptyUuids(); |
| 65 | + static::addVendorSubscriptionIdIndex(); | |
| 59 | 66 | static::addExpiryScanIndex(); |
| 67 | + static::addCollectionMethodIndex(); | |
| 60 | 68 | } |
| 61 | 69 | |
| 70 | + // Serves the store-managed cron guard: whereIn(collection_method,[manual,system])->exists(). | |
| 71 | + // Online DDL, builds over existing rows; column is NOT NULL so no legacy backfill. | |
| 72 | + public static function addCollectionMethodIndex() | |
| 73 | + { | |
| 74 | + static::addIndexIfNotExists( | |
| 75 | + static::getDbPrefix() . 'fct_index_collection_method_idx', | |
| 76 | + 'collection_method' | |
| 77 | + ); | |
| 78 | + } | |
| 79 | + | |
| 80 | + public static function addVendorSubscriptionIdIndex() | |
| 81 | + { | |
| 82 | + static::addIndexIfNotExists( | |
| 83 | + static::getDbPrefix() . 'fct_index_vendor_subscription_id_idx', | |
| 84 | + 'vendor_subscription_id' | |
| 85 | + ); | |
| 86 | + } | |
| 87 | + | |
| 62 | 88 | public static function addExpiryScanIndex() |
| 63 | 89 | { |
| 64 | 90 | static::addIndexIfNotExists( |
| 65 | 91 | static::getDbPrefix() . 'fct_index_expiry_scan_idx', |
| @@ -105,6 +131,15 @@ | ||
| 105 | 131 | } |
| 106 | 132 | |
| 107 | 133 | (new Subscription())->batchUpdate($uuids); |
| 108 | 134 | } while ($subscriptions->count() >= $chunkSize); |
| 135 | + } | |
| 136 | + public static function addCustomerRecoveryIndex(): void | |
| 137 | + { | |
| 138 | + static::addIndexIfNotExists(self::CUSTOMER_RECOVERY_INDEX, ['customer_id', 'id']); | |
| 139 | + } | |
| 140 | + | |
| 141 | + public static function hasCustomerRecoveryIndex(): bool | |
| 142 | + { | |
| 143 | + return static::hasIndex(self::CUSTOMER_RECOVERY_INDEX); | |
| 109 | 144 | } |
| 110 | 145 | } |