SWMM Inputs and Runs to Scenarios Merge Plan
Executive Summary
This plan outlines the consolidation of the Inputs and Runs Azure tables into a single Scenarios table, eliminating the artificial 1:1 relationship and simplifying the data architecture.
New Unified Schema Design
SwmmScenarioEntity (Replaces SwmmInputEntity + SwmmRunEntity)
public class SwmmScenarioEntity : ITableEntity
{
// Azure Table Storage Properties
public string PartitionKey { get; set; } // ScenarioId
public string RowKey { get; set; } // "scenario" (fixed)
public DateTimeOffset? Timestamp { get; set; }
public ETag ETag { get; set; }
// Core Scenario Properties (from Inputs)
public string Name { get; set; } // NEW: Human-readable name
public string Description { get; set; } // NEW: Scenario description
public string InputFileName { get; set; }
public int SiteArea { get; set; }
public string TimeZone { get; set; }
public DateTime CreatedAt { get; set; } // NEW: Creation timestamp
public string CreatedBy { get; set; } // NEW: Creator identifier
public bool IsActive { get; set; } // NEW: Active status
// Simulation Parameters (from Inputs)
public string StartTime { get; set; }
public string EndTime { get; set; }
public int RainfallYear { get; set; }
public int ReportingTimeStep { get; set; }
public bool RunFlag { get; set; } // Triggers worker processing
// Run Results (from Runs - nullable for scenarios without runs)
public string? Status { get; set; } // Run status
public double? Flow { get; set; } // Total flow volume
public double? Flooding { get; set; } // Total flooding volume
public DateTime? RunStartTime { get; set; } // When run started
public DateTime? RunEndTime { get; set; } // When run completed
public DateTime? CompletedAt { get; set; } // Completion timestamp
public string? ErrorMessage { get; set; } // Error details if failed
public TimeSpan? Duration { get; set; } // Run duration
}
Affected Projects and Files
1. Core Data Layer (swmm5_core)
Files to Update:
GqcStorage1/TableEntities/SwmmInputEntity.cs→ DELETEGqcStorage1/TableEntities/SwmmRunEntity.cs→ DELETEGqcStorage1/TableEntities/SwmmScenarioEntity.cs→ CREATE NEWGqcStorage1/ConstantsSwmm.cs→ Update table namesGqcStorage1/Mappers/RequestToEntityMapper.cs→ Complete rewriteGqcStorage1/Mappers/EntityToDtoMapper.cs→ Update mappings
Changes Required:
- Replace all
SwmmInputEntityandSwmmRunEntityreferences - Update table name constants:
INPUTS_TABLE→SCENARIOS_TABLE - Remove
RUNS_TABLEconstant - Rewrite all mapping methods
2. Worker Functions
Projects to Update:
swmm-worker-function/SwmmWorkerFunction8/→ Update table referencesswc-worker-function/SwcWorkerFunction8/→ Update table references
Changes Required:
- Update table client references
- Modify worker logic to update single table
- Update result storage logic
3. API Layer (swmm-api-aspnet)
Controllers to Update:
Controllers/ScenarioManagementController.cs→ Major refactorControllers/RunManagementController.cs→ DELETE (functionality merged)Controllers/ScenarioController.cs→ Update table referencesControllers/NodeController.cs→ Update table referencesControllers/LinkController.cs→ Update table referencesControllers/SubcatchmentController.cs→ Update table referencesControllers/SystemController.cs→ Update table references
Changes Required:
- Remove dual table client references
- Consolidate API endpoints
- Update all database queries
- Merge run management functionality into scenario management
4. Frontend (swmm-frontend-react)
Files to Update:
src/pages/ScenarioSelectPage.jsx→ Update API callssrc/pages/ScenarioRunSelectPage.jsx→ DELETE (functionality merged)src/contexts/RunContext.jsx→ DELETE (functionality merged)src/contexts/ScenarioContext.jsx→ CREATE NEW (unified context)src/components/runs/RunsTable.jsx→ DELETEsrc/components/scenarios/ScenariosTable.jsx→ Update to show run statussrc/constants.jsx→ Update API endpointssrc/routes.jsx→ Remove run-specific routes
Changes Required:
- Remove separate run management UI
- Integrate run status into scenario views
- Update API endpoint calls
- Simplify data flow
Migration Plan
Phase 1: Preparation
Create new SwmmScenarioEntity
- Design and implement new entity class
- Add all required properties
- Create migration utilities
Update Constants and Configuration
- Update
ConstantsSwmm.cswith new table names - Update connection strings and table references
- Create backward compatibility constants
- Update
Create Data Migration Script
- Script to merge existing Inputs and Runs data
- Handle data validation and cleanup
- Create rollback procedures
Phase 2: Core Data Layer
Update Mappers
- Rewrite
RequestToEntityMapper.cs - Update
EntityToDtoMapper.cs - Create new unified DTOs
- Rewrite
Update Storage Utilities
- Modify
SwmmStorageUtility.cs - Update all table client references
- Test data access patterns
- Modify
Phase 3: API Layer
Consolidate Controllers
- Merge
RunManagementControllerintoScenarioManagementController - Update all API endpoints
- Remove duplicate functionality
- Merge
Update Legacy Controllers
- Update
ScenarioController.cs - Update
NodeController.cs,LinkController.cs, etc. - Test all API endpoints
- Update
Phase 4: Frontend Updates
Unify User Interface
- Merge scenario and run management pages
- Create unified context for scenario management
- Update all components
Update API Integration
- Update all API calls
- Remove run-specific endpoints
- Test user workflows
Phase 5: Worker Updates
Update Worker Functions
- Modify worker logic for single table
- Update result storage
- Test worker processing
Data Migration Execution
- Run migration script in production
- Validate data integrity
- Monitor system performance
Phase 6: Cleanup
Remove Legacy Code
- Delete old entity classes
- Remove unused API endpoints
- Clean up frontend components
Documentation and Testing
- Update API documentation
- Complete integration testing
- Performance optimization
Benefits of This Approach
Simplified Architecture
- Single source of truth for scenario data
- Eliminated data synchronization issues
- Reduced complexity in data access
Improved Performance
- Fewer database queries
- Reduced data duplication
- Simplified caching strategies
Better User Experience
- Unified scenario management interface
- Clearer data relationships
- Simplified workflows
Easier Maintenance
- Single table to maintain
- Simplified API endpoints
- Reduced code complexity
Conclusion
This migration will significantly simplify the data architecture while maintaining all existing functionality. The estimated 9-10 week timeline allows for thorough testing and gradual deployment, minimizing risks to the production system.