PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
← All changes | database/Migrations/OrderAddressesMigrator.php +30 -2 1.5.1 → 1.6.5 View file →
@@ -5,8 +5,15 @@
5 5 class OrderAddressesMigrator extends Migrator
6 6 {
7 7 public static string $tableName = 'fct_order_addresses';
8 8
9 + /**
10 + * Named once and reused by getSqlSchema(), migrated() and hasOrderIdTypeIndex(),
11 + * so the three can never drift into declaring, creating and checking different
12 + * index names.
13 + */
14 + const ORDER_ID_TYPE_INDEX = 'idx_order_addresses_order_id_type';
15 +
9 16 public static function getSqlSchema(): string
10 17 {
11 18 return "`id` BIGINT(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
12 19 `order_id` BIGINT UNSIGNED NOT NULL,
@@ -19,15 +26,36 @@
19 26 `postcode` VARCHAR(50) NULL,
20 27 `country` VARCHAR(100) NULL,
21 28 `meta` JSON DEFAULT NULL,
22 29 `created_at` DATETIME NULL,
23 - `updated_at` DATETIME NULL";
30 + `updated_at` DATETIME NULL,
31 +
32 + INDEX `" . self::ORDER_ID_TYPE_INDEX . "` (`order_id` ASC, `type` ASC)";
24 33 }
25 34
26 35 public static function migrated()
27 36 {
28 37 static::addMetaColumn();
29 - static::addIndexIfNotExists('idx_order_addresses_order_id_type', ['order_id', 'type']);
38 + // Same index as getSqlSchema(), by the SAME name on purpose: the schema
39 + // above covers fresh installs (the table is created with it), this call
40 + // self-heals tables created before the index was declared. A different
41 + // name here would leave those installs carrying two identical indexes.
42 + static::addIndexIfNotExists(self::ORDER_ID_TYPE_INDEX, ['order_id', 'type']);
43 + }
44 +
45 + /**
46 + * Whether the composite index is actually present on the table.
47 + *
48 + * Public because the DataBackfills delivery path has to VERIFY its work rather
49 + * than assume it: addIndexIfNotExists() returns void and its ALTER goes through
50 + * $wpdb->query(), which returns false on failure instead of throwing, so a
51 + * backfill that cannot see the outcome would retire its slug with no index
52 + * created. Kept here rather than reimplemented in DataBackfills so this class
53 + * stays the only place that knows the index name.
54 + */
55 + public static function hasOrderIdTypeIndex(): bool
56 + {
57 + return static::hasIndex(self::ORDER_ID_TYPE_INDEX);
30 58 }
31 59
32 60 public static function addMetaColumn()
33 61 {