Repository navigation
fix(upgrade): stop the second schema pass re-adding columns on notification_queue - #938
Conversation
…cation_queue thold_upgrade_database() reconciles the schema before and after its version-gated migrations. Cacti's db_column_exists() and db_table_exists() remember a negative answer for the request unless IN_PLUGIN_INSTALL is defined, so the second pass saw columns the first pass had just added as missing, issued ADD again and failed the whole ALTER with a duplicate column error. Define the constant before the first pass, as core does for installs run from the plugin manager. Fixes Cacti#933 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The stubs were declared with eval. They now live in a fixture file loaded with require_once; the test still fails on develop and passes with the fix. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
|
Checked against Cacti 1.2.32 core. |
TheWitness
left a comment
There was a problem hiding this comment.
Reviewed. IN_PLUGIN_INSTALL only affects core's schema-cache lookups (lib/database.php 1457/1539; lib/poller.php 2284 needs IN_CACTI_INSTALL as well), so defining it for the upgrade has no other side effects. The suite passes merged with current develop.



Problem
Upgrading from 1.8.2 or 1.8.1 to
developlogsDuplicate column name 'attempt_count'andPlugin 'thold' could not update table 'notification_queue'.thold_upgrade_database()reconciles the schema before and after its migrations (the second pass undoes a laterMODIFYonthold_data.name, so both passes are needed). Core'sdb_column_exists()anddb_table_exists()keep their answers in a static for the rest of the request unlessIN_PLUGIN_INSTALLorIN_CACTI_INSTALLis defined. Core definesIN_PLUGIN_INSTALLfor installs from the plugin manager, but not for an upgrade started from a plugin page or the command line, so the second pass saw the new columns as missing, added them again, and the wholeALTERfailed.Fix
Define
IN_PLUGIN_INSTALL(if not already defined) before the first pass, the same way core's plugin manager andcli/audit_database.phpdo, so both passes read the live schema. The only other effect is that core's table and column caches are bypassed for the rest of that request, which happens only during an upgrade.Verification
tests/Unit/UpgradeSchemaCacheTest.phpfails on currentdevelopand passes with the change. Full Pest suite on PHP 8.3: 728 passed, 1 skipped.cacti.log, the general log showsADD attempt_countonce, and the plugin version moves to 1.8.3. A fresh install ofdevelopis unchanged.attempt_countandnext_attempt(they are appended at the end rather than aftererror_message). Neither is changed here.CHANGELOG line for the release PR:
* issue#933: Stop an upgrade run from a page or the command line adding columns to notification_queue twiceFixes #933