chore: Database migration SQL - auth0_sub to UUID (#206) #211

Closed
opened 2026-02-16 15:01:32 +00:00 by egullickson · 0 comments
Owner

Relates to #206

Milestone 1: Database migration SQL

Multi-phase SQL migration to convert all user_id columns from VARCHAR(255) storing auth0_sub to UUID referencing user_profiles.id.

Phases

  1. Add user_profile_id UUID column to all 18 affected tables
  2. Backfill UUID values from user_profiles join
  3. admin_users: add id UUID PK, add user_profile_id UUID, backfill, create user_profiles for admins without one
  4. Set NOT NULL constraints, add FK constraints with ON DELETE CASCADE, add indexes
  5. Drop old VARCHAR columns and FK constraints, rename user_profile_id to user_id

Files

  • backend/src/features/user-profile/migrations/005_migrate_user_id_to_uuid.sql (new)

Acceptance Criteria

  • Migration executes without error
  • All tables have user_id UUID referencing user_profiles.id
  • user_profiles.auth0_sub remains as VARCHAR UNIQUE column
  • admin_users has id UUID PK + user_profile_id UUID FK
  • No data loss (row counts match before/after)
  • All FK constraints pass validation
Relates to #206 ## Milestone 1: Database migration SQL Multi-phase SQL migration to convert all user_id columns from VARCHAR(255) storing auth0_sub to UUID referencing user_profiles.id. ### Phases 1. Add `user_profile_id UUID` column to all 18 affected tables 2. Backfill UUID values from `user_profiles` join 3. admin_users: add `id UUID PK`, add `user_profile_id UUID`, backfill, create user_profiles for admins without one 4. Set NOT NULL constraints, add FK constraints with ON DELETE CASCADE, add indexes 5. Drop old VARCHAR columns and FK constraints, rename `user_profile_id` to `user_id` ### Files - `backend/src/features/user-profile/migrations/005_migrate_user_id_to_uuid.sql` (new) ### Acceptance Criteria - [ ] Migration executes without error - [ ] All tables have user_id UUID referencing user_profiles.id - [ ] user_profiles.auth0_sub remains as VARCHAR UNIQUE column - [ ] admin_users has id UUID PK + user_profile_id UUID FK - [ ] No data loss (row counts match before/after) - [ ] All FK constraints pass validation
egullickson added the
status
backlog
type
chore
labels 2026-02-16 15:02:02 +00:00
egullickson added this to the Sprint 2026-02-02 milestone 2026-02-16 15:02:07 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: egullickson/motovaultpro#211