Skip to content

Fix fatal PRIMARY KEY (Array) on fresh install from array primary key - #59

Merged
TheWitness merged 1 commit into
mainfrom
fix/create-path-array-primary
Oct 15, 2026
Merged

TheWitness merged 1 commit into
mainfrom
fix/create-path-array-primary

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Problem

On a fresh install, plugin_evidence_initialize_database() hands api_plugin_db_table_create() two table definitions whose primary is declared in the array form:

$data['primary'] = ['id'];   // plugin_evidence_organization, plugin_evidence_specific_query

Down to this plugin''s compat = 1.2.29 floor, api_plugin_db_table_create() (lib/plugins.php) interpolates the primary key straight into the DDL string:

$sql .= ",\n PRIMARY KEY (`" . $data['primary'] . '`)';

With an array, PHP renders it as PRIMARY KEY (`Array`), so the CREATE TABLE fails and the table is never created on Cacti 1.2.29-1.2.31.

This is the fresh-install counterpart of the primary-key form incompatibility fixed for the upgrade path in plugin_routerconfigs #191: api_plugin_db_table_create() requires the scalar primary form.

Fix

Evidence only ever creates these tables (it has no db_update_table() path that would need the array form), so the two definitions are changed to the scalar 'id' form that api_plugin_db_table_create() expects.

Validation

  • php -l includes/database.php - no syntax errors.
  • Added regression coverage asserting every create call that declares a primary passes it as a scalar.

@TheWitness
TheWitness requested review from bmfmancini and xmacan and a balanced review from Copilot October 15, 2026 13:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused fix matches the table-creation API contract and includes targeted regression coverage, with no unresolved findings.

0 open findings

What changed in this PR

Fixes fresh-install table creation by using scalar primary-key definitions compatible with Cacti 1.2.29–1.2.31.

Changes:

  • Changes both affected primary keys from ['id'] to 'id'.
  • Adds regression coverage requiring string primary keys in table-creation calls.
File Description
tests/​Unit/​EvidenceDatabaseTest.php Adds scalar primary-key regression coverage.
includes/​database.php Corrects primary-key definitions for two tables.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@TheWitness
TheWitness merged commit 45f1064 into main Oct 15, 2026
4 checks passed
@TheWitness
TheWitness requested a review from xmacan October 15, 2026 13:37
@TheWitness
TheWitness deleted the fix/create-path-array-primary branch October 15, 2026 13:41
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.

3 participants