| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\Database\Migrations; |
| 4 |
|
| 5 |
|
| 6 |
use FluentCart\Framework\Database\Schema; |
| 7 |
|
| 8 |
class AppliedCouponsMigrator extends Migrator |
| 9 |
{ |
| 10 |
|
| 11 |
public static string $tableName = 'fct_applied_coupons'; |
| 12 |
|
| 13 |
public static function getSqlSchema(): string |
| 14 |
{ |
| 15 |
$indexPrefix = 'fct_acoup_'; |
| 16 |
return "`id` BIGINT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, |
| 17 |
`order_id` BIGINT UNSIGNED NOT NULL, |
| 18 |
`coupon_id` BIGINT UNSIGNED NULL, |
| 19 |
`code` VARCHAR(100) NOT NULL , |
| 20 |
`amount` double NOT NULL, |
| 21 |
`created_at` DATETIME NULL , |
| 22 |
`updated_at` DATETIME NULL, |
| 23 |
INDEX `{$indexPrefix}_code_idx` (`code`), |
| 24 |
INDEX `{$indexPrefix}_coupon_order_idx` (`coupon_id`, `order_id`)"; |
| 25 |
} |
| 26 |
|
| 27 |
public static function migrated() |
| 28 |
{ |
| 29 |
// Per-customer usage counting filters by coupon_id and joins orders |
| 30 |
// through order_id (CanValidateCoupon::hasMaxPerUserLimit, |
| 31 |
// DiscountService::isCouponValid) — without this, every validation |
| 32 |
// scans the table as usage history grows. |
| 33 |
static::addIndexIfNotExists('fct_acoup__coupon_order_idx', ['coupon_id', 'order_id']); |
| 34 |
} |
| 35 |
} |
| 36 |
|