fixing db
Deploy / deploy (push) Successful in 39s

This commit is contained in:
2026-05-07 21:17:46 +02:00
parent 01e68cce9b
commit 105bbb2b2c
2 changed files with 38 additions and 17 deletions
+23 -2
View File
@@ -15,7 +15,7 @@ require_once __DIR__ . '/../config/database.php';
$db = getDbConnection();
// Ensure notes column exists
try { $db->exec("ALTER TABLE network_nodes ADD COLUMN notes TEXT DEFAULT '' AFTER group_name"); } catch (Exception $e) {}
try { $db->exec("ALTER TABLE network_nodes ADD COLUMN notes TEXT DEFAULT ''"); } catch (Exception $e) {}
// Auth check (except for session check)
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
@@ -370,6 +370,7 @@ function handleNodes($method, $id, $db) {
break;
case 'POST':
$data = json_decode(file_get_contents('php://input'), true);
try {
$stmt = $db->prepare("
INSERT INTO network_nodes (label, ip_address, node_type, status, group_name, pos_x, pos_y, notes)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
@@ -384,6 +385,22 @@ function handleNodes($method, $id, $db) {
$data['pos_y'] ?? 0,
$data['notes'] ?? ''
]);
} catch (Exception $e) {
// Fallback without notes column
$stmt = $db->prepare("
INSERT INTO network_nodes (label, ip_address, node_type, status, group_name, pos_x, pos_y)
VALUES (?, ?, ?, ?, ?, ?, ?)
");
$stmt->execute([
$data['label'],
$data['ip_address'] ?? '',
$data['node_type'] ?? 'host',
$data['status'] ?? 'unknown',
$data['group_name'] ?? 'default',
$data['pos_x'] ?? 0,
$data['pos_y'] ?? 0
]);
}
echo json_encode(['id' => $db->lastInsertId()]);
break;
case 'PUT':
@@ -391,7 +408,7 @@ function handleNodes($method, $id, $db) {
$data = json_decode(file_get_contents('php://input'), true);
$fields = [];
$params = [];
foreach (['label','ip_address','node_type','status','group_name','pos_x','pos_y','notes'] as $f) {
foreach (['label','ip_address','node_type','status','group_name','pos_x','pos_y'] as $f) {
if (isset($data[$f])) {
$fields[] = "$f = ?";
$params[] = $data[$f];
@@ -402,6 +419,10 @@ function handleNodes($method, $id, $db) {
$stmt = $db->prepare("UPDATE network_nodes SET " . implode(', ', $fields) . " WHERE id = ?");
$stmt->execute($params);
}
// Update notes separately (column may not exist)
if (isset($data['notes'])) {
try { $db->prepare("UPDATE network_nodes SET notes = ? WHERE id = ?")->execute([$data['notes'], $id]); } catch (Exception $e) {}
}
echo json_encode(['updated' => true]);
}
break;
+1 -1
View File
@@ -39,7 +39,7 @@ function migrate($db) {
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)");
try {
$db->exec("ALTER TABLE network_nodes ADD COLUMN notes TEXT DEFAULT '' AFTER group_name");
$db->exec("ALTER TABLE network_nodes ADD COLUMN notes TEXT DEFAULT ''");
} catch (Exception $e) {
}
}