Skip to content

Conversation

@marcodejongh
Copy link
Owner

Summary

  • Remove foreign key constraint on board_climb_stats that references board_climbs
  • Stats can now be synced even when corresponding climbs haven't been synced yet
  • Fixes sync failures caused by Aurora API returning stats before their parent climbs

Test plan

  • Run npm run db:migrate to apply the migration
  • Trigger a shared sync and verify climb_stats inserts succeed
  • Verify existing queries still work correctly

🤖 Generated with Claude Code

@vercel
Copy link

vercel bot commented Jan 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
boardsesh Building Building Preview, Comment Jan 4, 2026 10:12pm

marcodejongh and others added 3 commits January 5, 2026 09:06
- Add UNIFIED_TABLES constant and helper functions to table-select.ts
- Update shared-sync.ts to use unified tables for:
  - board_attempts, board_difficulty_grades (seeded with MoonBoard data)
  - board_climbs, board_climb_stats, board_climb_stats_history
  - board_climb_holds, board_beta_links
  - board_shared_syncs
- Update user-sync.ts to use unified tables for:
  - board_users, board_walls, board_circuits, board_tags
  - board_user_syncs
  - draft_climbs (uses board_climbs)
- Keep legacy getTable for ascents/bids (phased out, already in boardsesh_ticks)
- All inserts now include boardType, conflict targets include boardType
- All queries filter by boardType

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
## Changes

### Ascent/Bid Data Migration
- All ascent/bid reads now use boardsesh_ticks table
- All ascent/bid writes now use boardsesh_ticks table
- Switched from Aurora user_id (integer) to NextAuth userId (string)
- Removed dual-write pattern from user-sync.ts

### Files Updated
- saveAscent.ts: Write to boardsesh_ticks with NextAuth userId
- saveAscent/route.ts: Require NextAuth session, pass user.id
- get-logbook.ts: Read from boardsesh_ticks
- create-climb-filters.ts: Personal progress uses boardsesh_ticks
- holds-heatmap.ts: User data queries use boardsesh_ticks
- heatmap/route.ts: Use getServerSession for NextAuth
- user-sync.ts: Remove legacy table writes
- aurora-credentials/route.ts: Remove migration call

### Files Deleted
- migrate-user-history.ts: No longer needed
- migrate-users-cron/route.ts: Cron job no longer needed

### Migration
- 0030_drop_legacy_ascents_bids.sql: Drop kilter/tension ascents/bids tables

### Additional Fixes
- saveClimb.ts: Use unified boardClimbs table
- beta/route.ts: Use unified boardBetaLinks table
- view/page.tsx: Use unified boardBetaLinks table
- slug-utils.ts: Use unified tables

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The foreign key constraint on board_climb_stats caused sync failures when
stats arrived from the Aurora API before their corresponding climbs.
This is expected behavior during incremental sync where stats for climbs
may be returned before the climbs themselves are synced.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@marcodejongh marcodejongh merged commit 72a7bb3 into main Jan 4, 2026
3 of 6 checks passed
@claude
Copy link

claude bot commented Jan 4, 2026

Claude Review

Ready to merge - Minor issues noted below, but nothing blocking.

Issues

  1. Journal index mismatch (packages/db/drizzle/meta/_journal.json): The new entry has "idx": 27 but follows entry with "idx": 26. While the indexes have been non-sequential in this journal before (entries jump from idx 18 to idx 19 with tag "0025_fix_missing_tables"), this appears intentional. Just noting for awareness.

  2. No tests: This is a database migration without integration tests to verify the sync behavior works correctly after removing the FK. Consider adding a test that inserts stats before climbs exist to validate the fix, though this is not blocking for a simple constraint removal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants