| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\Database\Migrations; |
| 4 |
|
| 5 |
use FluentCart\Framework\Database\Schema; |
| 6 |
|
| 7 |
class OrderTransactionsMigrator extends Migrator |
| 8 |
{ |
| 9 |
|
| 10 |
public static string $tableName = "fct_order_transactions"; |
| 11 |
|
| 12 |
public static function getSqlSchema(): string |
| 13 |
{ |
| 14 |
$indexPrefix = static::getDbPrefix() . 'fct_ot_'; |
| 15 |
|
| 16 |
return "`id` BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, |
| 17 |
`order_id` BIGINT UNSIGNED NOT NULL DEFAULT '0', |
| 18 |
`order_type` VARCHAR(100) NOT NULL DEFAULT '', |
| 19 |
`transaction_type` varchar(192) DEFAULT 'charge', |
| 20 |
`subscription_id` int(11) NULL, |
| 21 |
`card_last_4` VARCHAR(4) NULL, |
| 22 |
`card_brand` varchar(100), |
| 23 |
`vendor_charge_id` VARCHAR(192) NOT NULL DEFAULT '', |
| 24 |
`payment_method` VARCHAR(100) NOT NULL DEFAULT '', |
| 25 |
`payment_mode` VARCHAR(100) NOT NULL DEFAULT '', |
| 26 |
`payment_method_type` VARCHAR(100) NOT NULL DEFAULT '', |
| 27 |
`status` VARCHAR(20) NOT NULL DEFAULT '', |
| 28 |
`currency` VARCHAR(10) NOT NULL DEFAULT '', -- Add the currency column here |
| 29 |
`total` BIGINT NOT NULL DEFAULT '0', |
| 30 |
`rate` BIGINT NOT NULL DEFAULT '1', |
| 31 |
`uuid` VARCHAR(100) NULL DEFAULT '', |
| 32 |
`meta` json DEFAULT NULL, |
| 33 |
`created_at` DATETIME NULL, |
| 34 |
`updated_at` DATETIME NULL, |
| 35 |
|
| 36 |
INDEX `{$indexPrefix}_ven_charge_id` (`vendor_charge_id`(64) ASC), |
| 37 |
INDEX `{$indexPrefix}_payment_method_idx` (`payment_method` ASC), |
| 38 |
INDEX `{$indexPrefix}_status_idx` (`status` ASC), |
| 39 |
INDEX `{$indexPrefix}_order_id_idx` (`order_id` ASC), |
| 40 |
INDEX `{$indexPrefix}_subscription_id_idx` (`subscription_id` ASC)"; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Runs on activation via Migrator::migrate() AND on in-place plugin |
| 45 |
* updates via the version-gated block in |
| 46 |
* DBMigrator::maybeMigrateDBChanges(). addIndexIfNotExists() is |
| 47 |
* idempotent, so double delivery is harmless. |
| 48 |
*/ |
| 49 |
public static function migrated() |
| 50 |
{ |
| 51 |
// Subscription views eager-load transactions filtered by |
| 52 |
// subscription_id (SubscriptionController, customer portal) — without |
| 53 |
// this, every detail view scans the transactions table. |
| 54 |
static::addIndexIfNotExists(static::getDbPrefix() . 'fct_ot__subscription_id_idx', 'subscription_id'); |
| 55 |
|
| 56 |
// card_last_4 was int(4), which silently strips a leading zero |
| 57 |
// (e.g. "0042" -> 42) on write. Widen to VARCHAR so gateway-provided |
| 58 |
// last-4 strings survive intact. modifyColumnIfExists is idempotent. |
| 59 |
static::modifyColumnIfExists('card_last_4', 'VARCHAR(4) NULL'); |
| 60 |
} |
| 61 |
} |
| 62 |
|