fix(local-db): migrate non-UUID workspace IDs to UUID v4#1667
fix(local-db): migrate non-UUID workspace IDs to UUID v4#1667
Conversation
The cloud database expects workspace IDs to be UUIDs but some existing workspaces may have non-UUID IDs. This migration detects and replaces them with valid v4 UUIDs, updating settings references accordingly.
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughAdds a database migration that converts non-UUID workspace IDs to UUID v4 using a temporary mapping, updates dependent references, and removes the mapping; also adds a schema snapshot and a migration journal entry. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/local-db/drizzle/0031_migrate_workspace_ids_to_uuid.sql (1)
6-9: Minor: considerINSERT OR IGNOREfor extra resilience against partial re-runs.If the migration runner ever re-executes after a partial failure outside a transaction, the
INSERTat Line 11 would fail on duplicateold_idprimary keys whileCREATE TABLE IF NOT EXISTSwould silently succeed. UsingINSERT OR IGNORE(orINSERT OR REPLACE) on Line 11 would make the migration fully idempotent.Not a blocker given Drizzle typically wraps SQLite migrations in a transaction.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/local-db/drizzle/0031_migrate_workspace_ids_to_uuid.sql` around lines 6 - 9, The INSERT in the migration that populates the _workspace_id_map table should be made idempotent: change the insertion statement that writes into the _workspace_id_map (using old_id as PK) to use "INSERT OR IGNORE" (or "INSERT OR REPLACE" if you prefer overwrite semantics) so re-running the migration after a partial failure won't raise a duplicate-key error; update the INSERT that targets _workspace_id_map accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/local-db/drizzle/0031_migrate_workspace_ids_to_uuid.sql`:
- Around line 6-9: The INSERT in the migration that populates the
_workspace_id_map table should be made idempotent: change the insertion
statement that writes into the _workspace_id_map (using old_id as PK) to use
"INSERT OR IGNORE" (or "INSERT OR REPLACE" if you prefer overwrite semantics) so
re-running the migration after a partial failure won't raise a duplicate-key
error; update the INSERT that targets _workspace_id_map accordingly.
Remove statement breakpoints so all migration steps execute in one transaction, preventing partial updates if a step fails.
🚀 Preview Deployment🔗 Preview Links
Preview updates automatically with new commits |
Summary
workspace.ensureendpoint) validatesz.string().uuid()and rejects themChanges
packages/local-db/drizzle/0031_migrate_workspace_ids_to_uuid.sql— Data migration that:old_id -> new_uuidfor workspaces with non-UUID IDssettings.last_active_workspace_idif it references a migrated workspaceworkspaces.idprimary keys to the new UUIDspackages/local-db/drizzle/meta/— Updated journal and snapshot for migration 0031Test Plan
settings.last_active_workspace_idis updated when it references a migrated workspaceSummary by CodeRabbit