2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 11:21:24 +00:00

Don't migrate from the old database if it doesn't exist

This commit is contained in:
Aode (lion) 2022-08-14 11:49:20 -05:00
parent f8fed14317
commit 547934071a
3 changed files with 26 additions and 23 deletions

View file

@ -243,10 +243,9 @@ impl Repo {
return Ok(());
}
if let Some(old) = self::old::Old::open(path)? {
tracing::warn!("Migrating Database from 0.3 layout to 0.4 layout");
let old = self::old::Old::open(path)?;
for hash in old.hashes() {
match self {
Self::Sled(repo) => {
@ -256,6 +255,7 @@ impl Repo {
}
}
}
}
self.mark_migrated().await?;

View file

@ -44,10 +44,9 @@ pub(super) struct Old {
}
impl Old {
pub(super) fn open(path: PathBuf) -> color_eyre::Result<Self> {
let db = migrate::LatestDb::exists(path).migrate()?;
Ok(Self {
pub(super) fn open(path: PathBuf) -> color_eyre::Result<Option<Self>> {
if let Some(db) = migrate::LatestDb::exists(path).migrate()? {
Ok(Some(Self {
alias_tree: db.open_tree("alias")?,
filename_tree: db.open_tree("filename")?,
main_tree: db.open_tree("main")?,
@ -55,7 +54,10 @@ impl Old {
settings_tree: db.open_tree("settings")?,
identifier_tree: db.open_tree("path")?,
_db: db,
})
}))
} else {
Ok(None)
}
}
pub(super) fn setting(&self, key: &[u8]) -> color_eyre::Result<Option<sled::IVec>> {

View file

@ -60,7 +60,7 @@ impl LatestDb {
LatestDb { root_dir, version }
}
pub(crate) fn migrate(self) -> Result<sled::Db, Error> {
pub(crate) fn migrate(self) -> Result<Option<sled::Db>, Error> {
let LatestDb { root_dir, version } = self;
loop {
@ -89,9 +89,10 @@ impl DbVersion {
DbVersion::Fresh
}
fn migrate(self, root: PathBuf) -> Result<sled::Db, Error> {
fn migrate(self, root: PathBuf) -> Result<Option<sled::Db>, Error> {
match self {
DbVersion::Sled034 | DbVersion::Fresh => s034::open(root),
DbVersion::Sled034 => Some(s034::open(root)).transpose(),
DbVersion::Fresh => Ok(None),
}
}
}