Login endpoint #20

Merged
phoenix merged 24 commits from login_endpoint into devel 2025-04-07 01:22:59 +00:00
2 changed files with 13 additions and 16 deletions
Showing only changes of commit 98d58b9906 - Show all commits

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));