test case and handle in-place migration correctly
This commit is contained in:
parent
ed0a2567d8
commit
ac82a838b8
@ -201,6 +201,9 @@ fn migrate_database(version: u32, db_path: PathBuf, mut migrations: MigrationMan
|
||||
// migrate old database to the new one
|
||||
let temp_path = migrations.execute(&db_path, version)?;
|
||||
|
||||
// completely in-place migration leads to the paths being equal.
|
||||
// in that case, no need to shuffle directories.
|
||||
if temp_path != db_path {
|
||||
// create backup
|
||||
fs::rename(&db_path, &backup_path)?;
|
||||
|
||||
@ -213,6 +216,7 @@ fn migrate_database(version: u32, db_path: PathBuf, mut migrations: MigrationMan
|
||||
|
||||
// remove backup
|
||||
fs::remove_dir_all(&backup_path)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -226,3 +226,24 @@ fn pre_columns() {
|
||||
// short of the one before it.
|
||||
manager.execute(&db_path, 0).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn change_columns() {
|
||||
use kvdb::DatabaseConfig;
|
||||
|
||||
let mut manager = Manager::new(Config::default());
|
||||
manager.add_migration(::migration::ChangeColumns {
|
||||
pre_columns: None,
|
||||
post_columns: Some(4),
|
||||
version: 1,
|
||||
}).unwrap();
|
||||
|
||||
let dir = RandomTempPath::create_dir();
|
||||
let db_path = db_path(dir.as_path());
|
||||
|
||||
let new_path = manager.execute(&db_path, 0).unwrap();
|
||||
|
||||
let config = DatabaseConfig::with_columns(Some(4));
|
||||
let db = Database::open(&config, new_path.to_str().unwrap()).unwrap();
|
||||
assert_eq!(db.num_columns(), 4);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user