-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Migrate Aurora ascents/bids to unified boardsesh_ticks table #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Implements a comprehensive migration strategy to sync Aurora climb data to the new unified boardsesh_ticks table while maintaining backward compatibility. Changes: - Add SQL migration (0026) to backfill existing Aurora data - Implement dual-write strategy in user-sync.ts for ascents/bids - Create reusable migrate-user-history.ts for per-user migrations - Add user-triggered migration when linking Aurora credentials - Add background cron job to migrate users with missing data - Convert Aurora quality ratings (1-5) using formula: quality / 3.0 * 5 - Map Aurora user IDs to NextAuth user IDs via aurora_credentials - Ensure all writes are transactional for data integrity Migration paths: 1. Initial SQL migration for existing users 2. Automatic migration when users add Aurora credentials 3. Daily cron job (3 AM) to catch any missed users 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Claude ReviewIssues Found
|
Fixed TypeScript errors in migrate-user-history.ts by replacing boolean expressions in .where() clauses with proper Drizzle ORM SQL helper functions (eq, and, isNotNull). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Claude ReviewIssues Found
|
Fixed type mismatches in migration and sync code: - Removed ::text casts from timestamp columns in SQL migration - Changed TypeScript to use Date objects instead of .toISOString() - Ensures proper timestamp type compatibility with PostgreSQL schema This fixes the error: "column climbed_at is of type timestamp without time zone but expression is of type text" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Claude ReviewCritical Issues
Other Issues
|
Fixed TypeScript type errors by using .toISOString() for timestamp fields in Drizzle inserts. The boardsesh_ticks schema uses { mode: 'string' } for timestamps, requiring string values instead of Date objects.
Changes:
- Convert Date objects to ISO strings for all timestamp fields
- Applies to both migrate-user-history.ts and user-sync.ts
- SQL migration remains correct (uses PostgreSQL timestamp types)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Claude ReviewIssues Found
|
Implemented multiple improvements based on code review: 1. **Extract duplicate function**: Created shared convert-quality.ts utility - Removes duplicate convertQuality function from migrate-user-history.ts and user-sync.ts - Centralizes quality conversion logic (Aurora 1-3 scale → Boardsesh 1-5 scale) 2. **Fix N+1 query pattern**: Use batch inserts for migration - Collect all ascent/bid values before inserting - Single INSERT with multiple values instead of loop with individual INSERTs - Significantly improves performance for users with many climbs 3. **Fix weak auth bypass**: Strengthen cron endpoint security - Change from `VERCEL_ENV !== 'development'` to explicit check - Now requires secret in all non-development environments - Prevents bypass when VERCEL_ENV is undefined 4. **Fix race condition**: Add PostgreSQL advisory locks - Use pg_try_advisory_xact_lock to prevent concurrent migrations - Hash user ID + board type for unique lock ID - Ensures only one migration runs per user+board at a time 5. **Fix silent data loss**: Guard boardsesh_ticks writes - Skip dual-write to boardsesh_ticks when nextAuthUserId is null - Prevents failed inserts and maintains data consistency - Aurora tables still sync correctly for users without NextAuth accounts 6. **Remove unused import**: Clean up NeonDatabase import from migrate-user-history.ts 7. **Verify index exists**: Confirmed syncPendingIdx covers aurora_id queries Additional improvements: - Handle null timestamp values from Aurora tables gracefully - Add validation to skip records with missing required fields - Improve error messages and logging 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Claude ReviewIssues Found
|
…bility 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Claude ReviewIssues Found
|
Summary
Implements a comprehensive migration strategy to sync Aurora climb data (ascents and bids) to the new unified
boardsesh_tickstable while maintaining backward compatibility with existing Aurora tables.This PR enables:
Changes
New Files
packages/db/drizzle/0026_migrate_aurora_to_boardsesh_ticks.sql- SQL migration to backfill existing Aurora datapackages/web/app/lib/data-sync/aurora/migrate-user-history.ts- Reusable function for per-user historical data migrationpackages/web/app/api/internal/migrate-users-cron/route.ts- Background cron job to process unmigrated usersModified Files
packages/web/app/lib/data-sync/aurora/user-sync.ts- Added dual-write strategy for ascents/bids to both Aurora tables and boardsesh_tickspackages/web/app/api/internal/aurora-credentials/route.ts- Trigger user migration when credentials are addedvercel.json- Added daily migration cron job schedule (3 AM)Implementation Details
Data Transformations
(aurora_quality / 3.0) * 5to convert Aurora's 1-5 scaleattempt_id = 1→status: 'flash'attempt_id > 1→status: 'send'status: 'attempt'aurora_credentialstableMigration Strategy
Three migration paths ensure all users get their data:
Dual-Write Pattern
The
user-sync.tscode now writes to both:kilter_ascents,kilter_bids, etc.) - for backward compatibilityboardsesh_ticks- unified new tableAll writes happen in the same transaction to ensure data integrity.
Testing Strategy
Pre-Migration Validation
Post-Migration Validation
Rollback Plan
If issues occur:
Sync code changes can be reverted via git. Aurora tables remain unchanged, ensuring no data loss.
Edge Cases Handled
🤖 Generated with Claude Code