spicywebau / craft-neo

A Matrix-like field type for Craft CMS that uses existing fields
Other
402 stars 63 forks source link

[documentation request]Docs on updating Neo 2.5.x => 2.7.x while updating to Craft 3.4 #326

Closed tomdavies closed 4 years ago

tomdavies commented 4 years ago

Hey,

I have a suggestion for an addition to the docs.

I found I was getting a failed craft (core) migration when attempting to upgrade from Neo 2.5.10 => 2.7.3 at the same time as updating from Craft 3.3.20.1 => 3.4.11

I traced it to the fact that ./craft migrate/all will run Craft's own migrations before plugin migration. However because the 3.4 update triggers element resaves, these resaves in turn result in Neo 2.7.3 calls before Neo's own migrations have run, making everything explode (stack trace below for completeness)

The solution is to run

./craft migrate/up --plugin=neo

before running

./craft migrate/all

Other information

Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'neoblocks.sortOrder' in 'field list'
The SQL being executed was: SELECT `elements`.`id`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`slug`, `elements_sites`.`siteId`, `elements_sites`.`uri`, `elements_sites`.`enabled` AS `enabledForSite`, `neoblocks`.`fieldId`, `neoblocks`.`ownerId`, `neoblocks`.`typeId`, `neoblocks`.`sortOrder`, `content`.`id` AS `contentId`, `structureelements`.`root`, `structureelements`.`lft`, `structureelements`.`rgt`, `structureelements`.`level`
FROM (SELECT `elements`.`id` AS `elementsId`, `elements_sites`.`id` AS `elementsSitesId`, `content`.`id` AS `contentId`
FROM `elements` `elements`
INNER JOIN `neoblocks` `neoblocks` ON `neoblocks`.`id` = `elements`.`id`
INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`elementId` = `elements`.`id`
INNER JOIN `content` `content` ON (`content`.`elementId` = `elements`.`id`) AND (`content`.`siteId` = `elements_sites`.`siteId`)
INNER JOIN `structureelements` `structureelements` ON (`structureelements`.`elementId` = `elements`.`id`) AND (`structureelements`.`structureId`='7034')
WHERE (`neoblocks`.`fieldId`='258') AND (`neoblocks`.`ownerId`='1828') AND (`elements_sites`.`siteId`='3') AND (`elements`.`archived`=FALSE) AND (`elements`.`dateDeleted` IS NULL) AND (`elements`.`draftId` IS NULL) AND (`elements`.`revisionId` IS NULL)) `subquery`
INNER JOIN `neoblocks` `neoblocks` ON `neoblocks`.`id` = `subquery`.`elementsId`
INNER JOIN `elements` `elements` ON `elements`.`id` = `subquery`.`elementsId`
INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`id` = `subquery`.`elementsSitesId`
INNER JOIN `content` `content` ON `content`.`id` = `subquery`.`contentId`
INNER JOIN `structureelements` `structureelements` ON (`structureelements`.`elementId` = `subquery`.`elementsId`) AND (`structureelements`.`structureId`='7034')
ORDER BY `neoblocks`.`sortOrder` (/app/vendor/yiisoft/yii2/db/Schema.php:674)
#0 /app/vendor/yiisoft/yii2/db/Command.php(1298): yii\db\Schema->convertException(Object(PDOException), 'SELECT `element...')
#1 /app/vendor/yiisoft/yii2/db/Command.php(1159): yii\db\Command->internalExecute('SELECT `element...')
#2 /app/vendor/yiisoft/yii2/db/Command.php(401): yii\db\Command->queryInternal('fetchAll', NULL)
#3 /app/vendor/yiisoft/yii2/db/Query.php(237): yii\db\Command->queryAll()
#4 /app/vendor/craftcms/cms/src/db/Query.php(152): yii\db\Query->all(NULL)
#5 /app/vendor/craftcms/cms/src/elements/db/ElementQuery.php(1471): craft\db\Query->all(NULL)
#6 /app/vendor/spicyweb/craft-neo/src/elements/db/BlockQuery.php(259): craft\elements\db\ElementQuery->all(NULL)
#7 /app/vendor/spicyweb/craft-neo/src/services/Fields.php(319): benf\neo\elements\db\BlockQuery->all()
#8 /app/vendor/spicyweb/craft-neo/src/Field.php(686): benf\neo\services\Fields->duplicateBlocks(Object(benf\neo\Field), Object(craft\elements\Entry), Object(craft\elements\Entry), true)
#9 /app/vendor/craftcms/cms/src/base/Element.php(2555): benf\neo\Field->afterElementPropagate(Object(craft\elements\Entry), true)
#10 /app/vendor/craftcms/cms/src/elements/Entry.php(1283): craft\base\Element->afterPropagate(true)
#11 /app/vendor/craftcms/cms/src/services/Elements.php(855): craft\elements\Entry->afterPropagate(true)
#12 /app/vendor/craftcms/cms/src/services/Revisions.php(160): craft\services\Elements->duplicateElement(Object(craft\elements\Entry), Array)
#13 /app/vendor/craftcms/cms/src/elements/Entry.php(1287): craft\services\Revisions->createRevision(Object(craft\elements\Entry), NULL, NULL)
#14 /app/vendor/craftcms/cms/src/services/Elements.php(2144): craft\elements\Entry->afterPropagate(false)
#15 /app/vendor/craftcms/cms/src/services/Elements.php(530): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, true, true)
#16 /app/vendor/craftcms/cms/src/services/Sections.php(1566): craft\services\Elements->saveElement(Object(craft\elements\Entry))
#17 /app/vendor/craftcms/cms/src/services/Sections.php(776): craft\services\Sections->_ensureSingleEntry(Object(craft\models\Section), Array)
#18 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(1099): craft\services\Sections->handleChangedSection(Object(craft\events\ConfigEvent))
#19 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#20 /app/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Array, Object(craft\events\ConfigEvent))
#21 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(675): yii\base\Component->trigger('updateItem', Object(craft\events\ConfigEvent))
#22 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(1089): craft\services\ProjectConfig->processConfigChanges('sections.198002...')
#23 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#24 /app/vendor/yiisoft/yii2/base/Component.php(627): call_user_func(Array, Object(craft\events\ConfigEvent))
#25 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(672): yii\base\Component->trigger('addItem', Object(craft\events\ConfigEvent))
#26 /app/vendor/craftcms/cms/src/services/ProjectConfig.php(489): craft\services\ProjectConfig->processConfigChanges('sections.198002...', true, '')
#27 /app/vendor/craftcms/cms/src/migrations/m190913_152146_update_preview_targets.php(54): craft\services\ProjectConfig->set('sections.198002...', Array)
#28 /app/vendor/craftcms/cms/src/db/Migration.php(52): craft\migrations\m190913_152146_update_preview_targets->safeUp()
#29 /app/vendor/craftcms/cms/src/db/MigrationManager.php(233): craft\db\Migration->up(true)
#30 /app/vendor/craftcms/cms/src/db/MigrationManager.php(153): craft\db\MigrationManager->migrateUp(Object(craft\migrations\m190913_152146_update_preview_targets))
#31 /app/vendor/craftcms/cms/src/services/Updates.php(225): craft\db\MigrationManager->up()
#32 /app/vendor/craftcms/cms/src/console/controllers/MigrateController.php(259): craft\services\Updates->runMigrations(Array)
#33 [internal function]: craft\console\controllers\MigrateController->actionAll()
#34 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#35 /app/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#36 /app/vendor/yiisoft/yii2/console/Controller.php(164): yii\base\Controller->runAction('all', Array)
#37 /app/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('all', Array)
#38 /app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#39 /app/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application->runAction('migrate/all', Array)
#40 /app/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array)
#41 /app/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#42 /app/craft(22): yii\base\Application->run()
#43 {main}
Exception 'craft\errors\MigrateException' with message 'An error occurred while migrating Craft CMS.'

