Moved code for db stuff
Some checks failed
Rust Build / Check (pull_request) Successful in 45s
Rust Build / Test Suite (pull_request) Failing after 53s
Rust Build / Rustfmt (pull_request) Successful in 30s
Rust Build / Clippy (pull_request) Successful in 41s
Rust Build / build (pull_request) Successful in 1m5s

This commit is contained in:
2025-04-06 18:45:17 -04:00
parent db3f083810
commit 98d58b9906
2 changed files with 13 additions and 16 deletions

View File

@@ -15,7 +15,7 @@ mod connection_settings {
pub const MAXCONN: u32 = 5; pub const MAXCONN: u32 = 5;
} }
pub mod db_pool { pub mod db {
use sqlx::postgres::PgPoolOptions; use sqlx::postgres::PgPoolOptions;
use std::env; use std::env;
@@ -38,6 +38,15 @@ pub mod db_pool {
env::var(keys::DBURL).expect(keys::error::ERROR) 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 { mod token_stuff {

View File

@@ -14,17 +14,6 @@ async fn main() {
axum::serve(listener, app).await.unwrap(); 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 { mod init {
use axum::{ use axum::{
Router, Router,
@@ -32,7 +21,6 @@ mod init {
}; };
use crate::callers; use crate::callers;
use crate::db;
pub async fn routes() -> Router { pub async fn routes() -> Router {
// build our application with a route // build our application with a route
@@ -46,11 +34,11 @@ mod init {
} }
pub async fn app() -> Router { pub async fn app() -> Router {
let pool = icarus_auth::db_pool::create_pool() let pool = icarus_auth::db::create_pool()
.await .await
.expect("Failed to create pool"); .expect("Failed to create pool");
db::migrations(&pool).await; icarus_auth::db::migrations(&pool).await;
routes().await.layer(axum::Extension(pool)) routes().await.layer(axum::Extension(pool))
} }
@@ -180,7 +168,7 @@ mod tests {
let pool = db_mgr::connect_to_db(&db_name).await.unwrap(); 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)); let app = init::routes().await.layer(axum::Extension(pool));