Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ IMPORTANT NOTE: This version only works on CACTI 1.x++!
* issue#343: Run engine unit tests in-process where they no longer need isolation
* issue#346: Split js/editor.js into dialog, picker, compact-editor and asset-library scripts so browser tests load whole files
* issue#351: Keep an unrecognised target, a zero-width or doubled-back link, the first sample of a new poller_output row and a */0 schedule from aborting the poller, and accept lists and ranges in map schedules
* issue: Fix the database upgrade failing to add a missing debug column to weathermap_maps and repair affected installations already marked as 2.1
* issue: Keep the editor toolbar "Return to Map"/"Return to Manage" button on two lines instead of wrapping onto three
* issue: Render editor text and image paths as data, escape backslashes and line breaks in the legacy example helper, and use a CSPRNG for random values
* issue: Select the narrowest matching scale range, preserve collinear route reversals, and keep link position calculations within path endpoints
Expand Down
6 changes: 5 additions & 1 deletion includes/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function weathermap_setup_table() {
}

if (!db_column_exists('weathermap_maps', 'debug')) {
db_execute('ALTER TABLE weathermap_maps ADD COLUMN debug `debug` set("on","off","once") NOT NULL DEFAULT "off" AFTER warncount');
db_execute('ALTER TABLE weathermap_maps ADD COLUMN `debug` set("on","off","once") NOT NULL DEFAULT "off" AFTER warncount');
Comment thread
TheWitness marked this conversation as resolved.
Resolved
}

if (!db_column_exists('weathermap_maps', 'config')) {
Expand Down Expand Up @@ -278,6 +278,10 @@ function weathermap_setup_table() {
break;
}
}
} elseif ($dbversion === '2.1' && !db_column_exists('weathermap_maps', 'debug')) {
// The original 2.1 upgrade recorded success even when ADD COLUMN failed.
// Repair only that omission; checking the column also permits a later retry.
db_execute('ALTER TABLE weathermap_maps ADD COLUMN `debug` set("on","off","once") NOT NULL DEFAULT "off" AFTER warncount');
}

// Normalize invalid sizes even when the schema version is already current.
Expand Down
42 changes: 42 additions & 0 deletions tests/Unit/WeathermapUpgradeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,48 @@ public function testUnrelatedPageSkipsUpgrade(): void {
self::assertEmpty($GLOBALS['__test_db_calls']);
}

/** Verify the missing debug column is added with a valid SET definition. */
public function testUpgradeAddsMissingDebugColumn(): void {
weathermap_setup_table();
$queries = array_column($GLOBALS['__test_db_calls'], 'sql');
self::assertContains(
'ALTER TABLE weathermap_maps ADD COLUMN `debug` set("on","off","once") NOT NULL DEFAULT "off" AFTER warncount',
$queries
);
}

/** Recover the failed 2.1 migration without rerunning unrelated upgrades. */
public function testCurrentVersionRepairsMissingDebugColumn(): void {
$GLOBALS['__test_config_options']['weathermap_db_version'] = plugin_weathermap_numeric_version();
$GLOBALS['__test_table_exists']['weathermap_maps'] = true;
self::assertSame('2.1', plugin_weathermap_numeric_version());

weathermap_setup_table();
self::assertSame([
'ALTER TABLE weathermap_maps ADD COLUMN `debug` set("on","off","once") NOT NULL DEFAULT "off" AFTER warncount',
], array_column($GLOBALS['__test_db_calls'], 'sql'));

// A failed ALTER leaves the column absent: the next call must retry.
$GLOBALS['__test_db_calls'] = [];
weathermap_setup_table();
self::assertCount(1, $GLOBALS['__test_db_calls']);

// Once the column exists, subsequent calls must leave the schema alone.
$GLOBALS['__test_column_exists']['weathermap_maps']['debug'] = true;
$GLOBALS['__test_db_calls'] = [];
weathermap_setup_table();
self::assertEmpty($GLOBALS['__test_db_calls']);
}

/** A healthy current installation needs no schema writes. */
public function testCurrentVersionWithDebugColumnSkipsSchemaChanges(): void {
$GLOBALS['__test_config_options']['weathermap_db_version'] = plugin_weathermap_numeric_version();
$GLOBALS['__test_table_exists']['weathermap_maps'] = true;
$GLOBALS['__test_column_exists']['weathermap_maps']['debug'] = true;
weathermap_setup_table();
self::assertEmpty($GLOBALS['__test_db_calls']);
}

/**
* Verify a version drift updates the realm and version metadata.
*
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap-unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function db_index_exists($t, $i) {

if (!function_exists('db_column_exists')) {
function db_column_exists($t, $c) {
return false;
return $GLOBALS['__test_column_exists'][$t][$c] ?? false;
}
}

Expand Down
Loading