Version: 1.0.0Documentation Index
Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
Use this file to discover all available pages before exploring further.
Date: 2026-01-16
Status: Planning
Reference: docs/migration/SUPABASE_PERFORMANCE_RECOMMENDATIONS.md
Executive Summary
This document outlines the data archival strategy for the Encore Health OS platform. The goal is to maintain database performance by archiving old data while ensuring compliance with healthcare data retention requirements.1. Archival Candidates
1.1 Audit & Activity Logs
| Table | Retention Period | Archive After | Priority |
|---|---|---|---|
pf_audit_logs | 7 years (HIPAA) | 1 year | High |
pf_activity_logs | 3 years | 6 months | High |
pf_login_history | 2 years | 6 months | Medium |
pf_api_logs | 1 year | 3 months | Medium |
1.2 Workflow & Execution Logs
| Table | Retention Period | Archive After | Priority |
|---|---|---|---|
fw_workflow_executions | 3 years | 1 year | High |
fw_execution_logs | 2 years | 6 months | High |
fw_approval_history | 5 years | 1 year | Medium |
fw_debug_sessions | 90 days | 30 days | Low |
fw_sandbox_executions | 90 days | 30 days | Low |
1.3 Notifications & Communications
| Table | Retention Period | Archive After | Priority |
|---|---|---|---|
pf_notifications | 2 years | 6 months | High |
pf_notification_deliveries | 1 year | 3 months | Medium |
pf_email_logs | 2 years | 6 months | Medium |
1.4 Temporary & Session Data
| Table | Retention Period | Archive After | Priority |
|---|---|---|---|
pf_sessions | 30 days | N/A (delete) | High |
pf_temp_files | 7 days | N/A (delete) | High |
fw_form_drafts | 90 days | 30 days | Medium |
2. Healthcare Compliance Requirements
2.1 HIPAA Requirements
- Patient Records: Minimum 6 years from date of creation or last effective date
- Audit Logs: Minimum 6 years (some states require longer)
- Business Records: Generally 6-7 years
2.2 State-Specific Requirements
| State | Requirement | Notes |
|---|---|---|
| California | 7 years | From date of service |
| New York | 6 years | From date of discharge |
| Florida | 7 years | For adults, 7 years for minors after reaching majority |
| Texas | 10 years | For adults |
2.3 Compliance Rules
- Never archive PHI-containing records prematurely
- Maintain audit trail for archived data
- Ensure archived data is retrievable
- Document archival process for compliance audits
3. Archival Methods
3.1 Method 1: Archive Tables (Recommended)
Create parallel archive tables in a separate schema.- Data stays in same database
- Easy to query archived data when needed
- Simple implementation
- Storage costs remain in database
- May need to manage archive table growth
3.2 Method 2: External Storage (Future)
Export to external storage for long-term retention. Options:- AWS S3 / Glacier (cold storage)
- Azure Blob Storage
- Google Cloud Storage
- Archive data exceeds practical database size
- Cost optimization is priority
- Data is rarely accessed
3.3 Method 3: Hard Delete (Non-PHI Only)
For temporary data that doesn’t require retention.- Session data
- Temporary files
- Debug/sandbox data
- Non-business-critical logs
4. Implementation Plan
Phase 1: Infrastructure Setup
- Create
archiveschema - Create archive tables for high-priority candidates
- Set up archive RLS policies (platform_admin only)
- Create archival functions
Phase 2: Archival Functions
Phase 3: Scheduled Archival
Options for scheduling:- Supabase Edge Functions (cron trigger)
- External scheduler (n8n, Vercel cron)
- pg_cron extension (if available)
- Weekly archival runs (low-traffic period)
- Monthly summary reports
- Quarterly compliance audits
Phase 4: Monitoring
- Track archive table sizes
- Monitor archival job success/failure
- Alert on failed archival runs
- Report on archived record counts
5. Table Size Assessment Query
Run this query to identify archival candidates by size:6. Archival Verification Query
After archival, verify data integrity:7. Risk Mitigation
7.1 Data Loss Prevention
- Always archive before delete
- Test archival process in staging first
- Maintain backup before first production run
- Verify record counts after each run
7.2 Compliance
- Document archival dates for audit
- Maintain chain of custody for PHI
- Test data retrieval from archive
- Regular compliance review
7.3 Performance
- Run archival during low-traffic periods
- Batch large archival operations
- Monitor lock contention
- Use transactions with appropriate isolation
8. Success Metrics
| Metric | Target | Measurement |
|---|---|---|
| Archive completion rate | 100% | Jobs completed / Jobs scheduled |
| Data integrity | 100% | Archived count = Deleted count |
| Query performance | <1s | Archive query execution time |
| Storage reduction | >20% | Main table size reduction |
9. Next Steps
- Run table size assessment query
- Identify top 10 archival candidates by size
- Create archive schema and initial tables
- Implement archival functions
- Test in staging environment
- Schedule production archival
- Set up monitoring and alerting
10. References
- HIPAA Retention Requirements: HHS.gov
- Supabase Storage Best Practices: Supabase Docs
- PostgreSQL Partitioning: PostgreSQL Docs
Document Owner: Platform Team
Review Schedule: Quarterly
Last Updated: 2026-01-16