Skip to content

Comments

fix(local-db): migrate non-UUID workspace IDs to UUID v4#1667

Open
Kitenite wants to merge 2 commits intomainfrom
kitenite/uuid
Open

fix(local-db): migrate non-UUID workspace IDs to UUID v4#1667
Kitenite wants to merge 2 commits intomainfrom
kitenite/uuid

Conversation

@Kitenite
Copy link
Collaborator

@Kitenite Kitenite commented Feb 21, 2026

Summary

  • Some existing workspaces in the local SQLite database may have non-UUID IDs, but the cloud database (workspace.ensure endpoint) validates z.string().uuid() and rejects them
  • Adds a local-db migration that detects non-UUID workspace IDs and replaces them with valid v4 UUIDs

Changes

  • packages/local-db/drizzle/0031_migrate_workspace_ids_to_uuid.sql — Data migration that:
    1. Creates a temp mapping table of old_id -> new_uuid for workspaces with non-UUID IDs
    2. Updates settings.last_active_workspace_id if it references a migrated workspace
    3. Updates workspaces.id primary keys to the new UUIDs
    4. Drops the temp mapping table
  • packages/local-db/drizzle/meta/ — Updated journal and snapshot for migration 0031

Test Plan

  • Verify migration is a no-op when all workspace IDs are already UUIDs (mapping table stays empty)
  • Verify non-UUID workspace IDs are replaced with valid v4 UUIDs after migration
  • Verify settings.last_active_workspace_id is updated when it references a migrated workspace
  • Verify the app starts and loads workspaces correctly after migration

Summary by CodeRabbit

  • Chores
    • Standardized workspace identifiers to UUID v4 across the local database to improve data consistency and reduce migration errors.
    • Added a schema snapshot and migration journal entry to ensure safer, atomic upgrades and better rollback reliability.

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.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 21, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Database Migration
packages/local-db/drizzle/0031_migrate_workspace_ids_to_uuid.sql
New SQL migration that creates a temporary _workspace_id_map, maps non-UUID workspaces.id values to generated UUID v4 values, updates settings.last_active_workspace_id and workspaces.id using the map in an atomic statement, then drops the map.
Database Metadata & Journal
packages/local-db/drizzle/meta/0031_snapshot.json, packages/local-db/drizzle/meta/_journal.json
Adds a full SQLite schema snapshot (new JSON snapshot) and appends a journal entry (idx 31, version 6, tag 0031_migrate_workspace_ids_to_uuid).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble bytes and hop through rows,

Old IDs swapped for UUIDs that glow.
A tiny map, a tidy sweep,
Now workspaces dream in IDs that keep.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(local-db): migrate non-UUID workspace IDs to UUID v4' clearly and concisely summarizes the main change—migrating non-UUID workspace IDs to UUID v4 format in the local database.
Description check ✅ Passed The pull request description comprehensively covers the summary, changes made, and test plan; all required template sections are addressed with clear, detailed information about the migration logic and verification steps.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kitenite/uuid

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/local-db/drizzle/0031_migrate_workspace_ids_to_uuid.sql (1)

6-9: Minor: consider INSERT OR IGNORE for extra resilience against partial re-runs.

If the migration runner ever re-executes after a partial failure outside a transaction, the INSERT at Line 11 would fail on duplicate old_id primary keys while CREATE TABLE IF NOT EXISTS would silently succeed. Using INSERT OR IGNORE (or INSERT 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.
@github-actions
Copy link
Contributor

github-actions bot commented Feb 21, 2026

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) View Branch
Fly.io Electric (Fly.io) View App
Vercel API (Vercel) Open Preview
Vercel Web (Vercel) Open Preview
Vercel Marketing (Vercel) Open Preview
Vercel Admin (Vercel) Open Preview
Vercel Docs (Vercel) Open Preview

Preview updates automatically with new commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant