Skip to content

Commit 7a94e49

Browse files
authored
Merge pull request #4174 from craftcms/nathaniel/com-495-5x-missing-db-indexes-after-upgrading-from-commerce-4
[5.x] Missing DB indexes for catalog pricing
2 parents 492bc89 + ebddf57 commit 7a94e49

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fixed a SQL error that could occur when viewing unfulfilled orders on PostgreSQL. ([#4171](https://github.com/craftcms/commerce/issues/4171))
66
- Fixed a bug where duplicate pricing catalog jobs were being queued. ([#4136](https://github.com/craftcms/commerce/issues/4136))
7+
- Fixed missing pricing catalog database indexes. ([#4160](https://github.com/craftcms/commerce/issues/4160))
78
- Deprecated `craft\commerce\services\CatalogPricing::afterSavePurchasableHandler()`.
89

910
## 5.4.9 - 2025-10-29

src/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public static function editions(): array
257257
/**
258258
* @inheritDoc
259259
*/
260-
public string $schemaVersion = '5.4.0.6';
260+
public string $schemaVersion = '5.4.0.7';
261261

262262
/**
263263
* @inheritdoc

src/migrations/Install.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,18 +1064,18 @@ public function dropProjectConfig(): void
10641064
public function createIndexes(): void
10651065
{
10661066
$this->createIndex(null, Table::CATALOG_PRICING, 'catalogPricingRuleId', false);
1067+
$this->createIndex(null, Table::CATALOG_PRICING, 'isPromotionalPrice', false);
10671068
$this->createIndex(null, Table::CATALOG_PRICING, 'purchasableId', false);
10681069
$this->createIndex(null, Table::CATALOG_PRICING, 'storeId', false);
10691070
$this->createIndex(null, Table::CATALOG_PRICING, 'userId', false);
1070-
$this->createIndex(null, Table::CATALOG_PRICING, ['purchasableId', 'storeId', 'isPromotionalPrice', 'price'], false);
10711071
$this->createIndex(null, Table::CATALOG_PRICING, ['purchasableId', 'storeId', 'isPromotionalPrice', 'price', 'catalogPricingRuleId', 'dateFrom', 'dateTo'], false);
1072+
$this->createIndex(null, Table::CATALOG_PRICING, ['purchasableId', 'storeId', 'isPromotionalPrice', 'price'], false);
1073+
$this->createIndex(null, Table::CATALOG_PRICING, ['purchasableId', 'storeId'], false);
10721074
$this->createIndex(null, Table::CATALOG_PRICING_RULES, 'storeId', false);
10731075
$this->createIndex(null, Table::CATALOG_PRICING_RULES_USERS, 'catalogPricingRuleId', false);
10741076
$this->createIndex(null, Table::CATALOG_PRICING_RULES_USERS, 'userId', false);
10751077
$this->createIndex(null, Table::COUPONS, 'code', false);
10761078
$this->createIndex(null, Table::COUPONS, 'discountId', false);
1077-
$this->createIndex(null, Table::CATALOG_PRICING, 'isPromotionalPrice', false);
1078-
$this->createIndex(null, Table::CATALOG_PRICING, ['purchasableId', 'storeId'], false);
10791079
$this->createIndex(null, Table::CUSTOMERS, 'customerId', true);
10801080
$this->createIndex(null, Table::CUSTOMERS, 'primaryBillingAddressId', false);
10811081
$this->createIndex(null, Table::CUSTOMERS, 'primaryPaymentSourceId', false);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace craft\commerce\migrations;
4+
5+
use craft\commerce\db\Table;
6+
use craft\db\Migration;
7+
8+
/**
9+
* m251111_092942_ensure_catalog_pricing_indexes migration.
10+
*/
11+
class m251111_092942_ensure_catalog_pricing_indexes extends Migration
12+
{
13+
/**
14+
* @inheritdoc
15+
*/
16+
public function safeUp(): bool
17+
{
18+
$this->createIndexIfMissing(Table::CATALOG_PRICING, 'catalogPricingRuleId', false);
19+
$this->createIndexIfMissing(Table::CATALOG_PRICING, 'isPromotionalPrice', false);
20+
$this->createIndexIfMissing(Table::CATALOG_PRICING, 'purchasableId', false);
21+
$this->createIndexIfMissing(Table::CATALOG_PRICING, 'storeId', false);
22+
$this->createIndexIfMissing(Table::CATALOG_PRICING, 'userId', false);
23+
$this->createIndexIfMissing(Table::CATALOG_PRICING, ['purchasableId', 'storeId', 'isPromotionalPrice', 'price', 'catalogPricingRuleId', 'dateFrom', 'dateTo'], false);
24+
$this->createIndexIfMissing(Table::CATALOG_PRICING, ['purchasableId', 'storeId', 'isPromotionalPrice', 'price'], false);
25+
$this->createIndexIfMissing(Table::CATALOG_PRICING, ['purchasableId', 'storeId'], false);
26+
27+
return true;
28+
}
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
public function safeDown(): bool
34+
{
35+
echo "m251111_092942_ensure_catalog_pricing_indexes cannot be reverted.\n";
36+
return false;
37+
}
38+
}

0 commit comments

Comments
 (0)