Add migration 2: remove old data.
This commit is contained in:
parent
6b21b0aff8
commit
5224357f8b
|
@ -6,7 +6,7 @@ use thiserror::Error;
|
|||
|
||||
/// Shortcut to defining db migration versions. Will probably
|
||||
/// eventually be moved to a config file.
|
||||
const MIGRATION_VERSION: u32 = 1;
|
||||
const MIGRATION_VERSION: u32 = 2;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ConfigError {
|
||||
|
|
|
@ -7,6 +7,7 @@ pub(super) type DataMigration = (fn(&Database) -> Result<(), DataError>, &'stati
|
|||
|
||||
static MIGRATIONS: phf::Map<u32, DataMigration> = phf_map! {
|
||||
1u32 => (add_room_user_variable_count, "add_room_user_variable_count"),
|
||||
2u32 => (delete_v0_schema, "delete_v0_schema"),
|
||||
};
|
||||
|
||||
pub fn get_migrations(versions: &[u32]) -> Result<Vec<DataMigration>, MigrationError> {
|
||||
|
|
|
@ -92,3 +92,19 @@ pub(in crate::db) fn add_room_user_variable_count(db: &Database) -> Result<(), D
|
|||
tx_result?; //For some reason, it cannot infer the type
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(in crate::db) fn delete_v0_schema(db: &Database) -> Result<(), DataError> {
|
||||
let mut vars = db.variables.0.scan_prefix("");
|
||||
let mut batch = Batch::default();
|
||||
|
||||
while let Some(Ok((key, _))) = vars.next() {
|
||||
let key = key.to_vec();
|
||||
|
||||
if !key.contains(&0xff) {
|
||||
batch.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
db.variables.0.apply_batch(batch)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue