Moved templates to be embedded in executable

This commit is contained in:
Manuel Forcén Muñoz 2024-06-03 18:39:17 +02:00
parent b676be8cb2
commit 1c1a9589b7
25 changed files with 957 additions and 256 deletions

View file

@ -1,3 +1,4 @@
use log::{error, info};
use sqlx::{migrate::MigrateDatabase, Sqlite, SqlitePool};
pub mod models;
@ -6,8 +7,11 @@ pub async fn create_db(db_url: &str) -> sqlx::Result<SqlitePool> {
if !Sqlite::database_exists(db_url).await.unwrap_or(false) {
println!("Creating database {}", db_url);
match Sqlite::create_database(db_url).await {
Ok(_) => println!("create db success"),
Err(e) => panic!("Cannot create db: {e:?}"),
Ok(_) => info!("create db success"),
Err(e) => {
error!("Cannot create db at {db_url}: {e:?}");
panic!("Cannot create db at {db_url}: {e:?}")
}
};
} else {
println!("Database already exists")