From aebd01540cc09724f68366709281d2350f758f8c Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Sat, 26 Oct 2024 20:53:10 +0200 Subject: Feat: Add initial tables --- src/main.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 335649c..d99fbe9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,12 @@ +use std::env; + use axum::extract::DefaultBodyLimit; use axum::http::StatusCode; use axum::response::IntoResponse; use axum::routing::get; use axum::Router; use maud::{html, Markup, DOCTYPE}; +use sqlx::sqlite::SqlitePoolOptions; use tower_http::services::ServeDir; struct AppError(anyhow::Error); @@ -29,6 +32,18 @@ where #[tokio::main] async fn main() { + let pool = SqlitePoolOptions::new() + .connect( + &env::var("DATABASE_URL").expect("Failed to get environment variable DATABASE_URL"), + ) + .await + .expect("Failed to connect to database"); + + sqlx::migrate!() + .run(&pool) + .await + .expect("Failed to run migrations"); + let app = Router::new() .route("/", get(home)) .nest_service("/static", ServeDir::new("src/static")) -- cgit v1.2.3