From b0670c2f666442b82d534e512224bb3803104eb3 Mon Sep 17 00:00:00 2001 From: "Aode (lion)" Date: Sun, 3 Apr 2022 15:07:31 -0500 Subject: [PATCH] Move migrate to old --- src/main.rs | 6 +----- src/repo.rs | 5 +++-- src/repo/old.rs | 6 +++++- src/{ => repo/old}/migrate.rs | 0 src/{ => repo/old}/migrate/s034.rs | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) rename src/{ => repo/old}/migrate.rs (100%) rename src/{ => repo/old}/migrate/s034.rs (97%) diff --git a/src/main.rs b/src/main.rs index 66b9a3d..6c2d6a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,6 @@ mod ingest; mod init_tracing; mod magick; mod middleware; -mod migrate; mod process; mod processor; mod queue; @@ -60,7 +59,6 @@ use self::{ init_tracing::init_tracing, magick::details_hint, middleware::{Deadline, Internal}, - migrate::LatestDb, queue::queue_generate, repo::{Alias, DeleteToken, FullRepo, HashRepo, IdentifierRepo, Repo, SettingsRepo, UploadId}, serde_str::Serde, @@ -873,9 +871,7 @@ async fn main() -> color_eyre::Result<()> { init_tracing(&CONFIG.tracing)?; let repo = Repo::open(CONFIG.repo.clone())?; - - let db = LatestDb::exists(CONFIG.old_db.path.clone()).migrate()?; - repo.from_db(db).await?; + repo.from_db(CONFIG.old_db.path.clone()).await?; match (*OPERATION).clone() { Operation::Run => (), diff --git a/src/repo.rs b/src/repo.rs index 3985c12..f356a97 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -1,6 +1,7 @@ use crate::{config, details::Details, error::Error, store::Identifier}; use futures_util::Stream; use std::fmt::Debug; +use std::path::PathBuf; use tracing::debug; use uuid::Uuid; @@ -210,12 +211,12 @@ impl Repo { } #[tracing::instrument(skip_all)] - pub(crate) async fn from_db(&self, db: ::sled::Db) -> color_eyre::Result<()> { + pub(crate) async fn from_db(&self, path: PathBuf) -> color_eyre::Result<()> { if self.has_migrated().await? { return Ok(()); } - let old = self::old::Old::open(db)?; + let old = self::old::Old::open(path)?; for hash in old.hashes() { match self { diff --git a/src/repo/old.rs b/src/repo/old.rs index e6a3ac2..c555a17 100644 --- a/src/repo/old.rs +++ b/src/repo/old.rs @@ -20,6 +20,8 @@ use super::{Alias, DeleteToken, Details}; use std::path::PathBuf; +mod migrate; + #[derive(Debug)] struct OldDbError(&'static str); @@ -42,7 +44,9 @@ pub(super) struct Old { } impl Old { - pub(super) fn open(db: sled::Db) -> color_eyre::Result { + pub(super) fn open(path: PathBuf) -> color_eyre::Result { + let db = migrate::LatestDb::exists(path).migrate()?; + Ok(Self { alias_tree: db.open_tree("alias")?, filename_tree: db.open_tree("filename")?, diff --git a/src/migrate.rs b/src/repo/old/migrate.rs similarity index 100% rename from src/migrate.rs rename to src/repo/old/migrate.rs diff --git a/src/migrate/s034.rs b/src/repo/old/migrate/s034.rs similarity index 97% rename from src/migrate/s034.rs rename to src/repo/old/migrate/s034.rs index fde33a2..16340ed 100644 --- a/src/migrate/s034.rs +++ b/src/repo/old/migrate/s034.rs @@ -1,6 +1,6 @@ use crate::{ error::Error, - migrate::{SledDb, SledIter, SledTree}, + repo::old::migrate::{SledDb, SledIter, SledTree}, }; use sled as sled034; use std::path::PathBuf;