@@ -217,7 +217,7 @@ export class ProjectHandlers {
217217 await projectStoreInstance . saveSchema ( projectId , liveSchemas , newHash , dbType ) ;
218218
219219 if ( newHash !== oldHash ) {
220- this . rpc . sendNotification ( "project.schema_changed" , { projectId, newHash } ) ;
220+ this . rpc ? .sendNotification ?. ( "project.schema_changed" , { projectId, newHash } ) ;
221221
222222 // Commit to Git if tracking
223223 try {
@@ -431,7 +431,10 @@ export class ProjectHandlers {
431431 pendingMigrations . push ( { file, version, isDestructive, destructiveOps } ) ;
432432 }
433433
434- // 6. Compute drift status
434+ // 6. Detect if all migration files are baseline-only (no real user migrations)
435+ const isBaselineOnly = hasMigrations && migrationFiles . every ( f => f . includes ( "baseline" ) ) ;
436+
437+ // 7. Compute drift status
435438 let driftStatus : "synced" | "drifted" | "unknown" = "unknown" ;
436439 if ( pendingMigrations . length === 0 && hasMigrations ) {
437440 // All migrations applied
@@ -449,10 +452,18 @@ export class ProjectHandlers {
449452 driftStatus = "synced" ;
450453 }
451454
452- // 7 . Compute available modes
455+ // 8 . Compute available modes
453456 const availableModes : Array < "run_migrations" | "apply_snapshot" | "skip" > = [ "skip" ] ;
454457 let recommendedMode : "run_migrations" | "apply_snapshot" | "skip" = "skip" ;
455- if ( hasMigrations && pendingMigrations . length > 0 ) {
458+
459+ if ( isBaselineOnly && hasSchemaSnapshot && targetDatabaseEmpty ) {
460+ // Baseline-only + empty DB + schema.json exists:
461+ // The baseline file has no real DDL — use schema.json to reconstruct the DB
462+ availableModes . unshift ( "apply_snapshot" ) ;
463+ recommendedMode = "apply_snapshot" ;
464+ // Override: treat as "no real migrations" for the dialog
465+ driftStatus = "drifted" ;
466+ } else if ( hasMigrations && pendingMigrations . length > 0 && ! isBaselineOnly ) {
456467 availableModes . unshift ( "run_migrations" ) ;
457468 recommendedMode = "run_migrations" ;
458469 }
@@ -461,17 +472,23 @@ export class ProjectHandlers {
461472 recommendedMode = "apply_snapshot" ;
462473 }
463474
475+ // For the dialog: if baseline-only + empty DB, report as "no real migrations"
476+ // so the frontend shows "Apply Schema Snapshot" (STATE 3) instead of
477+ // "Pending Migrations" (STATE 2) which would try to run the empty baseline
478+ const reportHasMigrations = isBaselineOnly && targetDatabaseEmpty ? false : hasMigrations ;
479+ const reportPendingMigrations = isBaselineOnly && targetDatabaseEmpty ? [ ] : pendingMigrations ;
480+
464481 const result = {
465- hasMigrations,
466- migrationCount : pendingMigrations . length ,
482+ hasMigrations : reportHasMigrations ,
483+ migrationCount : reportPendingMigrations . length ,
467484 hasSchemaSnapshot,
468485 lockFileStatus,
469486 tamperedFiles,
470487 targetDatabaseEmpty,
471488 targetTableCount,
472489 driftStatus,
473490 driftDetails : undefined ,
474- pendingMigrations,
491+ pendingMigrations : reportPendingMigrations ,
475492 availableModes,
476493 recommendedMode,
477494 } ;
0 commit comments