use cortex_core::storage::{RedbStorage, Storage};
use cortex_core::NodeFilter;
pub fn migrate_alexandria() -> anyhow::Result<()> {
tracing::warn!("Alexandria migration not yet implemented");
Ok(())
}
pub fn migrate_v1_to_v2(storage: &mut RedbStorage) -> anyhow::Result<()> {
let db_path = storage.path().to_path_buf();
let backup_path = db_path.with_extension("redb.v1.bak");
std::fs::copy(&db_path, &backup_path)
.map_err(|e| anyhow::anyhow!("Failed to backup database to {:?}: {}", backup_path, e))?;
tracing::info!("Database backed up to {:?}", backup_path);
let nodes = storage
.list_nodes(NodeFilter::new().include_deleted())
.map_err(|e| {
anyhow::anyhow!(
"Failed to read nodes — DB may contain genuine v1 (enum-encoded) NodeKind data. \
To migrate: export with the v1 binary, then re-import using `cortex import`. \
Error: {}",
e
)
})?;
tracing::info!("Migration v1 → v2 complete: {} nodes verified", nodes.len());
Ok(())
}