
Complete church management system with bulletin management, media processing, live streaming integration, and web interface. Includes authentication, email notifications, database migrations, and comprehensive test suite.
3.9 KiB
3.9 KiB
Timezone Migration Plan: V1/V2 Endpoints
Problem Statement
Currently, the database stores EST times that are masquerading as UTC. This causes confusion and requires hacky workarounds on the frontend to display proper times on devices.
Solution Overview
- Database: Store actual UTC times (fix the current EST-masquerading-as-UTC issue)
- V1 Endpoints: Convert UTC → EST for backward compatibility with existing clients
- V2 Endpoints: Return actual UTC times and let clients handle timezone conversion
Current State
- Database columns:
TIMESTAMP WITH TIME ZONE
(should store UTC but currently stores EST) - V1 endpoints:
/api/events
,/api/bulletins
, etc. - return EST times masquerading as UTC - V2 endpoints:
/api/v2/events
,/api/v2/bulletins
, etc. - already exist but may have same timezone issues
Target State
- Database: Store true UTC times
- V1 Endpoints: Return EST times (for backward compatibility)
- V2 Endpoints: Return true UTC times (clients handle conversion)
Implementation Steps
Step 1: Database Migration
- Identify all datetime fields that currently store EST-masquerading-as-UTC
- Convert existing EST times to actual UTC times
- Ensure all new inserts store proper UTC times
Key tables/fields to migrate:
events.start_time
,events.end_time
pending_events.start_time
,pending_events.end_time
,pending_events.submitted_at
bulletins.created_at
,bulletins.updated_at
- Other timestamp fields
Step 2: V1 Endpoint Modification
- Read UTC times from database
- Add conversion layer: UTC → EST
- Return EST times to maintain backward compatibility
- Existing frontend clients continue working without changes
Endpoints to modify:
/api/events*
/api/bulletins*
/api/schedule*
- All other v1 endpoints returning datetime fields
Step 3: V2 Endpoint Verification
- Ensure v2 endpoints read UTC from database
- Return true UTC times without conversion
- Remove any existing timezone conversion logic
- Let clients handle timezone conversion based on their needs
V2 endpoints:
/api/v2/events*
/api/v2/bulletins*
/api/v2/schedule*
- All other v2 endpoints
Step 4: Utility Functions
Create conversion utilities in src/utils/datetime.rs
:
convert_utc_to_est()
- For v1 endpointsensure_utc_storage()
- For database insertsmigrate_est_to_utc()
- For data migration
Migration Strategy
Phase 1: Database Migration (No Breaking Changes)
- Run migration to convert EST → UTC in database
- Update insert/update logic to store UTC
- Deploy without changing endpoint behavior
Phase 2: V1 Endpoint Compatibility Layer
- Add UTC → EST conversion to v1 endpoints
- Deploy and verify existing clients still work
- No frontend changes needed
Phase 3: V2 Endpoint Cleanup
- Ensure v2 endpoints return proper UTC
- Deploy and test with v2-compatible clients
- Update documentation for v2 API
Phase 4: Client Migration
- Frontend applications gradually migrate to v2 endpoints
- V2 clients handle timezone conversion locally
- Better user experience with proper timezone handling
Phase 5: V1 Deprecation (Future)
- Announce v1 deprecation timeline
- Eventually remove v1 endpoints after all clients migrate
Benefits
- Clean separation: Database stores UTC, display logic in clients
- Backward compatibility: V1 clients continue working
- Future-proof: V2 clients get proper UTC handling
- No more hacks: Eliminates workarounds for timezone display
Files to Modify
src/utils/datetime.rs
- Add conversion utilitiessrc/handlers/*.rs
- V1 endpoints add EST conversionsrc/handlers/v2/*.rs
- Verify UTC handlingmigrations/
- Database migration scriptsrc/db/*.rs
- Ensure UTC storage on inserts
Testing Strategy
- Unit tests for conversion utilities
- Integration tests comparing v1 vs v2 responses
- Verify v1 returns EST times
- Verify v2 returns UTC times
- Test database migration with sample data