in /app/vendor/craftcms/cms/src/services/Updates.php:241

Stack trace:
#0 /app/vendor/craftcms/cms/src/console/controllers/MigrateController.php(259): craft\services\Updates->runMigrations(Array)
#1 [internal function]: craft\console\controllers\MigrateController->actionAll()
#2 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#3 /app/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#4 /app/vendor/yiisoft/yii2/console/Controller.php(164): yii\base\Controller->runAction('all', Array)
#5 /app/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('all', Array)
#6 /app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate/all', Array)
#7 /app/vendor/craftcms/cms/src/console/Application.php(87): yii\console\Application->runAction('migrate/all', Array)
#8 /app/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('migrate/all', Array)
#9 /app/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(craft\console\Request))
#10 /app/craft(22): yii\base\Application->run()
#11 {main}
pvldigital commented 4 years ago

Hi @tomdavies,

That's interesting, i'll have a look if I can prevent this issue from happening when updating to Craft 3.4. If not i'll update the docs as you suggested

rmdiaconu commented 4 years ago

Hey @tomdavies.

I encounter the same error and tried your solution, but I keep getting the same error.

Any chance you can tell me the steps you followed to update to Craft 3.4?

Thank you.

pvldigital commented 4 years ago

Hey @rmdiaconu,

