Run database migrations on application start

This commit is contained in:
Chris Jean-Marie 2024-09-27 13:11:49 +00:00
parent 47b45fd40f
commit 8905d05b01
1 changed files with 8 additions and 0 deletions

View File

@ -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<UserData> = None;
// build our application with some routes