mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Don't migrate from the old database if it doesn't exist
This commit is contained in:
parent
f8fed14317
commit
547934071a
3 changed files with 26 additions and 23 deletions
|
@ -243,10 +243,9 @@ impl Repo {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(old) = self::old::Old::open(path)? {
|
||||||
tracing::warn!("Migrating Database from 0.3 layout to 0.4 layout");
|
tracing::warn!("Migrating Database from 0.3 layout to 0.4 layout");
|
||||||
|
|
||||||
let old = self::old::Old::open(path)?;
|
|
||||||
|
|
||||||
for hash in old.hashes() {
|
for hash in old.hashes() {
|
||||||
match self {
|
match self {
|
||||||
Self::Sled(repo) => {
|
Self::Sled(repo) => {
|
||||||
|
@ -256,6 +255,7 @@ impl Repo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.mark_migrated().await?;
|
self.mark_migrated().await?;
|
||||||
|
|
||||||
|
|
|
@ -44,10 +44,9 @@ pub(super) struct Old {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Old {
|
impl Old {
|
||||||
pub(super) fn open(path: PathBuf) -> color_eyre::Result<Self> {
|
pub(super) fn open(path: PathBuf) -> color_eyre::Result<Option<Self>> {
|
||||||
let db = migrate::LatestDb::exists(path).migrate()?;
|
if let Some(db) = migrate::LatestDb::exists(path).migrate()? {
|
||||||
|
Ok(Some(Self {
|
||||||
Ok(Self {
|
|
||||||
alias_tree: db.open_tree("alias")?,
|
alias_tree: db.open_tree("alias")?,
|
||||||
filename_tree: db.open_tree("filename")?,
|
filename_tree: db.open_tree("filename")?,
|
||||||
main_tree: db.open_tree("main")?,
|
main_tree: db.open_tree("main")?,
|
||||||
|
@ -55,7 +54,10 @@ impl Old {
|
||||||
settings_tree: db.open_tree("settings")?,
|
settings_tree: db.open_tree("settings")?,
|
||||||
identifier_tree: db.open_tree("path")?,
|
identifier_tree: db.open_tree("path")?,
|
||||||
_db: db,
|
_db: db,
|
||||||
})
|
}))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn setting(&self, key: &[u8]) -> color_eyre::Result<Option<sled::IVec>> {
|
pub(super) fn setting(&self, key: &[u8]) -> color_eyre::Result<Option<sled::IVec>> {
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl LatestDb {
|
||||||
LatestDb { root_dir, version }
|
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;
|
let LatestDb { root_dir, version } = self;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -89,9 +89,10 @@ impl DbVersion {
|
||||||
DbVersion::Fresh
|
DbVersion::Fresh
|
||||||
}
|
}
|
||||||
|
|
||||||
fn migrate(self, root: PathBuf) -> Result<sled::Db, Error> {
|
fn migrate(self, root: PathBuf) -> Result<Option<sled::Db>, Error> {
|
||||||
match self {
|
match self {
|
||||||
DbVersion::Sled034 | DbVersion::Fresh => s034::open(root),
|
DbVersion::Sled034 => Some(s034::open(root)).transpose(),
|
||||||
|
DbVersion::Fresh => Ok(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue