refactor: rename last_import_hash to jsonl_content_hash (bd-39o)
The metadata key 'last_import_hash' was misleading because it's updated on both import AND export. Renamed to 'jsonl_content_hash' which more accurately describes its purpose - tracking the content hash of the JSONL file. Added migration support: read operations try new key first, then fall back to old key for backwards compatibility with existing databases. Files modified: - cmd/bd/integrity.go: Update key name with migration support - cmd/bd/import.go: Update key name - cmd/bd/sync.go: Update key name - cmd/bd/autoflush.go: Update key name with migration support - cmd/bd/daemon_sync.go: Update key name - cmd/bd/daemon_event_loop.go: Update key name with migration support - internal/autoimport/autoimport.go: Update key name with migration support - Updated all related tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -84,10 +84,14 @@ func AutoImportIfNewer(ctx context.Context, store storage.Storage, dbPath string
|
||||
hasher.Write(jsonlData)
|
||||
currentHash := hex.EncodeToString(hasher.Sum(nil))
|
||||
|
||||
lastHash, err := store.GetMetadata(ctx, "last_import_hash")
|
||||
if err != nil {
|
||||
notify.Debugf("metadata read failed (%v), treating as first import", err)
|
||||
lastHash = ""
|
||||
// Try new key first, fall back to old key for migration (bd-39o)
|
||||
lastHash, err := store.GetMetadata(ctx, "jsonl_content_hash")
|
||||
if err != nil || lastHash == "" {
|
||||
lastHash, err = store.GetMetadata(ctx, "last_import_hash")
|
||||
if err != nil {
|
||||
notify.Debugf("metadata read failed (%v), treating as first import", err)
|
||||
lastHash = ""
|
||||
}
|
||||
}
|
||||
|
||||
if currentHash == lastHash {
|
||||
@@ -130,8 +134,8 @@ func AutoImportIfNewer(ctx context.Context, store storage.Storage, dbPath string
|
||||
onChanged(needsFullExport)
|
||||
}
|
||||
|
||||
if err := store.SetMetadata(ctx, "last_import_hash", currentHash); err != nil {
|
||||
notify.Warnf("failed to update last_import_hash after import: %v", err)
|
||||
if err := store.SetMetadata(ctx, "jsonl_content_hash", currentHash); err != nil {
|
||||
notify.Warnf("failed to update jsonl_content_hash after import: %v", err)
|
||||
notify.Warnf("This may cause auto-import to retry the same import on next operation.")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user