Update database schema
Also bump major version to match schema version
This commit is contained in:
36
src/database/migrations/mod.rs
Normal file
36
src/database/migrations/mod.rs
Normal file
@ -0,0 +1,36 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user