diff --git a/includes/database.php b/includes/database.php index efa7a3e..70ff330 100644 --- a/includes/database.php +++ b/includes/database.php @@ -39,7 +39,7 @@ function plugin_evidence_initialize_database() { $data = []; $data['columns'][] = ['name' => 'id', 'type' => 'int(11)', 'NULL' => false]; $data['columns'][] = ['name' => 'organization', 'type' => 'varchar(200)', 'NULL' => false]; - $data['primary'] = ['id']; + $data['primary'] = 'id'; $data['type'] = 'InnoDB'; $data['comment'] = 'evidence organizations'; api_plugin_db_table_create('evidence', 'plugin_evidence_organization', $data); @@ -65,7 +65,7 @@ function plugin_evidence_initialize_database() { $data['columns'][] = ['name' => 'method', 'type' => 'enum("get", "walk", "info", "table")', 'default' => 'get', 'NULL' => false]; $data['columns'][] = ['name' => 'table_items', 'type' => 'varchar(100)', 'default' => null, 'NULL' => true]; $data['columns'][] = ['name' => 'mandatory', 'type' => 'enum("yes","no")', 'default' => 'yes', 'NULL' => false]; - $data['primary'] = ['id']; + $data['primary'] = 'id'; $data['type'] = 'InnoDB'; $data['comment'] = 'evidence specific'; api_plugin_db_table_create('evidence', 'plugin_evidence_specific_query', $data); diff --git a/tests/Unit/EvidenceDatabaseTest.php b/tests/Unit/EvidenceDatabaseTest.php index 233ce50..b307a90 100644 --- a/tests/Unit/EvidenceDatabaseTest.php +++ b/tests/Unit/EvidenceDatabaseTest.php @@ -38,6 +38,23 @@ )); }); +it('declares scalar primary keys for api_plugin_db_table_create', function () { + // api_plugin_db_table_create() interpolates data['primary'] straight into + // PRIMARY KEY (`...`) down to the 1.2.29 compat floor, so an array would + // render as PRIMARY KEY (`Array`) and fail the create on a fresh install. + plugin_evidence_setup_database(); + + $withPrimary = array_filter($GLOBALS['__test_db_calls'], function ($call) { + return $call['fn'] === 'api_plugin_db_table_create' && isset($call['params']['primary']); + }); + + expect($withPrimary)->not->toBeEmpty(); + + foreach ($withPrimary as $call) { + expect($call['params']['primary'])->toBeString(); + } +}); + it('seeds the vendor-specific query catalog', function () { plugin_evidence_setup_database();