fix: database audit phase 2 — PG/MySQL crash prevention and schema alignment#2386
fix: database audit phase 2 — PG/MySQL crash prevention and schema alignment#2386
Conversation
…ignment - Fix getAuditStatsAsync using wrong column names (user_id → userId) for PG/MySQL - Add PG/MySQL guards to 6 maintenance methods that crashed via this.db.prepare() - Add repo methods: cleanupOldRouteSegments (traceroutes), cleanupOldNeighborInfo (neighbors) - Make async wrappers properly delegate to repos on PG/MySQL instead of calling sync methods - Add getDatabaseSizeAsync with pg_database_size()/information_schema for PG/MySQL - Add vacuumAsync with native VACUUM for PostgreSQL - Add grantedAt/grantedBy to PG/MySQL permission Drizzle schemas and baselines - Add valueBefore/valueAfter to PG/MySQL audit_log baselines - Remove auth repo branching that stripped grantedAt/grantedBy on PG/MySQL Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Claude finished @Yeraze's task —— View job Code Review for Database Audit Phase 2Review Checklist
Critical Issues Found ✅ FIXED1. Column Naming Bug - CRITICAL FIX ✅Issue:
Fix Applied: The PR correctly fixes these column references to match the Drizzle schema:
This fix resolves 500 errors on audit statistics pages. 2. Database Guards - CRITICAL FIX ✅Issue: Six maintenance methods crashed on PostgreSQL/MySQL due to SQLite-specific
Fix Applied: The PR correctly adds database type guards and delegates to appropriate repositories for PostgreSQL/MySQL while preserving SQLite behavior. Code Quality Assessment ✅ EXCELLENTPositive Aspects
Authentication Repository Changes ✅ GOODThe simplification of
Performance & Security ✅ NO ISSUES
Test Coverage ✅ COMPREHENSIVEThe PR reports excellent test coverage:
Migration Safety ✅ EXCELLENTThe baseline migration changes in
Final Recommendation: ✅ APPROVEThis is a high-quality, critical bugfix PR that should be merged immediately:
The code follows MeshMonitor's multi-database architecture perfectly and demonstrates excellent understanding of the codebase patterns. | |
Summary
Phase 2 of the database audit remediation. Fixes critical bugs that cause crashes on PostgreSQL/MySQL backends during scheduled maintenance (default 4:00 AM) and on admin pages.
Critical Fixes
getAuditStatsAsync— Fixed wrong column names (user_id→"userId"for PG,userIdfor MySQL) that caused 500 errors on the audit statistics pagecleanupOldTraceroutes,cleanupOldRouteSegments,cleanupOldNeighborInfo,cleanupAuditLogs,vacuum,getDatabaseSizewhich all crashed viathis.db.prepare()on non-SQLite backendscleanupOldTraceroutesAsync,cleanupOldRouteSegmentsAsync,cleanupOldNeighborInfoAsync,cleanupAuditLogsAsync,vacuumAsync,getDatabaseSizeAsyncto properly delegate to repos on PG/MySQLgetDatabaseSizeAsyncnow usespg_database_size()/information_schemafor PG/MySQL;vacuumAsyncuses native PostgreSQLVACUUMSchema Alignment (Medium)
grantedAt/grantedByto PG/MySQL permission Drizzle schemas and baselines — enables Drizzle read/write of these columnsvalueBefore/valueAfterto PG/MySQL audit_log baselines for consistency with SQLitegrantedAt/grantedByon PG/MySQL insertsNew Repository Methods
TraceroutesRepository.cleanupOldRouteSegments(days)— Drizzle-based cleanup for non-record-holder segmentsNeighborsRepository.cleanupOldNeighborInfo(days)— Drizzle-based cleanup for old neighbor infoTest Plan
npx vitest run— 3070 tests pass, 0 failuresnpm run build— no TypeScript errors./tests/system-tests.sh— 9/10 pass (1 pre-existing flaky favorite count test)Files Changed
src/services/database.ts— Guards + async wrapper fixessrc/db/repositories/traceroutes.ts— NewcleanupOldRouteSegmentsmethodsrc/db/repositories/neighbors.ts— NewcleanupOldNeighborInfomethodsrc/db/repositories/auth.ts— SimplifiedcreatePermissionbranchingsrc/db/schema/auth.ts— AddedgrantedAt/grantedByto PG/MySQL permission schemassrc/server/migrations/001_v37_baseline.ts— Added missing columns to PG/MySQL baselines🤖 Generated with Claude Code