fix: migration to convert user_id text → uuid with FK to auth.users#113
Open
bmersereau wants to merge 4 commits into
Open
fix: migration to convert user_id text → uuid with FK to auth.users#113bmersereau wants to merge 4 commits into
bmersereau wants to merge 4 commits into
Conversation
bmersereau
commented
May 13, 2026
Author
bmersereau
left a comment
There was a problem hiding this comment.
PR Review
Summary
Adds a transactional SQL migration converting user_id text to uuid references auth.users(id) across 9 tables, plus a rollback script. Five static-analysis tests verify the migration is transactional, covers all tables, uses a USING cast, adds FK constraints with ON DELETE CASCADE/SET NULL, and that the rollback script exists.
Findings
- [severity:praise] Migration is wrapped in
BEGIN/COMMIT— safe to abort on error - [severity:praise]
workflows.user_idusesON DELETE SET NULL(not CASCADE) — correct decision to preserve shared workflows after owner deletion - [severity:praise] Pre-flight check query included in comments — operator has guidance before applying
- [severity:praise] Rollback script present and comprehensive
- [severity:minor] The rollback script drops FK constraints and reverts to
text— but it does not restore any previously-existing FK constraint if one existed. Givenuser_idwas plaintextbefore, this is correct; just worth noting in operator runbook - [severity:nit] Migration has no explicit
SET search_path = publicguard. On multi-schema setups,public.table qualifiers (which are present) are sufficient — no change needed
Specific checks
-
"test": "vitest run"in package.json ✓ -
vitest.config.tsinclude filter present ✓ - Rollback script exists ✓
-
BEGIN/COMMITpresent ✓ - Tests pass: 7/7 ✓
Verdict
Approve — ship it after pre-flight check confirms no non-UUID rows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
backend/migrations/20260513_userid_text_to_uuid.sql— a transactional migration that convertsuser_id textcolumns touuidand addsREFERENCES auth.users(id)FK constraints on all 9 affected tablesworkflows.user_idusesON DELETE SET NULL(not CASCADE) to preserve shared workflows when the owner account is deleted20260513_userid_text_to_uuid.rollback.sqlCloses #104
Closes #114
Affected tables
projects,project_subfolders,documents,chats,tabular_reviews,tabular_review_chats,workflows,hidden_workflows,workflow_sharesChanges
backend/migrations/20260513_userid_text_to_uuid.sql— the migration (wrapped inBEGIN/COMMIT)backend/migrations/20260513_userid_text_to_uuid.rollback.sql— rollback scriptbackend/src/lib/__tests__/useridMigration.test.ts— 5 static analysis testsbackend/package.json—"test": "vitest run"script addedpsql\d public.projectsthatuser_idshows typeuuidand a FK constraintTest plan