| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\Database\Migrations; |
| 4 |
|
| 5 |
use FluentCart\Framework\Database\Schema; |
| 6 |
|
| 7 |
class CartMigrator extends Migrator |
| 8 |
{ |
| 9 |
|
| 10 |
public static string $tableName = 'fct_carts'; |
| 11 |
|
| 12 |
|
| 13 |
const CUSTOMER_RECOVERY_INDEX = 'idx_carts_customer_recovery'; |
| 14 |
|
| 15 |
public static function getSqlSchema(): string |
| 16 |
{ |
| 17 |
return "`customer_id` BIGINT(20) UNSIGNED NULL, |
| 18 |
`user_id` BIGINT(20) UNSIGNED NULL, |
| 19 |
`order_id` BIGINT(20) UNSIGNED NULL, |
| 20 |
`cart_hash` varchar(192) NOT NULL, |
| 21 |
`checkout_data` longtext NULL, |
| 22 |
`cart_data` longtext NULL, |
| 23 |
`utm_data` longtext NULL, |
| 24 |
`coupons` longtext NULL, |
| 25 |
`first_name` varchar(192) NULL, |
| 26 |
`last_name` varchar(192) NULL, |
| 27 |
`email` varchar(192) NULL, |
| 28 |
`stage` VARCHAR(30) NULL DEFAULT 'draft', /* draft | pending | in-complete | completed */ |
| 29 |
`cart_group` VARCHAR(30) NULL DEFAULT 'global', |
| 30 |
`user_agent` VARCHAR(192) NULL, |
| 31 |
`ip_address` VARCHAR(50) NULL, |
| 32 |
`completed_at` TIMESTAMP NULL, |
| 33 |
`created_at` DATETIME NULL, |
| 34 |
`updated_at` DATETIME NULL, |
| 35 |
`deleted_at` TIMESTAMP NULL, |
| 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); |
| 52 |
} |
| 53 |
} |
| 54 |
|