Fix bd-11e0: Auto-upgrade database version in daemon instead of exiting
This commit is contained in:
@@ -288,24 +288,24 @@ func runDaemonLoop(interval time.Duration, autoCommit, autoPush bool, logPath, p
|
|||||||
}
|
}
|
||||||
|
|
||||||
if dbVersion != "" && dbVersion != Version {
|
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(" Database version: %s", dbVersion)
|
||||||
log.log(" Daemon version: %s", Version)
|
log.log(" Daemon version: %s", Version)
|
||||||
log.log("")
|
log.log(" Auto-upgrading database to daemon version...")
|
||||||
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("")
|
|
||||||
|
|
||||||
// Allow override via environment variable for emergencies
|
// Auto-upgrade database to daemon version
|
||||||
if os.Getenv("BEADS_IGNORE_VERSION_MISMATCH") != "1" {
|
// The daemon operates on its own database, so it should always use its own version
|
||||||
os.Exit(1)
|
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 == "" {
|
} else if dbVersion == "" {
|
||||||
// Old database without version metadata - set it now
|
// Old database without version metadata - set it now
|
||||||
log.log("Warning: Database missing version metadata, setting to %s", Version)
|
log.log("Warning: Database missing version metadata, setting to %s", Version)
|
||||||
|
|||||||
Reference in New Issue
Block a user