- Created migration-actions.ts with server actions for claiming lists - Added ClaimListsModal component for UI during registration - Integrated claim modal into RegisterForm - Created anonymous-lists.ts utilities for tracking lists in localStorage - Added migrate-lists.ts script for deployment migration - Created comprehensive MIGRATION_GUIDE.md documentation - Added migration tests with 100% pass rate - Updated package.json with db:migrate script - Added tsx as dev dependency for running migration scripts Requirements: 10.2, 10.3, 10.4, 10.5 - Users can claim existing lists on first registration - All list data is preserved during migration - All lists have an owner after migration - Migrated lists appear in user's account
4.6 KiB
Data Migration Guide
This guide explains how to migrate existing anonymous lists to the new user authentication system.
Overview
The Ultimate Lists App now supports user authentication and private lists. This migration ensures that:
- All existing lists are preserved (Requirement 10.3)
- All lists have an associated owner (Requirement 10.4)
- Users can claim their existing lists when they register (Requirement 10.2)
- All list data including items, metadata, and timestamps remain unchanged (Requirement 10.3)
Migration Strategy
For New Deployments
If you're deploying the authentication system for the first time:
-
Run the migration script before enabling authentication:
npx tsx scripts/migrate-lists.tsThis script will:
- Create a system user if it doesn't exist
- Assign any orphaned lists to the system user
- Verify all lists have owners
-
Deploy the application with authentication enabled
-
Users can claim lists when they register:
- Lists created before registration are tracked in localStorage
- During registration, users are prompted to claim their lists
- Lists are transferred from system user to the new user account
For Existing Users
When a user registers for the first time:
- The app checks localStorage for any tracked list IDs
- If lists are found, a modal appears asking the user to claim them
- User can select which lists to claim
- Selected lists are transferred to the user's account
- All list data (items, metadata, timestamps) is preserved
Technical Details
Database Schema Changes
The migration adds:
Usertable with authentication fieldsownerIdfield onListtable (required)Collaboratortable for list sharingInvitationtable for sharing invitations
Migration Script
Location: scripts/migrate-lists.ts
The script:
- Creates a system user (
system@ultimatelists.app) - Assigns orphaned lists to the system user
- Verifies data integrity
- Provides a migration summary
Client-Side Tracking
Location: lib/anonymous-lists.ts
Utilities for tracking anonymous lists:
trackAnonymousList(listId)- Add a list to trackinggetAnonymousListIds()- Get all tracked listsclearAnonymousLists()- Clear tracking after migrationhasAnonymousLists()- Check if there are lists to migrate
Migration Actions
Location: lib/migration-actions.ts
Server actions for migration:
getClaimableLists(listIds)- Fetch lists that can be claimedclaimLists(listIds)- Transfer lists to user accounthasExistingLists()- Check if user has listsmigrateOrphanedListsToSystemUser()- One-time migration script
UI Components
Location: components/ClaimListsModal.tsx
Modal component that:
- Displays claimable lists with details
- Allows users to select which lists to claim
- Handles the claim process
- Clears localStorage after successful claim
Testing the Migration
Test Scenario 1: New User with Anonymous Lists
- Create lists without being logged in
- Register for an account
- Verify the claim modal appears
- Select lists to claim
- Verify lists appear in the user's account
- Verify all items and metadata are preserved
Test Scenario 2: New User without Anonymous Lists
- Register for an account without creating lists
- Verify no claim modal appears
- Verify user is redirected to the app
Test Scenario 3: Existing User
- Log in with an existing account
- Verify existing lists are displayed
- Verify all data is intact
Rollback Plan
If issues occur during migration:
-
Database Rollback:
npx prisma migrate reset -
Restore from Backup:
- Restore database from pre-migration backup
- Redeploy previous version of the application
-
Manual Data Recovery:
- Export lists from system user
- Manually assign to correct users
- Verify data integrity
Monitoring
After migration, monitor:
- Number of orphaned lists (should be 0)
- Number of lists owned by system user
- User registration and claim rates
- Any errors in migration logs
Support
If users experience issues:
- Check browser console for errors
- Verify localStorage contains list IDs
- Check server logs for migration errors
- Manually transfer lists if needed using admin tools
Requirements Validation
This migration satisfies:
- ✓ Requirement 10.1: Authentication system provides migration path
- ✓ Requirement 10.2: Users can claim existing lists on registration
- ✓ Requirement 10.3: All list data is preserved during migration
- ✓ Requirement 10.4: All lists have an associated owner
- ✓ Requirement 10.5: Migrated lists appear in user's account