mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-10 06:25:00 +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(());
|
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 {
|
||||||
for hash in old.hashes() {
|
Self::Sled(repo) => {
|
||||||
match self {
|
if let Err(e) = migrate_hash(repo, &old, hash).await {
|
||||||
Self::Sled(repo) => {
|
tracing::error!("Failed to migrate hash: {}", e);
|
||||||
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 {
|
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")?,
|
details_tree: db.open_tree("details")?,
|
||||||
details_tree: db.open_tree("details")?,
|
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