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
16
src/repo.rs
16
src/repo.rs
|
@ -243,15 +243,15 @@ impl Repo {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
tracing::warn!("Migrating Database from 0.3 layout to 0.4 layout");
|
||||
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) => {
|
||||
if let Err(e) = migrate_hash(repo, &old, hash).await {
|
||||
tracing::error!("Failed to migrate hash: {}", e);
|
||||
for hash in old.hashes() {
|
||||
match self {
|
||||
Self::Sled(repo) => {
|
||||
if let Err(e) = migrate_hash(repo, &old, hash).await {
|
||||
tracing::error!("Failed to migrate hash: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,18 +44,20 @@ 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 {
|
||||
alias_tree: db.open_tree("alias")?,
|
||||
filename_tree: db.open_tree("filename")?,
|
||||
main_tree: db.open_tree("main")?,
|
||||
details_tree: db.open_tree("details")?,
|
||||
settings_tree: db.open_tree("settings")?,
|
||||
identifier_tree: db.open_tree("path")?,
|
||||
_db: db,
|
||||
})
|
||||
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")?,
|
||||
details_tree: db.open_tree("details")?,
|
||||
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>> {
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue