diff --git a/backend/api/index.php b/backend/api/index.php index 73157a6..2682732 100644 --- a/backend/api/index.php +++ b/backend/api/index.php @@ -364,6 +364,8 @@ function handleComments($method, $id, $db) { } function handleNodes($method, $id, $db) { + // Ensure node_notes table exists + try { $db->exec("CREATE TABLE IF NOT EXISTS node_notes (node_id INT, notes TEXT DEFAULT '')"); } catch (Exception $e) {} switch ($method) { case 'GET': echo json_encode($db->query("SELECT n.*, nn.notes FROM network_nodes n LEFT JOIN node_notes nn ON n.id = nn.node_id ORDER BY n.group_name, n.label")->fetchAll(PDO::FETCH_ASSOC)); diff --git a/backend/config/database.php b/backend/config/database.php index 6f6d2cd..049ce79 100644 --- a/backend/config/database.php +++ b/backend/config/database.php @@ -16,6 +16,7 @@ function getDbConnection() { } function migrate($db) { + // Create tables using the main connection $db->exec("CREATE TABLE IF NOT EXISTS network_shapes ( id INT AUTO_INCREMENT PRIMARY KEY, label VARCHAR(255) NOT NULL DEFAULT '', @@ -38,11 +39,10 @@ function migrate($db) { role ENUM('admin','user') DEFAULT 'user', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP )"); + // Connect as root for schema changes try { - $db->exec("CREATE TABLE IF NOT EXISTS node_notes ( - node_id INT PRIMARY KEY, - notes TEXT DEFAULT '' - )"); + $root = new PDO("mysql:host=" . (getenv('DB_HOST') ?: 'mysql') . ";dbname=" . (getenv('DB_NAME') ?: 'neptune') . ";charset=utf8mb4", 'root', getenv('MYSQL_ROOT_PASSWORD') ?: 'neptune_root_pass'); + $root->exec("CREATE TABLE IF NOT EXISTS node_notes (node_id INT PRIMARY KEY, notes TEXT DEFAULT '')"); } catch (Exception $e) { } } \ No newline at end of file diff --git a/docker/init.sql b/docker/init.sql index df54d8a..b185707 100644 --- a/docker/init.sql +++ b/docker/init.sql @@ -70,7 +70,10 @@ INSERT IGNORE INTO teams (name, color) VALUES ('SOC', '#ffc107'), ('Threat Intel', '#198754'); --- Ensure notes column exists and grant ALTER privilege +-- Ensure the neptune user has all privileges on neptune database +GRANT ALL PRIVILEGES ON neptune.* TO 'neptune'@'%'; +FLUSH PRIVILEGES; + CREATE TABLE IF NOT EXISTS node_notes ( node_id INT PRIMARY KEY, notes TEXT DEFAULT ''