about summary refs log tree commit diff stats
path: root/crates/yt/src/app.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--crates/yt/src/app.rs (renamed from yt/src/app.rs)26
1 files changed, 17 insertions, 9 deletions
diff --git a/yt/src/app.rs b/crates/yt/src/app.rs
index 1f82214..15a9388 100644
--- a/yt/src/app.rs
+++ b/crates/yt/src/app.rs
@@ -1,6 +1,7 @@
 // yt - A fully featured command line YouTube client
 //
 // Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+// Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
 // SPDX-License-Identifier: GPL-3.0-or-later
 //
 // This file is part of Yt.
@@ -9,9 +10,10 @@
 // If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
 
 use anyhow::{Context, Result};
-use sqlx::{query, sqlite::SqliteConnectOptions, SqlitePool};
+use log::warn;
+use sqlx::{SqlitePool, sqlite::SqliteConnectOptions};
 
-use crate::config::Config;
+use crate::{config::Config, storage::migrate::migrate_db};
 
 #[derive(Debug)]
 pub struct App {
@@ -20,7 +22,7 @@ pub struct App {
 }
 
 impl App {
-    pub async fn new(config: Config) -> Result<Self> {
+    pub async fn new(config: Config, should_migrate_db: bool) -> Result<Self> {
         let options = SqliteConnectOptions::new()
             .filename(&config.paths.database_path)
             .optimize_on_close(true, None)
@@ -30,13 +32,19 @@ impl App {
             .await
             .context("Failed to connect to database!")?;
 
-        query(include_str!("storage/video_database/schema.sql"))
-            .execute(&pool)
-            .await?;
-
-        Ok(App {
+        let app = App {
             database: pool,
             config,
-        })
+        };
+
+        if should_migrate_db {
+            migrate_db(&app)
+                .await
+                .context("Failed to migrate db to new version")?;
+        } else {
+            warn!("Skipping database migration.");
+        }
+
+        Ok(app)
     }
 }