about summary refs log tree commit diff stats
path: root/crates/yt/src/storage/migrate/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/yt/src/storage/migrate/mod.rs')
-rw-r--r--crates/yt/src/storage/migrate/mod.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/crates/yt/src/storage/migrate/mod.rs b/crates/yt/src/storage/migrate/mod.rs
index 953d079..4fa39ab 100644
--- a/crates/yt/src/storage/migrate/mod.rs
+++ b/crates/yt/src/storage/migrate/mod.rs
@@ -75,7 +75,7 @@ macro_rules! make_upgrade {
 }
 
 #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
-pub enum DbVersion {
+pub(crate) enum DbVersion {
     /// The database is not yet initialized.
     Empty,
 
@@ -222,9 +222,10 @@ fn get_current_date() -> i64 {
 ///
 /// # Panics
 /// Only if internal assertions fail.
-pub async fn get_version(app: &App) -> Result<DbVersion> {
+pub(crate) async fn get_version(app: &App) -> Result<DbVersion> {
     get_version_db(&app.database).await
 }
+
 /// Return the current database version.
 ///
 /// In contrast to the [`get_version`] function, this function does not
@@ -232,13 +233,19 @@ pub async fn get_version(app: &App) -> Result<DbVersion> {
 ///
 /// # Panics
 /// Only if internal assertions fail.
-pub async fn get_version_db(pool: &SqlitePool) -> Result<DbVersion> {
+pub(crate) async fn get_version_db(pool: &SqlitePool) -> Result<DbVersion> {
     let version_table_exists = {
         let query = query!(
-            "SELECT 1 as result FROM sqlite_master WHERE type = 'table' AND name = 'version'"
+            "
+            SELECT 1 as result
+            FROM sqlite_master
+            WHERE type = 'table'
+            AND name = 'version'
+            "
         )
         .fetch_optional(pool)
         .await?;
+
         if let Some(output) = query {
             assert_eq!(output.result, 1);
             true
@@ -246,13 +253,16 @@ pub async fn get_version_db(pool: &SqlitePool) -> Result<DbVersion> {
             false
         }
     };
+
     if !version_table_exists {
         return Ok(DbVersion::Empty);
     }
 
     let current_version = query!(
         "
-        SELECT namespace, number FROM version WHERE valid_to IS NULL;
+        SELECT namespace, number
+        FROM version
+        WHERE valid_to IS NULL;
         "
     )
     .fetch_one(pool)
@@ -262,7 +272,7 @@ pub async fn get_version_db(pool: &SqlitePool) -> Result<DbVersion> {
     DbVersion::from_db(current_version.number, current_version.namespace.as_str())
 }
 
-pub async fn migrate_db(app: &App) -> Result<()> {
+pub(crate) async fn migrate_db(app: &App) -> Result<()> {
     let current_version = get_version(app)
         .await
         .context("Failed to determine initial version")?;