| @@ -9,8 +9,10 @@ | ||
| 9 | 9 | |
| 10 | 10 | public static string $tableName = 'fct_carts'; |
| 11 | 11 | |
| 12 | 12 | |
| 13 | + const CUSTOMER_RECOVERY_INDEX = 'idx_carts_customer_recovery'; | |
| 14 | + | |
| 13 | 15 | public static function getSqlSchema(): string |
| 14 | 16 | { |
| 15 | 17 | return "`customer_id` BIGINT(20) UNSIGNED NULL, |
| 16 | 18 | `user_id` BIGINT(20) UNSIGNED NULL, |
| @@ -30,7 +32,22 @@ | ||
| 30 | 32 | `completed_at` TIMESTAMP NULL, |
| 31 | 33 | `created_at` DATETIME NULL, |
| 32 | 34 | `updated_at` DATETIME NULL, |
| 33 | 35 | `deleted_at` TIMESTAMP NULL, |
| 34 | - UNIQUE KEY cart_hash (cart_hash)"; | |
| 36 | + UNIQUE KEY cart_hash (cart_hash), | |
| 37 | + INDEX `" . self::CUSTOMER_RECOVERY_INDEX . "` (`customer_id` ASC, `cart_hash` ASC)"; | |
| 38 | + } | |
| 39 | + public static function migrated() | |
| 40 | + { | |
| 41 | + static::addCustomerRecoveryIndex(); | |
| 42 | + } | |
| 43 | + | |
| 44 | + public static function addCustomerRecoveryIndex(): void | |
| 45 | + { | |
| 46 | + static::addIndexIfNotExists(self::CUSTOMER_RECOVERY_INDEX, ['customer_id', 'cart_hash']); | |
| 47 | + } | |
| 48 | + | |
| 49 | + public static function hasCustomerRecoveryIndex(): bool | |
| 50 | + { | |
| 51 | + return static::hasIndex(self::CUSTOMER_RECOVERY_INDEX); | |
| 35 | 52 | } |
| 36 | 53 | } |