fix: migration to convert user_id text → uuid with FK to auth.users

🟢 open · #113 · willchen96/mike ← bmersereau/mike · opened 13d ago by bmersereau · +1,532-8 across 8 files · ↗ on GitHub

From the PR description

Summary

  • Adds backend/migrations/20260513_userid_text_to_uuid.sql - a transactional migration that converts user_id text columns to uuid and adds REFERENCES auth.users(id) FK constraints on all 9 affected tables
  • workflows.user_id uses ON DELETE SET NULL (not CASCADE) to preserve shared workflows when the owner account is deleted
  • Provides a pre-flight check query (in comments) to identify any non-UUID values before applying
  • Adds rollback script 20260513_userid_text_to_uuid.rollback.sql

Closes #104 Closes #114

Affected tables

projects, project_subfolders, documents, chats, tabular_reviews, tabular_review_chats, workflows, hidden_workflows, workflow_shares

Changes

  • backend/migrations/20260513_userid_text_to_uuid.sql - the migration (wrapped in BEGIN/COMMIT)
  • backend/migrations/20260513_userid_text_to_uuid.rollback.sql - rollback script
  • backend/src/lib/__tests__/useridMigration.test.ts - 5 static analysis tests
  • backend/package.json - "test": "vitest run" script added

⚠️ Apply instructions

  1. Run the pre-flight check query from the migration comments - confirm zero rows returned
  2. Apply via Supabase dashboard SQL editor or psql
  3. Verify with \d public.projects that user_id shows type uuid and a FK constraint

Test plan

  • Unit tests added and passing (5/5)
  • Backend build passes

Our analysis

Convert user_id columns from text to uuid with FK constraints — read the full analysis →

Think the analysis missed something the PR description covers?

Capture this PR into my fork

Download a Markdown prompt that tells Claude how to port every commit in this PR into your working tree. Run it via claude -p < capture-pull-113.md from inside the repo you want the changes in.

⬇ Download capture-pull-113.md