forked from projectmoon/tenebrous-dicebot
Remove variable_count keys missed in manual data migration.
This commit is contained in:
parent
5224357f8b
commit
9f598541fb
|
@ -197,6 +197,7 @@ dependencies = [
|
|||
"itertools",
|
||||
"log",
|
||||
"matrix-sdk",
|
||||
"memmem",
|
||||
"nom",
|
||||
"olm-sys",
|
||||
"phf",
|
||||
|
@ -1043,6 +1044,12 @@ version = "2.3.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
|
||||
|
||||
[[package]]
|
||||
name = "memmem"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a64a92489e2744ce060c349162be1c5f33c6969234104dbd99ddb5feb08b8c15"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.5.6"
|
||||
|
|
|
@ -27,6 +27,7 @@ sled = "0.34"
|
|||
zerocopy = "0.3"
|
||||
byteorder = "1.3"
|
||||
futures = "0.3"
|
||||
memmem = "0.1"
|
||||
phf = { version = "0.7", features = ["macros"] }
|
||||
olm-sys = "1.0"
|
||||
matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "master" }
|
||||
|
|
|
@ -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 = 2;
|
||||
const MIGRATION_VERSION: u32 = 3;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ConfigError {
|
||||
|
|
|
@ -8,6 +8,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"),
|
||||
3u32 => (delete_variable_count, "delete_variable_count"),
|
||||
};
|
||||
|
||||
pub fn get_migrations(versions: &[u32]) -> Result<Vec<DataMigration>, MigrationError> {
|
||||
|
|
|
@ -2,6 +2,7 @@ use super::*;
|
|||
use crate::db::errors::{DataError, MigrationError};
|
||||
use crate::db::Database;
|
||||
use byteorder::LittleEndian;
|
||||
use memmem::{Searcher, TwoWaySearcher};
|
||||
use sled::transaction::TransactionError;
|
||||
use sled::{Batch, IVec};
|
||||
use zerocopy::byteorder::U32;
|
||||
|
@ -108,3 +109,26 @@ pub(in crate::db) fn delete_v0_schema(db: &Database) -> Result<(), DataError> {
|
|||
db.variables.0.apply_batch(batch)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(in crate::db) fn delete_variable_count(db: &Database) -> Result<(), DataError> {
|
||||
let prefix = variables_space_prefix("");
|
||||
let mut vars = db.variables.0.scan_prefix(prefix);
|
||||
let mut batch = Batch::default();
|
||||
|
||||
while let Some(Ok((key, _))) = vars.next() {
|
||||
let search = TwoWaySearcher::new(b"variable_count");
|
||||
let ends_with = {
|
||||
match search.search_in(&key) {
|
||||
Some(index) => key.len() - index == b"variable_count".len(),
|
||||
None => false,
|
||||
}
|
||||
};
|
||||
|
||||
if ends_with {
|
||||
batch.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
db.variables.0.apply_batch(batch)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue