use std::path::PathBuf;
use anyhow::Context;
use webfind::storage::migrate::migrate_graph;
pub async fn run(
cfg: &webfind::config::WebfindConfig,
from: PathBuf,
to: PathBuf,
) -> anyhow::Result<()> {
let to = resolve_dest(cfg, to);
let to_str = to
.to_str()
.with_context(|| format!("destination path is not valid UTF-8: {}", to.display()))?;
if !from.exists() {
anyhow::bail!(
"export file not found: {} — run `surrealdb export` or supply a valid path",
from.display()
);
}
println!(
"Migrating\n from: {}\n to: {}",
from.display(),
to.display()
);
let report = migrate_graph(&from, to_str)
.await
.context("migration failed")?;
println!("\nMigration complete:");
println!(" url_nodes: {}", report.url_nodes_imported);
println!(" link_edges: {}", report.link_edges_imported);
println!(" page_content: {}", report.page_content_imported);
println!(" crawl_jobs: {}", report.crawl_jobs_imported);
if let Some(dim) = report.embedding_dimension {
println!(" embedding_dim: {} (validated)", dim);
} else {
println!(" embedding_dim: none");
}
Ok(())
}
fn resolve_dest(_cfg: &webfind::config::WebfindConfig, to: PathBuf) -> PathBuf {
if to.is_absolute() {
return to;
}
webfind::config::data_dir().join(to)
}