-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storage: Migration 28 - fix empty petnames
- Loading branch information
1 parent
c99f603
commit 7ba455d
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::error::Error; | ||
use crate::storage::types::Person2; | ||
use crate::storage::Storage; | ||
use heed::RwTxn; | ||
|
||
impl Storage { | ||
pub(super) fn m28_trigger(&self) -> Result<(), Error> { | ||
let _ = self.db_people2()?; | ||
Ok(()) | ||
} | ||
|
||
pub(super) fn m28_migrate<'a>( | ||
&'a self, | ||
prefix: &str, | ||
txn: &mut RwTxn<'a>, | ||
) -> Result<(), Error> { | ||
// Info message | ||
tracing::info!("{prefix}: fixing empty petnames..."); | ||
|
||
// Migrate | ||
self.m28_fix_empty_petnames(txn)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn m28_fix_empty_petnames<'a>(&'a self, txn: &mut RwTxn<'a>) -> Result<(), Error> { | ||
let loop_txn = self.env.read_txn()?; | ||
for result in self.db_people2()?.iter(&loop_txn)? { | ||
let (key, val) = result?; | ||
let mut person: Person2 = serde_json::from_slice(val)?; | ||
if person.petname == Some("".to_string()) { | ||
person.petname = None; | ||
let bytes = serde_json::to_vec(&person)?; | ||
self.db_people2()?.put(txn, &key, &bytes)?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters