From 98d58b99062d48e7007f59fb894466c730379a81 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 6 Apr 2025 18:45:17 -0400 Subject: [PATCH] Moved code for db stuff --- src/lib.rs | 11 ++++++++++- src/main.rs | 18 +++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ea7dde2..67b590b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,7 @@ mod connection_settings { pub const MAXCONN: u32 = 5; } -pub mod db_pool { +pub mod db { use sqlx::postgres::PgPoolOptions; use std::env; @@ -38,6 +38,15 @@ pub mod db_pool { env::var(keys::DBURL).expect(keys::error::ERROR) } + + pub async fn migrations(pool: &sqlx::PgPool) { + // Run migrations using the sqlx::migrate! macro + // Assumes your migrations are in a ./migrations folder relative to Cargo.toml + sqlx::migrate!("./migrations") + .run(pool) + .await + .expect("Failed to run migrations on testcontainer DB"); + } } mod token_stuff { diff --git a/src/main.rs b/src/main.rs index da52960..c9c136c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,17 +14,6 @@ async fn main() { axum::serve(listener, app).await.unwrap(); } -mod db { - pub async fn migrations(pool: &sqlx::PgPool) { - // Run migrations using the sqlx::migrate! macro - // Assumes your migrations are in a ./migrations folder relative to Cargo.toml - sqlx::migrate!("./migrations") - .run(pool) - .await - .expect("Failed to run migrations on testcontainer DB"); - } -} - mod init { use axum::{ Router, @@ -32,7 +21,6 @@ mod init { }; use crate::callers; - use crate::db; pub async fn routes() -> Router { // build our application with a route @@ -46,11 +34,11 @@ mod init { } pub async fn app() -> Router { - let pool = icarus_auth::db_pool::create_pool() + let pool = icarus_auth::db::create_pool() .await .expect("Failed to create pool"); - db::migrations(&pool).await; + icarus_auth::db::migrations(&pool).await; routes().await.layer(axum::Extension(pool)) } @@ -180,7 +168,7 @@ mod tests { let pool = db_mgr::connect_to_db(&db_name).await.unwrap(); - db::migrations(&pool).await; + icarus_auth::db::migrations(&pool).await; let app = init::routes().await.layer(axum::Extension(pool));