Simplify database migration logic - error if both files exist

This commit is contained in:
Jamie Pine 2025-12-01 15:00:59 -08:00
parent e127a5aa0b
commit b5a77c403e

View File

@ -441,26 +441,13 @@ impl LibraryManager {
let new_db_path = path.join(LIBRARY_DB_FILENAME);
if old_db_path.exists() {
// Check if we need to migrate
let should_migrate = if new_db_path.exists() {
// If both exist, migrate if old one is substantially larger (means new one is empty/fresh)
let old_size = tokio::fs::metadata(&old_db_path).await?.len();
let new_size = tokio::fs::metadata(&new_db_path).await?.len();
old_size > new_size * 10
} else {
true
};
if should_migrate {
info!("Migrating database.db to library.db");
// Remove any empty library.db first
if new_db_path.exists() {
let _ = tokio::fs::remove_file(&new_db_path).await;
let _ = tokio::fs::remove_file(path.join("library.db-wal")).await;
let _ = tokio::fs::remove_file(path.join("library.db-shm")).await;
return Err(LibraryError::Other(
"Both database.db and library.db exist. Please manually delete one.".to_string()
));
}
info!("Migrating database.db to library.db");
tokio::fs::rename(&old_db_path, &new_db_path)
.await
.map_err(|e| LibraryError::Other(format!("Failed to rename database: {}", e)))?;
@ -478,7 +465,6 @@ impl LibraryManager {
let _ = tokio::fs::rename(&old_shm, &new_shm).await;
}
}
}
// Open database
let db_path = new_db_path;