Back to DevLog

Six Beta Program Bugs Down: When Database Constraints Fight Your Features

3 min read

Had one of those satisfying debugging sessions today where you just methodically work through a bug list and crush them one by one. Fixed 6 bugs in AdminStack's Beta Program feature, ranging from database constraint issues to some classic React state timing problems.

The Big Two: Database Drama

Started with two gnarly 500 errors that were blocking the whole beta flow:

Bug #1: PATCH /api/projects/[id] throwing 500s Turns out when I originally set up the projects table, the CHECK constraint on status didn't include 'beta' as a valid option. So every time someone tried to mark a project as beta status... boom, constraint violation. Had to create migration v3 to drop and recreate the constraint with 'beta' included. Note to self: always think ahead when setting up database constraints.

Bug #2: GET /api/admin/beta/requests also 500ing This one was trickier. The PostgREST foreign key join hint was pointing to auth.users instead of my accounts table. After banging my head against this for a bit, I just switched to a two-step query pattern - fetch the requests first, then grab the accounts by ID and merge them with a Map. Sometimes the simple approach wins.

The Polish Pass

Once the core functionality was working, tackled some UX improvements:

Consistency cleanup: Renamed all instances of "Beta Product" to "Beta Project" across modals, buttons, toasts, and table headers. These little inconsistencies always bug me.

Visual polish: Added a nice teal badge next to beta projects in the admin interface. Had to make sure status was included in the Supabase projects join.

State management fix: Classic React gotcha - I was clearing the userSearchResults array when a user clicked a result, but then trying to .find() the selected user in that now-empty array later. Added a separate selectedUser state variable to fix this timing issue.

Better user experience: Removed the status='open' filter from the user-facing beta page. Now users see all beta projects with appropriate "Open" (green) or "Coming Soon" (neutral) badges. Much better than showing "No beta products available" when everything was in coming soon status.

Key Takeaways

  • CHECK constraints in PostgreSQL need to be dropped and recreated to add new values - ALTER TYPE won't work here
  • PostgREST FK join hints are finicky - sometimes a simple two-step query is more reliable
  • React state timing issues: if you're going to clear an array on selection, store the selected item separately

All fixes are pushed to main. Just need to run the v3 migration in production and the beta program should be solid. Sometimes the best coding sessions are the ones where you just methodically work through a bug list and ship fixes.

Share this post