37 lines
896 B
Rust
37 lines
896 B
Rust
pub mod v1_to_v2;
|
|
|
|
use crate::database::unversioned::global::schema_version;
|
|
use duplicate::duplicate;
|
|
use sled::Db;
|
|
|
|
pub fn migrate(db: &mut Db, from: schema_version::V, to: schema_version::V) -> Result<(), MigrationError> {
|
|
for current in from..to {
|
|
let next = current + 1;
|
|
|
|
println!("Will migrate from {} to {}", current, next);
|
|
match (current, next) {
|
|
(1, 2) => v1_to_v2::migrate(db)?,
|
|
_ => panic!("No valid migration from version {} to version {}", current, next),
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum MigrationError {
|
|
Serde(bincode::Error),
|
|
Sled(sled::Error),
|
|
}
|
|
|
|
#[duplicate(
|
|
Variant Error;
|
|
[ Sled ] [ sled::Error ];
|
|
[ Serde ] [ bincode::Error ];
|
|
)]
|
|
impl From<Error> for MigrationError {
|
|
fn from(e: Error) -> MigrationError {
|
|
MigrationError::Variant(e)
|
|
}
|
|
}
|