Handle legacy DB schema mismatch at startup#1025
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR adds schema validation to detect and handle legacy database files that lack required columns. It introduces a typed Key Changes:
Impact: Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| src/main/db/path.ts | Added EMDASH_DB_FILE environment variable override support with absolute path resolution |
| src/main/services/DatabaseService.ts | Added DatabaseSchemaMismatchError class and validateSchemaContract() to check for required schema invariants after migrations |
| src/main/main.ts | Added startup recovery dialog for schema mismatch errors with database reset and relaunch functionality |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
Start[App Startup] --> Init[databaseService.initialize]
Init --> Migrate[ensureMigrations]
Migrate --> Validate[validateSchemaContract]
Validate -->|Check 1| CheckBaseRef{projects.base_ref exists?}
CheckBaseRef -->|No| AddMissing1[Add to missingInvariants]
CheckBaseRef -->|Yes| CheckTasks
AddMissing1 --> CheckTasks
CheckTasks{tasks table exists?} -->|No| AddMissing2[Add to missingInvariants]
CheckTasks -->|Yes| CheckTaskId
AddMissing2 --> CheckTaskId
CheckTaskId{conversations.task_id exists?} -->|No| AddMissing3[Add to missingInvariants]
CheckTaskId -->|Yes| CheckList
AddMissing3 --> CheckList
CheckList{missingInvariants.length > 0?} -->|Yes| ThrowError[Throw DatabaseSchemaMismatchError]
CheckList -->|No| Success[Initialization Complete]
ThrowError --> ShowDialog[Show Recovery Dialog]
ShowDialog -->|User: Reset & Relaunch| DeleteDB[Delete DB files WAL SHM]
ShowDialog -->|User: Quit| AppQuit[app.quit]
DeleteDB --> Relaunch[app.relaunch + app.exit]
DeleteDB -->|Delete fails| ErrorBox[Show error dialog]
ErrorBox --> AppQuit
Success --> ContinueStartup[Continue app startup]
Last reviewed commit: 3a79a7a
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Summary
Contract checks
Tests
Validation
Note
Medium Risk
Changes core startup/database initialization behavior and adds a destructive “reset local data” path; mistakes could block app launch or delete the wrong DB file if the resolved path is unexpected.
Overview
Adds an explicit
EMDASH_DB_FILEoverride for database path resolution to make local DB selection deterministic (and testable).Tightens DB startup by validating a post-migration schema contract and throwing a typed
DatabaseSchemaMismatchErrorwhen required invariants are missing; app startup now catches this error and prompts the user to reset local DB files (including-wal/-shm) and relaunch or quit.Includes new Vitest coverage for DB path override behavior and for distinguishing schema-contract failures from migration failures during
DatabaseService.initialize().Written by Cursor Bugbot for commit f9fb4ec. This will update automatically on new commits. Configure here.