diff --git a/webapp/api.php b/webapp/api.php index 4528589..f0f6a94 100644 --- a/webapp/api.php +++ b/webapp/api.php @@ -1958,7 +1958,7 @@ function handleSchemaCheck($db) { jsonResponse(['error' => 'Method not allowed'], 405); } - $schemaUrl = 'https://git.prpl.tools/PurpleComputing/geofeed-manager/raw/branch/main/database/schema.sql'; + $schemaUrl = 'https://git.prpl.tools/PurpleComputing/ip-manager/raw/branch/main/database/schema.sql'; try { // Fetch remote schema @@ -2058,9 +2058,34 @@ function handleSchemaCheck($db) { $hasUpdates = !empty($missingTables) || !empty($missingColumns) || !empty($missingIndexes); + // Build changes array for frontend + $changes = []; + foreach ($missingTables as $table) { + $changes[] = [ + 'type' => 'table', + 'name' => $table, + 'description' => "Create table: $table" + ]; + } + foreach ($missingColumns as $col) { + $changes[] = [ + 'type' => 'column', + 'name' => $col['table'] . '.' . $col['column'], + 'description' => "Add column {$col['column']} to {$col['table']}" + ]; + } + foreach ($missingIndexes as $idx) { + $changes[] = [ + 'type' => 'index', + 'name' => $idx['table'] . '.' . $idx['index'], + 'description' => "Add index {$idx['index']} to {$idx['table']}" + ]; + } + jsonResponse([ 'success' => true, 'has_updates' => $hasUpdates, + 'changes' => $changes, 'missing_tables' => $missingTables, 'missing_columns' => $missingColumns, 'missing_indexes' => $missingIndexes, @@ -2087,7 +2112,7 @@ function handleSchemaApply($db) { jsonResponse(['error' => 'Invalid CSRF token'], 403); } - $schemaUrl = 'https://git.prpl.tools/PurpleComputing/geofeed-manager/raw/branch/main/database/schema.sql'; + $schemaUrl = 'https://git.prpl.tools/PurpleComputing/ip-manager/raw/branch/main/database/schema.sql'; try { // Fetch remote schema @@ -2199,8 +2224,24 @@ function handleSchemaApply($db) { 'failed' => $failed ]); + // Build results array for frontend + $results = []; + foreach ($applied as $item) { + $results[] = [ + 'success' => true, + 'description' => $item + ]; + } + foreach ($failed as $item) { + $results[] = [ + 'success' => false, + 'description' => $item + ]; + } + jsonResponse([ 'success' => true, + 'results' => $results, 'applied' => $applied, 'failed' => $failed, 'message' => count($applied) > 0 ? 'Schema updates applied successfully' : 'No updates needed'