Fix guardian mode: create missing tables on startup, fix conversations column name

- Add CREATE TABLE IF NOT EXISTS for guardian_config and guardian_events in
  reactor lifespan so tables are created automatically on next restart
- Fix conversations column bug: reactor used 'message' but schema has 'content';
  fix INSERT and SELECT queries to use content (SELECT aliases it as 'message'
  so the JSON response key stays the same)
- Add guardian tables to schema.sql for documentation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X8tDRrQqgLjqXebMCBNcP3
This commit is contained in:
2026-07-01 03:49:10 -05:00
parent 90e4ded7c9
commit 651455cb47
2 changed files with 66 additions and 4 deletions
+37
View File
@@ -441,4 +441,41 @@ CREATE TABLE `users` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--
-- Table structure for table `guardian_config`
--
CREATE TABLE IF NOT EXISTS `guardian_config` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`key_name` varchar(64) NOT NULL,
`value` varchar(255) NOT NULL DEFAULT '',
`updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`id`),
UNIQUE KEY `uk_key` (`key_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table `guardian_events`
--
CREATE TABLE IF NOT EXISTS `guardian_events` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`event_type` varchar(64) NOT NULL,
`severity` enum('info','warning','critical') NOT NULL DEFAULT 'info',
`agent_id` varchar(64) NOT NULL DEFAULT '',
`hostname` varchar(128) NOT NULL DEFAULT '',
`metric` varchar(64) NOT NULL DEFAULT '',
`value` float NOT NULL DEFAULT 0,
`threshold` float NOT NULL DEFAULT 0,
`message` text NOT NULL,
`ai_analysis` text NOT NULL DEFAULT '',
`acknowledged` tinyint(1) NOT NULL DEFAULT 0,
`created_at` datetime NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
KEY `idx_severity` (`severity`),
KEY `idx_ack` (`acknowledged`),
KEY `idx_created` (`created_at`),
KEY `idx_agent` (`agent_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- Dump completed on 2026-06-29 23:15:44