Skip to content

fix(upgrade): stop the second schema pass re-adding columns on notification_queue - #938

Merged
TheWitness merged 2 commits into
Cacti:developfrom
somethingwithproof:fix/upgrade-duplicate-column
Dec 4, 2026
Merged

TheWitness merged 2 commits into
Cacti:developfrom
somethingwithproof:fix/upgrade-duplicate-column

Conversation

@somethingwithproof

Copy link
Copy Markdown
Member

Problem

Upgrading from 1.8.2 or 1.8.1 to develop logs Duplicate column name 'attempt_count' and Plugin 'thold' could not update table 'notification_queue'. thold_upgrade_database() reconciles the schema before and after its migrations (the second pass undoes a later MODIFY on thold_data.name, so both passes are needed). Core's db_column_exists() and db_table_exists() keep their answers in a static for the rest of the request unless IN_PLUGIN_INSTALL or IN_CACTI_INSTALL is defined. Core defines IN_PLUGIN_INSTALL for 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 whole ALTER failed.

Fix

Define IN_PLUGIN_INSTALL (if not already defined) before the first pass, the same way core's plugin manager and cli/audit_database.php do, 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

  • New tests/Unit/UpgradeSchemaCacheTest.php fails on current develop and passes with the change. Full Pest suite on PHP 8.3: 728 passed, 1 skipped.
  • Live upgrade on Cacti 1.2.x with MariaDB 11.8, from v1.8.2 and from v1.8.1: no errors in cacti.log, the general log shows ADD attempt_count once, and the plugin version moves to 1.8.3. A fresh install of develop is unchanged.
  • The upgraded schema still differs from a fresh install by the five defaults in A fresh install and an upgrade give different defaults on five columns #934, and by the position of attempt_count and next_attempt (they are appended at the end rather than after error_message). Neither is changed here.
  • Not tested: an upgrade through the plugin manager page, Cacti develop, other MariaDB or MySQL versions.

CHANGELOG line for the release PR:
* issue#933: Stop an upgrade run from a page or the command line adding columns to notification_queue twice

Fixes #933

…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>
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@TheWitness

Copy link
Copy Markdown
Member

Checked against Cacti 1.2.32 core. db_table_exists() and db_column_exists() (lib/database.php lines 1457 and 1539) return the cached answer unless IN_CACTI_INSTALL or IN_PLUGIN_INSTALL is defined. Defining IN_PLUGIN_INSTALL before the two thold_setup_database() passes is therefore enough for the second pass to see the column the first pass added. That double pass comes from the #905 upgrade restructuring, so this is the right place for the fix. CI is green, and the branch merges cleanly on top of the #906 stack (#923).

@TheWitness TheWitness left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@TheWitness
TheWitness merged commit 4b63387 into Cacti:develop Dec 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade from 1.8.2 logs Duplicate column name 'attempt_count' on notification_queue

3 participants