DocHub
Systemic bug where auth UUIDs were confused with legacy numeric IDs across the codebase

UUID vs Numeric ID Mismatch

The Problem

After migrating from Firebase to Supabase, the codebase has two ID systems:

  • auth_uid: UUID string from Supabase Auth (e.g. xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
  • legacy_numeric_id: Integer from the old Firebase system (e.g. 1772074673669)

Many API routes and repositories were passing legacy_numeric_id (number) to columns that store auth_uid (UUID string). This caused silent failures — queries returned no results, FK violations, or wrong data.

Affected Columns

Table Column Stores Was queried with
assignments user_id auth UUID legacy_numeric_id
restaurants owner_user_id auth UUID legacy_numeric_id
addresses user_id auth UUID (string) legacy_numeric_id (number)
orders user_id auth UUID Correct (was already UUID)

Files Fixed

File What was wrong
src/data/models.ts Address.user_id typed as number instead of string
src/repositories/addressesRepo.ts listAddressesByUser param was number, changed to string
src/utils/addressUtils.ts Passed numeric ID instead of UUID to address operations
src/repositories/ordersRepo.ts createOrderNumber(null) = 0 passed isFinite but violated FK
src/repositories/restaurantsRepo.ts findRestaurantByNumericId queried non-existent legacy_numeric_id column
src/app/api/admin/restaurants/route.ts owner_user_id queried with numeric ID instead of UUID
src/app/api/admin/orders/route.ts Assignment lookup used numeric ID for UUID column
src/app/api/admin/orders/[orderId]/route.ts Same UUID fix for assignment lookup
src/app/api/order-detail/[orderId]/route.ts Same UUID fix
src/app/api/push/notify/route.ts Manager audience queried legacy_numeric_id but assignments.user_id stores UUIDs
src/app/orders/page.tsx Customer orders page called admin-only API endpoints

Still Affected (Not Yet Fixed)

Likely exists in routes we haven’t touched:

  • Driver routes
  • Discount code routes
  • Report routes