From 23d272e50361c19df039481d33d5a3d5fc9a0108 Mon Sep 17 00:00:00 2001 From: MikeMoolenaar Date: Thu, 8 Feb 2024 20:39:17 +0100 Subject: [PATCH] Run migration in main function --- Dockerfile | 2 +- README.md | 3 +-- src/main.rs | 7 ++++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3f1366e..7f3337b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ COPY --from=planner /app/recipe.json recipe.json # Build dependencies - this is the caching Docker layer! RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json -RUN cargo install sqlx-cli +# RUN cargo install sqlx-cli # Build application diff --git a/README.md b/README.md index f0e61d2..d4c494f 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,9 @@ npm run tailwind - [x] Use the correct http status codes in login and register - [x] Add inline email validaton https://hypermedia.systems/hypermedia-systems/#_debouncing_our_validation_requests - [x] Refactor into separate files for each route -- [ ] Improve code for render_html.rs +- [x] Improve code for render_html.rs - [ ] Setup build via GH actions - [ ] Rename to RATH stack, Rust Actix Turso Hhtmx (SQLx doesn't support Turso yet.... such a shame) -- [ ] use https://github.com/wilsonzlin/minify-html in a middleware: https://docs.rs/axum/latest/axum/middleware/fn.from_fn.html ## Handy commands diff --git a/src/main.rs b/src/main.rs index 92f7f20..9de6c27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,8 @@ use crate::{filters::*, render_html::SHARED_JINJA_ENV, routes::error_404::*}; use axum::{ body::Body, - http::{header, HeaderValue, Request}, Router, + http::{header, HeaderValue, Request}, + Router, }; use dotenv::dotenv; use minijinja::{path_loader, Environment}; @@ -42,6 +43,10 @@ async fn main() { .connect(&db_url) .await .expect("Could not connect to database"); + sqlx::migrate!("./migrations") + .run(&db_pool.clone()) + .await + .expect("Could not run migrations"); let session_store = PostgresStore::new(db_pool.clone()); session_store.migrate().await.expect("Could not migrate session store");