Run database migrations on application start
This commit is contained in:
parent
47b45fd40f
commit
8905d05b01
|
|
@ -6,6 +6,7 @@ use axum::{
|
||||||
use http::{Request, StatusCode};
|
use http::{Request, StatusCode};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::{prelude::FromRow, sqlite::SqlitePoolOptions, SqlitePool};
|
use sqlx::{prelude::FromRow, sqlite::SqlitePoolOptions, SqlitePool};
|
||||||
|
use sqlx::migrate::Migrator;
|
||||||
use tower_http::services::ServeDir;
|
use tower_http::services::ServeDir;
|
||||||
|
|
||||||
mod error_handling;
|
mod error_handling;
|
||||||
|
|
@ -78,6 +79,13 @@ async fn main() {
|
||||||
|
|
||||||
let app_state = AppState {db_pool: db_pool.expect("Failed to get db_pool") };
|
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;
|
let user_data: Option<UserData> = None;
|
||||||
|
|
||||||
// build our application with some routes
|
// build our application with some routes
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue