diff --git a/src/error.rs b/src/error.rs index 71e334b..008bb95 100644 --- a/src/error.rs +++ b/src/error.rs @@ -40,6 +40,15 @@ impl Error { } } +impl From for Error { + fn from(source: std::io::Error) -> Self { + Self { + code: ErrorCode::Internal, + message: source.to_string(), + } + } +} + impl From<&str> for Error { fn from(s: &str) -> Self { Error { diff --git a/src/main.rs b/src/main.rs index 1dd2fea..afaf998 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use std::path::Path; + use actix_web::{get, web, App, HttpResponse, HttpServer}; use rust_embed::RustEmbed; use sea_orm::{Database, DatabaseConnection}; @@ -71,6 +73,12 @@ async fn dist(path: web::Path) -> HttpResponse { #[instrument] async fn setup_database() -> error::Result { + let db_fname = "data.db"; + + if !Path::new(db_fname).exists() { + std::fs::File::create(db_fname)?; + } + let pool = sqlx::SqlitePool::connect("sqlite://data.db").await?; sqlx::migrate!("./migrations").run(&pool).await?; tracing::info!("Database migrated");