craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
215 stars 169 forks source link

[5.x]: Error when upgrading from Commerce 4 #3488

Closed boboldehampsink closed 2 months ago

boboldehampsink commented 2 months ago

What happened?

Description

When upgrading from Commerce 4, while using the fix in #3486 to boot this on Postgres, I see the following error:

...
web-1  | *** applying m221122_055725_multi_store
web-1  |     > create table {{%commerce_storesettings}} ... done (time: 0.002s)
web-1  |     > add foreign key fk_ffmjdquysmkgdmcujclkcciweeclyswyijbf: {{%commerce_storesettings}} (id) references {{%commerce_stores}} (id) ... done (time: 0.000s)
web-1  |     > insert into {{%commerce_storesettings}} ... done (time: 0.004s)
web-1  |     > drop column locationAddressId from table {{%commerce_stores}} ... done (time: 0.000s)
web-1  |     > drop column countries from table {{%commerce_stores}} ... done (time: 0.000s)
web-1  |     > drop column marketAddressCondition from table {{%commerce_stores}} ... done (time: 0.000s)
web-1  |     > add column name string NOT NULL DEFAULT '' to table {{%commerce_stores}} ... done (time: 0.000s)
web-1  |     > add column handle string NOT NULL DEFAULT '' to table {{%commerce_stores}} ... done (time: 0.000s)
web-1  |     > add column primary boolean NOT NULL DEFAULT FALSE to table {{%commerce_stores}} ... done (time: 0.000s)
web-1  |     > update in {{%commerce_stores}} ... done (time: 0.003s)
web-1  | Exception: Undefined array key "autoSetNewCartAddresses" (/app/user/vendor/craftcms/commerce/src/services/Stores.php:385)
web-1  | #0 /app/user/vendor/craftcms/commerce/src/services/Stores.php(385): yii\base\ErrorHandler->handleError(2, 'Undefined array...', '/app/user/vendo...', 385)
web-1  | #1 /app/user/vendor/craftcms/cms/src/services/ProjectConfig.php(1177): craft\commerce\services\Stores->handleChangedStore(Object(craft\events\ConfigEvent))
web-1  | #2 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
web-1  | #3 /app/user/vendor/yiisoft/yii2/base/Component.php(633): call_user_func(Array, Object(craft\events\ConfigEvent))
web-1  | #4 /app/user/vendor/craftcms/cms/src/models/ProjectConfigData.php(82): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
web-1  | #5 /app/user/vendor/craftcms/cms/src/services/ProjectConfig.php(564): craft\models\ProjectConfigData->commitChanges(NULL, Array, 'commerce.stores...', true, 'Migration creat...', true)
...

Steps to reproduce

Upgrade from Commerce 4

Craft CMS version

5

Craft Commerce version

5

PHP version

8.3

Operating system and version

No response

Database type and version

PostgreSQL 15.3

Image driver and version

No response

Installed plugins and versions

-

linear[bot] commented 2 months ago

PT-1706 [5.x]: Error when upgrading from Commerce 4

lukeholder commented 2 months ago

@boboldehampsink can you please send me your Craft Commerce 4 DB backup, with the config/project folder, and composer.json, and composer.lock to support@craftcms.com so I can debug this. Thanks.

lukeholder commented 2 months ago

Thanks for that. I think the issues are now fixed.

To get the fix early, change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "5.x-dev#323ac6403f8a91812af074811fab37fb5e021e93 as 5.0.3",
  "...": "..."
}

Then run composer update.

I will let you know once the release is out here.

lukeholder commented 2 months ago

5.0.5 is out and contains fixes from upgrading from 4.x

boboldehampsink commented 1 month ago

@lukeholder got 5.0.5 and now seeing this error when upgrading:

> add column autoSetPaymentSource boolean NOT NULL DEFAULT FALSE to table {{%commerce_stores}} ...Exception: SQLSTATE[42701]: Duplicate column: 7 ERROR:  column "autoSetPaymentSource" of relation "commerce_stores" already exists
web-1  | The SQL being executed was: ALTER TABLE "commerce_stores" ADD "autoSetPaymentSource" boolean NOT NULL DEFAULT FALSE (/app/user/vendor/yiisoft/yii2/db/Schema.php:676)
web-1  | #0 /app/user/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'ALTER TABLE "co...')
boboldehampsink commented 1 month ago

@lukeholder is this related or do I need to create a new issue?

lukeholder commented 1 month ago

This should be fixed in 5.0.6