Fix bd-11e0: Auto-upgrade database version in daemon instead of exiting

This commit is contained in:
Steve Yegge
2025-11-01 19:28:37 -07:00
parent a4b9ae5fcf
commit a708c321fb

View File

@@ -288,24 +288,24 @@ func runDaemonLoop(interval time.Duration, autoCommit, autoPush bool, logPath, p
}
if dbVersion != "" && dbVersion != Version {
log.log("Error: Database schema version mismatch")
log.log("Warning: Database schema version mismatch")
log.log(" Database version: %s", dbVersion)
log.log(" Daemon version: %s", Version)
log.log("")
log.log("The database was created with a different version of bd.")
log.log("This may cause compatibility issues.")
log.log("")
log.log("Options:")
log.log(" 1. Run 'bd migrate' to update the database to the current version")
log.log(" 2. Upgrade/downgrade bd to match database version: %s", dbVersion)
log.log(" 3. Set BEADS_IGNORE_VERSION_MISMATCH=1 to proceed anyway (not recommended)")
log.log("")
log.log(" Auto-upgrading database to daemon version...")
// Allow override via environment variable for emergencies
if os.Getenv("BEADS_IGNORE_VERSION_MISMATCH") != "1" {
os.Exit(1)
// Auto-upgrade database to daemon version
// The daemon operates on its own database, so it should always use its own version
if err := store.SetMetadata(versionCtx, "bd_version", Version); err != nil {
log.log("Error: failed to update database version: %v", err)
// Allow override via environment variable for emergencies
if os.Getenv("BEADS_IGNORE_VERSION_MISMATCH") != "1" {
os.Exit(1)
}
log.log("Warning: Proceeding despite version update failure (BEADS_IGNORE_VERSION_MISMATCH=1)")
} else {
log.log(" Database version updated to %s", Version)
}
log.log("Warning: Proceeding despite version mismatch (BEADS_IGNORE_VERSION_MISMATCH=1)")
} else if dbVersion == "" {
// Old database without version metadata - set it now
log.log("Warning: Database missing version metadata, setting to %s", Version)