From 8905d05b01b6db731f1d4ec956fbf0e3f18e8e36 Mon Sep 17 00:00:00 2001 From: Chris Jean-Marie Date: Fri, 27 Sep 2024 13:11:49 +0000 Subject: [PATCH] Run database migrations on application start --- backend/src/main.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/src/main.rs b/backend/src/main.rs index babaf7e..663041e 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -6,6 +6,7 @@ use axum::{ use http::{Request, StatusCode}; use serde::{Deserialize, Serialize}; use sqlx::{prelude::FromRow, sqlite::SqlitePoolOptions, SqlitePool}; +use sqlx::migrate::Migrator; use tower_http::services::ServeDir; mod error_handling; @@ -78,6 +79,13 @@ async fn main() { let app_state = AppState {db_pool: db_pool.expect("Failed to get db_pool") }; + static MIGRATOR: Migrator = sqlx::migrate!(); + + MIGRATOR + .run(&app_state.db_pool) + .await + .expect("Failed to run migrations"); + let user_data: Option = None; // build our application with some routes