packages/db/src/migration-scripts/README.md
This directory contains migration scripts for transitioning the database schema to support new features.
The migrate-to-branching.ts script migrates existing projects from the legacy schema to the new branching structure introduced in PR #2763.
Before (Legacy):
sandboxId and sandboxUrl fieldstype field (using FrameType enum)After (New Schema):
sandboxId and sandboxUrl (moved to branches)branches table with default branch per projectbranchId referenceFrameType enum removed from framesisDefault: truesandboxId from projects to the default branch (generates new UUID if null)SUPABASE_DATABASE_URL environment variable (should be in root .env file)cd packages/db
bun run db:migrate:branching
cd packages/db/src/migration-scripts
bun run migrate-to-branching.ts
import { migrateToBranching } from '@onlook/db/src/migration-scripts/migrate-to-branching';
await migrateToBranching();
The script provides detailed logging:
After running the migration, verify:
-- Should return 0
SELECT COUNT(*) FROM frames WHERE branch_id IS NULL;
-- Should have at least one default branch per project
SELECT
p.id as project_id,
p.name,
b.id as branch_id,
b.name as branch_name,
b.is_default
FROM projects p
LEFT JOIN branches b ON p.id = b.project_id AND b.is_default = true;
If you need to rollback (not recommended after schema changes are deployed):
branches tablesandboxId and sandboxUrl columns to projects tablebranchId column from frames tabletype column to frames table⚠️ Important: This migration should be run before deploying the new schema that removes the deprecated columns.