Can you try updating to Craft 3.4 with neo set as "spicyweb/craft-neo": "2.6.5.1", within your composer file first? You can then revert neos version within composer and then update it.

Steps:

  1. Change neo within composer to "spicyweb/craft-neo": "2.6.5.1" (version before any migration changes for neo + 3.4 update).
  2. Update Craft to 3.4
  3. Revert neo within composer.
  4. Update neo
rmdiaconu commented 4 years ago

Hey @pvldigital, tried your solution and the following error occurred:

`Performing one update:

- craft 3.3.20.1 => 3.4.13

Backup the database? (yes|no) [no]:n Skipping database backup. Performing update with Composer ... error: An error occurred

Output:

Package "craftcms/vue-asset" listed for update is not installed. Ignoring. Package "danielstjules/stringy" listed for update is not installed. Ignoring.

Loading composer repositories with package information Updating dependencies Your requirements could not be resolved to an installable set of packages.

Problem 1

Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.`
pvldigital commented 4 years ago

Hi @rmdiaconu,

How are you updating to the latest craft version? Are you using the command line (if so what was the command)?

Can you also send over the composer file to plugins@spicyweb.com.au so I can have a look?

hiasl commented 4 years ago

@pvldigital We had the same issue as @tomdavies (hi btw :-) ) and I can confirm that locking to Neo to 2.6.5.1 in the first steps solves the problem.

It also solves another problem, which might happen when coming from before Craft 3.4.0 because the Neo migration of 3.7.5 tries to delete a row from the separate projectconfig table, which does not exist if Craft's migrations have not been done before migration Neo.

avr commented 4 years ago

I ran into this today and followed these steps without any issue.

Before the update, I was at Neo 2.5.10 and Craft 3.3.20.1

  1. Modify composer.json to set Craft to "3.4.0" and Neo to "2.6.5.1"
  2. From the command line, run composer update
  3. From the Admin CP, run the available updates independently (vs. running "Update All")
  4. After updating all my other plugins and Craft, finally update Neo to the latest version
pvldigital commented 4 years ago

@hiasl @avr good to know those steps worked for you. I'm currently working on a fix for this so any future updates will not have this issue.

tomdavies commented 4 years ago

Just to close the loop on this: updating to 2.6.5.1 first worked for me too. Many thanks @pvldigital. Feel free to close this issue if you have another place you're tracking the required change for a long term fix

pvldigital commented 4 years ago

Latest version v2.7.8 has a fix for this issue. Updating from an older version to Craft 3.4 shouldn't cause any issues.