Cleanup and Reseed Plan
Overview
Once all data models are reviewed and standardized, we can perform a complete database cleanup and reseed with the new standardized models. This is safe for staging environment.
Prerequisites Checklist
Before running cleanup and reseed, verify:
✅ Data Model Review
- Cases - Base model created, all inconsistencies fixed
- Users - Base model created, all inconsistencies fixed
- Donations - Base model created, all inconsistencies fixed
- Follows - Base model created, all inconsistencies fixed
- Case Updates - Base model created, all inconsistencies fixed
- Conversations - Base model created, all inconsistencies fixed
- Support Tickets - Base model created, all inconsistencies fixed
- Audit Logs - Skipped (backoffice infrastructure)
✅ Firestore Rules
- All collections have proper security rules
- Field names match between rules and models
-
donorId→userIdfixed in toto-app rules -
requesterId→userIdfixed in support tickets -
socialMediaPostsrules added to toto-bo
✅ Seeding Scripts
- All seeding scripts updated to match base models
- Field names consistent across all scripts
- All required fields populated
- Optional fields handled correctly
✅ Code Updates
- All interfaces updated to match base models
- API routes updated with correct field names
- Service files updated
- UI components updated (where applicable)
Collections to Keep
These collections will be preserved (not cleaned):
-
socialMediaPosts- Created by social media bot, should be preserved- Reason: Generated by AI agents, not seeded
- Action: Skip during cleanup
-
guardians- Twitter bot guardian management- Reason: Managed by Twitter bot, not seeded
- Action: Skip during cleanup
-
guardianTweets- Guardian tweets- Reason: Generated by Twitter bot, not seeded
- Action: Skip during cleanup
-
twitterBotConfig- Twitter bot configuration- Reason: Configuration data, not seeded
- Action: Skip during cleanup
Collections to Clean and Reseed
These collections will be completely cleaned and reseeded:
users- User accounts and profilescases- Pet rescue casesdonations- Donation recordsfollows- User subscriptionsupdates- Case updates (top-level)support_tickets- Support ticketsnotifications- User notificationsconversations- AI chat conversationsaudit_logs- System audit trail
Collections to Remove (Unused)
These collections appear to be unused and can be removed:
waitlist- External waitlist (now in users collection)chats- Replaced byconversationsanalytics- Check if used in Cloud Functionsanalytics_cache- Check if used in Cloud Functionsaccounts- Check if used for account managementsessions- Check if used for session managementverification_tokens- Check if used for email verificationcollaborators- Check if used for collaboration features
⚠️ Action Required: Before removing, verify these are not used in:
- Cloud Functions
- External services
- Legacy code paths
Cleanup Script Modifications
Update init-staging-complete/route.ts
Modify the cleanup section to:
- Skip collections to preserve:
const collectionsToPreserve = [
'socialMediaPosts',
'guardians',
'guardianTweets',
'twitterBotConfig'
];
- Collections to clean and reseed:
const collectionsToReseed = [
'users',
'cases',
'updates',
'donations',
'follows',
'notifications',
'support_tickets',
'conversations',
'audit_logs'
];
- Collections to remove (after verification):
const collectionsToRemove = [
'waitlist',
'chats',
'analytics',
'analytics_cache',
'accounts',
'sessions',
'verification_tokens',
'collaborators'
];
Execution Steps
Step 1: Final Review
- Review all base models one final time
- Verify all Firestore rules are correct
- Check all seeding scripts
- Verify no breaking changes in API routes
Step 2: Backup (Optional but Recommended)
- Export current database state (if needed for reference)
- Document any custom data that needs to be preserved
Step 3: Update Cleanup Script
- Add collections to preserve list
- Add collections to remove list (after verification)
- Test cleanup logic
Step 4: Run Cleanup and Reseed
- Execute
POST /api/init-staging-complete - Monitor logs for errors
- Verify all collections are seeded correctly
Step 5: Verification
- Check all collections have data
- Verify field names match base models
- Test UI displays data correctly
- Test API routes work correctly
- Verify Firestore rules work correctly
Post-Cleanup Checklist
After cleanup and reseed:
- All entities display correctly in toto-app UI
- All entities display correctly in toto-bo UI
- API routes return correct data structure
- Firestore rules allow/deny correctly
- No console errors in browser/terminal
- Social media bot can still create posts
- Twitter bot can still access guardians
Rollback Plan
If something goes wrong:
- Stop the process immediately
- Check logs for specific errors
- Fix the issue in seeding script or model
- Re-run cleanup (it's idempotent)
Notes
- Staging Only: This cleanup is for staging environment
- Production: For production, create a migration script instead of full cleanup
- Social Media Posts: These are generated by bots, not seeded, so they're preserved
- Audit Logs: Will be reseeded but will continue to be generated by system
Timeline
- Final Review: 1-2 hours
- Script Updates: 30 minutes
- Cleanup Execution: 5-10 minutes
- Verification: 30 minutes
Total Estimated Time: 2-3 hours