Repository navigation
Fix fatal PRIMARY KEY (Array) on fresh install from array primary key - #56
Merged
Merged
Conversation
TheWitness
requested review from
bmfmancini and
xmacan
and
a balanced review from Copilot
October 15, 2026 13:33
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Two existing tests still expect array-valued create-call primary keys and fail after normalization.
1 open finding
What changed in this PR
Fixes fresh-install table creation by adapting primary-key definitions to Cacti’s create API while preserving the array form needed for upgrades.
Changes:
- Normalizes primary keys at every table-create call.
- Adds regression coverage for create and upgrade definition formats.
| File | Description |
|---|---|
| tests/Unit/SetupTableApiUsageTest.php | Adds primary-key format assertions. |
| includes/database.php | Adds and applies the create-definition adapter. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
xmacan
approved these changes
Oct 15, 2026
xmacan
previously approved these changes
Oct 15, 2026
xmacan
previously approved these changes
Oct 15, 2026
xmacan
approved these changes
Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
On a fresh install,
slowlog_setup_table_new()handsapi_plugin_db_table_create()several table definitions whoseprimaryis declared in the array form, e.g.:Down to this plugin''s
compat = 1.2.29floor,api_plugin_db_table_create()(lib/plugins.php) interpolates the primary key straight into the DDL string:With an array, PHP renders it as
PRIMARY KEY (`Array`), so theCREATE TABLEfails and the table is never created on Cacti 1.2.29-1.2.31.This is the fresh-install mirror of the upgrade-path fatal fixed in plugin_routerconfigs #191:
api_plugin_db_table_create()requires the scalar primary form, whiledb_update_table()(used here forplugin_slowlog_details) requires the array form.Fix
Add a
slowlog_create_definition()helper that flattens an arrayprimaryto the backtick-joined scalar form, and wrap everyapi_plugin_db_table_create()call with it (a no-op for the tables that already declare a scalar primary). Theslowlog_details_table_data()definition keeps the array form thatdb_update_table()still requires on the upgrade path. This mirrors the helpers already present in plugin_maint, plugin_apcupsd, plugin_exlist, plugin_lsflog and plugin_stream.Validation
php -l includes/database.php- no syntax errors.slowlog_details_table_data()keeps the array form.