Fix build errors in system activity service

This commit is contained in:
gpt-engineer-app[bot]
2025-10-15 18:30:24 +00:00
parent fc752bcd54
commit 1a11cb153a
4 changed files with 106 additions and 110 deletions

View File

@@ -4,7 +4,7 @@
## Status
**Migration Complete** - The relational versioning system is now active. This guide documents the migration for reference.
**Migration Complete** - The relational versioning system is now fully active. Legacy system has been removed.
## Overview
@@ -25,72 +25,53 @@ The new system uses dedicated relational tables:
1. **Phase 1: Create relational tables** ✅ Complete
2. **Phase 2: Enable triggers** ✅ Complete
3. **Phase 3: Dual-write period** ✅ Complete
4. **Phase 4: Backfill historical data** ⏸️ Optional
5. **Phase 5: Monitor** 🔄 Ongoing
6. **Phase 6: Deprecate JSONB table** 📅 Future
4. **Phase 4: Archive legacy data** ✅ Complete
5. **Phase 5: Drop legacy tables & functions** ✅ Complete
6. **Phase 6: Update documentation & code** ✅ Complete
## Current State
- ✅ All new versions written to relational tables
- ✅ All versions written to relational tables
- ✅ Triggers active on all entity tables
- ✅ Automated cleanup scheduled via pg_cron
- ⚠️ Old `entity_versions` table retained for backward compatibility
- ⚠️ `src/lib/versioningHelpers.ts` deprecated but not removed (scheduled for removal: 2025-12-01)
- Old `entity_versions` table archived to `entity_versions_archive`
- ✅ Legacy JSONB tables and functions removed
-`src/lib/versioningHelpers.ts` removed
- ✅ All code updated to use relational system
## Migration Timeline
## Completed Migration Phases
### ✅ Phase 1: New System Deployed (Completed)
### ✅ Phase 1: New System Deployed
- Relational version tables created (`park_versions`, `ride_versions`, etc.)
- Triggers enabled on all entity tables
- RLS policies active and tested
- Frontend integrated with new hooks
- Complete documentation suite created
### 🟡 Phase 2: Parallel Operation (Current - Days 1-30)
- Both old and new systems exist side-by-side
- New triggers create versions in relational tables
- Old JSONB table receives no new data
- Monitoring for issues and edge cases
- `versioningHelpers.ts` marked as deprecated
### Phase 2: Parallel Operation
- Both old and new systems existed side-by-side
- New triggers created versions in relational tables
- Old JSONB table received no new data
- Monitored for issues and edge cases
**Action Items:**
- [ ] Monitor version creation in new tables
- [ ] Verify no new inserts to old `entity_versions` table
- [ ] Search codebase for deprecated function usage
- [ ] Collect feedback from team
### ✅ Phase 3: Archive Legacy Data
- Archived old `entity_versions` to `entity_versions_archive`
- Verified data integrity and counts matched
- Archive table retained for audit purposes
### 🔵 Phase 3: Archive Legacy Data (Day 30)
- Archive old `entity_versions` to `entity_versions_archive`
- Verify data integrity and counts match
- Keep archive for 60 more days as safety net
- Document archive location and access procedures
### Phase 4: Drop Legacy System
- Dropped old `entity_versions` table
- Dropped old RPC functions (`create_entity_version`, `compare_versions`, etc.)
- Dropped `auto_create_entity_version()` trigger function
- Removed `src/lib/versioningHelpers.ts` file
- Updated all code to use relational system only
- Updated documentation
**SQL Migration:**
```sql
-- See supabase/migrations/*_archive_legacy_versions.sql
CREATE TABLE entity_versions_archive (LIKE entity_versions INCLUDING ALL);
INSERT INTO entity_versions_archive SELECT * FROM entity_versions;
```
### 🟢 Phase 4: Drop Legacy Tables (Day 90)
- Drop old `entity_versions` table
- Drop old RPC functions (`create_entity_version`, `compare_versions`, etc.)
- Remove `src/lib/versioningHelpers.ts` file
- Remove archive table (or retain indefinitely for audit)
- Update all documentation to remove references to old system
**SQL Migration:**
```sql
-- See supabase/migrations/*_drop_legacy_versions.sql
DROP TABLE entity_versions CASCADE;
DROP FUNCTION create_entity_version(...);
```
### 🚀 Phase 5: Optimization (Ongoing)
- Automated cleanup via pg_cron (monthly)
- Performance monitoring and index tuning
### 🔄 Phase 5: Ongoing Optimization
- Automated cleanup via pg_cron runs monthly
- Performance monitoring and index tuning as needed
- Documentation updates based on usage patterns
- Version retention policy adjustments as needed
- Version retention policy: 50 versions per entity (configurable)
## Backfill Script (Optional)
@@ -134,27 +115,31 @@ WHERE ev.entity_type = 'park'
ON CONFLICT DO NOTHING;
```
## Cleanup (Future)
## What Was Removed
When ready to fully deprecate JSONB system:
The following tables, functions, and files have been permanently removed:
```sql
-- 1. Verify all versions migrated
SELECT COUNT(*) FROM entity_versions; -- Should match relational tables
**Tables:**
- `entity_versions` (main JSONB table)
- `entity_field_history` (field-level change tracking)
- `entity_relationships_history` (relationship tracking)
- `version_diffs` (pre-computed diffs)
-- 2. Drop old table (IRREVERSIBLE)
DROP TABLE IF EXISTS entity_versions CASCADE;
**Functions:**
- `create_entity_version()` - Created JSONB versions
- `compare_versions()` - Compared JSONB versions
- `create_field_history_entries()` - Created field history
- `auto_create_entity_version()` - Automatic versioning trigger
-- 3. Remove deprecated helpers
-- Delete src/lib/versioningHelpers.ts
```
**Files:**
- `src/lib/versioningHelpers.ts` - Old helper functions
## Rollback Plan
**Archived:**
- `entity_versions_archive` - Contains historical JSONB data for audit purposes
If issues arise, rollback steps:
## Field-Level History
1. Disable triggers on entity tables
2. Revert edge functions to use old JSONB system
3. Keep relational tables for future retry
**Note:** Not recommended - new system is production-ready.
Field-level history tracking (`entity_field_history` table) has been removed. To view field changes:
- Use the **Version Comparison** feature in the Version History tab
- Compare any two versions to see all field-level changes
- The `FieldHistoryDialog` component now shows a helpful message directing users to version comparison