<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Added database migration script to standardize router naming from dash-separated to underscore-separated format and remove deprecated tables.
**Key changes:**
- Implemented `migrate_router_names.py` with dry-run, migration, and verification modes
- Automatically creates timestamped SQLite backups before migration unless `--no-backup` is specified
- Updates router columns and `file_path` references across 6 active tables (`netflow_stats`, `processed_files`, `ip_stats`, `protocol_stats`, `spectrum_stats`, `structure_stats`)
- Drops 6 deprecated tables (`spectrum_results`, `structure_results`, `old_ip_stats`, `old_protocol_stats`, `hll_ip_stats`, `maad_metadata`)
- Uses parameterized queries for router column updates to prevent SQL injection
- Provides verification mode to check migration completeness
**Issues found:**
- `REPLACE` function on line 175 replaces all occurrences of old router name in file paths, which could cause unintended results if router names appear multiple times in a path (though unlikely given current path structure)
<h3>Confidence Score: 4/5</h3>
- Safe to merge with minor consideration for REPLACE logic behavior
- Well-structured migration script with proper safety features (backups, dry-run, verification). Uses parameterized queries to prevent SQL injection. The REPLACE logic on file paths could potentially cause issues in edge cases, but given the expected file path structure this is unlikely to occur in practice. Transaction handling and error checking are appropriate.
- No files require special attention
<h3>Important Files Changed</h3>
| Filename | Overview |
|----------|----------|
| netflow-db/migrate_router_names.py | Added migration script to rename routers from dash to underscore and drop deprecated tables. Script includes dry-run mode, backup functionality, and verification. Minor potential issue with REPLACE logic on file paths. |
</details>
<h3>Sequence Diagram</h3>
```mermaid
sequenceDiagram
participant User
participant Script as migrate_router_names.py
participant SQLite as flowStats.db
participant Backup as Backup Process
User->>Script: Execute with flags (--dry-run/--verify-only/default)
alt Verify Only Mode
Script->>SQLite: Query routers with '-' across tables
Script->>SQLite: Check deprecated table existence
Script->>User: Display verification results
else Dry Run Mode
Script->>SQLite: Detect routers containing '-'
Script->>SQLite: Count affected rows (router columns)
Script->>SQLite: Count affected rows (file_path columns)
Script->>SQLite: Check deprecated tables
Script->>User: Display impact report (no changes)
else Migration Mode
alt Backup Enabled (default)
Script->>Backup: Create timestamped backup
Backup-->>Script: Return backup path
end
Script->>SQLite: BEGIN transaction
Script->>SQLite: Get router mappings (dash to underscore)
loop For each table in ROUTER_TABLES
Script->>SQLite: UPDATE router columns (old → new)
end
loop For each table in FILE_PATH_TABLES
Script->>SQLite: UPDATE file_path with REPLACE()
end
loop For each table in DROP_TABLES
Script->>SQLite: DROP TABLE if exists
end
Script->>SQLite: COMMIT transaction
Script->>User: Display migration results
end
```
<sub>Last reviewed commit: df92f90</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->1 file changedLine totals unavailable