From d2c3433df341705d06eb3bf14f8fbe252a2b0471 Mon Sep 17 00:00:00 2001 From: fan-tastic-z Date: Thu, 30 May 2024 10:09:54 +0800 Subject: [PATCH] feat: support db migration --- src/app.rs | 6 ++++++ src/main.rs | 1 + 2 files changed, 7 insertions(+) diff --git a/src/app.rs b/src/app.rs index 153c755..4f3cdcf 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,4 +1,5 @@ use lazy_static::lazy_static; +use migration::MigratorTrait; use sea_orm::DatabaseConnection; use std::{collections::HashMap, sync::Arc, time::Duration}; use tokio::{task::JoinSet, time}; @@ -179,6 +180,11 @@ impl WatchVulnApp { } is_push } + + pub async fn run_migration(&self) -> Result<()> { + migration::Migrator::up(&self.app_context.db, None).await?; + Ok(()) + } } #[derive(Clone)] diff --git a/src/main.rs b/src/main.rs index 9f9b7cc..9bc65d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ async fn main() -> Result<()> { let app_context = Arc::new(create_context(&environment).await?); logger::init(&app_context.config.logger); let app = WatchVulnApp::new(app_context); + app.run_migration().await?; app.run().await?; Ok(()) }