fix(bd-68e4): make DBJSONLSync bidirectional - export DB when it has more issues
- Modified fix.DBJSONLSync() to detect which direction to sync: - If DB > JSONL: run 'bd export' to sync JSONL (DB has newer data) - If JSONL > DB: run 'bd sync --import-only' to import (JSONL is source of truth) - If equal but different timestamps: use file mtime to decide direction - Updated CheckDatabaseJSONLSync() error messages to recommend correct fix direction: - Shows different guidance based on whether DB or JSONL has more issues - Added helper functions: - countDatabaseIssues() to count issues in SQLite - countJSONLIssues() to count issues in JSONL (local, avoids circular import) - Added tests for countJSONLIssues() with edge cases Fixes issue where 'bd doctor --fix' would recommend 'bd sync --import-only' when DB > JSONL, which would be a no-op since JSONL hasn't changed.
This commit is contained in:
@@ -425,11 +425,25 @@ func CheckDatabaseJSONLSync(path string) DoctorCheck {
|
||||
|
||||
// If we found issues, report them
|
||||
if len(issues) > 0 {
|
||||
// Provide direction-specific guidance
|
||||
var fixMsg string
|
||||
if dbCount > jsonlCount {
|
||||
fixMsg = "Run 'bd doctor --fix' to automatically export DB to JSONL, or manually run 'bd export'"
|
||||
} else if jsonlCount > dbCount {
|
||||
fixMsg = "Run 'bd doctor --fix' to automatically import JSONL to DB, or manually run 'bd sync --import-only'"
|
||||
} else {
|
||||
// Equal counts but other issues (like prefix mismatch)
|
||||
fixMsg = "Run 'bd doctor --fix' to fix automatically, or manually run 'bd sync --import-only' or 'bd export' depending on which has newer data"
|
||||
}
|
||||
if strings.Contains(strings.Join(issues, " "), "Prefix mismatch") {
|
||||
fixMsg = "Run 'bd import -i " + filepath.Base(jsonlPath) + " --rename-on-import' to fix prefixes"
|
||||
}
|
||||
|
||||
return DoctorCheck{
|
||||
Name: "DB-JSONL Sync",
|
||||
Status: StatusWarning,
|
||||
Message: strings.Join(issues, "; "),
|
||||
Fix: "Run 'bd sync --import-only' to import JSONL updates or 'bd import -i issues.jsonl --rename-on-import' to fix prefixes",
|
||||
Fix: fixMsg,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user