fix: Code review fixes for auto-migration (bd-jgxi)
Critical fixes from code review: 1. **Moved auto-migration to correct location** - Now runs AFTER daemon check but BEFORE opening database - Prevents: database opened twice, conflicts with daemon - Was: Running too early, before knowing if daemon exists 2. **Fixed context cancellation issue** - Check if rootCtx is canceled before using it - Fall back to Background() if canceled - Fixes: "context canceled" errors in test suite 3. **Updated function signature** - Takes dbPath as parameter (no longer searches for it) - Simpler, more explicit, easier to test - Caller already has dbPath, no need to re-discover 4. **Enhanced test reliability** - Save/restore all global state - Add debug logging for troubleshooting - Verify preconditions before migration Changes: - cmd/bd/main.go: Move autoMigrateOnVersionBump call to correct location - cmd/bd/version_tracking.go: Fix context handling, update signature - cmd/bd/version_tracking_test.go: Improve test reliability 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -302,10 +302,6 @@ var rootCmd = &cobra.Command{
|
||||
// Best-effort tracking - failures are silent
|
||||
trackBdVersion()
|
||||
|
||||
// Auto-migrate database on version bump (bd-jgxi)
|
||||
// Best-effort migration - failures are silent to avoid disrupting commands
|
||||
autoMigrateOnVersionBump()
|
||||
|
||||
// Initialize daemon status
|
||||
socketPath := getSocketPath()
|
||||
daemonStatus = DaemonStatus{
|
||||
@@ -479,6 +475,11 @@ var rootCmd = &cobra.Command{
|
||||
debug.Logf("using direct mode (reason: %s)", daemonStatus.FallbackReason)
|
||||
}
|
||||
|
||||
// Auto-migrate database on version bump (bd-jgxi)
|
||||
// Do this AFTER daemon check but BEFORE opening database for main operation
|
||||
// This ensures: 1) no daemon has DB open, 2) we don't open DB twice
|
||||
autoMigrateOnVersionBump(dbPath)
|
||||
|
||||
// Fall back to direct storage access
|
||||
var err error
|
||||
store, err = sqlite.New(rootCtx, dbPath)
|
||||
|
||||
Reference in New Issue
Block a user