Remove variable_count keys missed in manual data migration.
This commit is contained in:
parent
5224357f8b
commit
9f598541fb
|
@ -197,6 +197,7 @@ dependencies = [
|
||||||
"itertools",
|
"itertools",
|
||||||
"log",
|
"log",
|
||||||
"matrix-sdk",
|
"matrix-sdk",
|
||||||
|
"memmem",
|
||||||
"nom",
|
"nom",
|
||||||
"olm-sys",
|
"olm-sys",
|
||||||
"phf",
|
"phf",
|
||||||
|
@ -1043,6 +1044,12 @@ version = "2.3.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
|
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memmem"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a64a92489e2744ce060c349162be1c5f33c6969234104dbd99ddb5feb08b8c15"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memoffset"
|
name = "memoffset"
|
||||||
version = "0.5.6"
|
version = "0.5.6"
|
||||||
|
|
|
@ -27,6 +27,7 @@ sled = "0.34"
|
||||||
zerocopy = "0.3"
|
zerocopy = "0.3"
|
||||||
byteorder = "1.3"
|
byteorder = "1.3"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
memmem = "0.1"
|
||||||
phf = { version = "0.7", features = ["macros"] }
|
phf = { version = "0.7", features = ["macros"] }
|
||||||
olm-sys = "1.0"
|
olm-sys = "1.0"
|
||||||
matrix-sdk = { git = "https://github.com/matrix-org/matrix-rust-sdk", rev = "master" }
|
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
|
/// Shortcut to defining db migration versions. Will probably
|
||||||
/// eventually be moved to a config file.
|
/// eventually be moved to a config file.
|
||||||
const MIGRATION_VERSION: u32 = 2;
|
const MIGRATION_VERSION: u32 = 3;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum ConfigError {
|
pub enum ConfigError {
|
||||||
|
|
|
@ -8,6 +8,7 @@ pub(super) type DataMigration = (fn(&Database) -> Result<(), DataError>, &'stati
|
||||||
static MIGRATIONS: phf::Map<u32, DataMigration> = phf_map! {
|
static MIGRATIONS: phf::Map<u32, DataMigration> = phf_map! {
|
||||||
1u32 => (add_room_user_variable_count, "add_room_user_variable_count"),
|
1u32 => (add_room_user_variable_count, "add_room_user_variable_count"),
|
||||||
2u32 => (delete_v0_schema, "delete_v0_schema"),
|
2u32 => (delete_v0_schema, "delete_v0_schema"),
|
||||||
|
3u32 => (delete_variable_count, "delete_variable_count"),
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn get_migrations(versions: &[u32]) -> Result<Vec<DataMigration>, MigrationError> {
|
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::errors::{DataError, MigrationError};
|
||||||
use crate::db::Database;
|
use crate::db::Database;
|
||||||
use byteorder::LittleEndian;
|
use byteorder::LittleEndian;
|
||||||
|
use memmem::{Searcher, TwoWaySearcher};
|
||||||
use sled::transaction::TransactionError;
|
use sled::transaction::TransactionError;
|
||||||
use sled::{Batch, IVec};
|
use sled::{Batch, IVec};
|
||||||
use zerocopy::byteorder::U32;
|
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)?;
|
db.variables.0.apply_batch(batch)?;
|
||||||
Ok(())
|
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