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
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:
11
src/lib.rs
11
src/lib.rs
@@ -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 {
|
||||||
|
18
src/main.rs
18
src/main.rs
@@ -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));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user