25 lines
731 B
Rust
25 lines
731 B
Rust
use sqlx::postgres::PgPoolOptions;
|
|
|
|
pub mod connection_settings {
|
|
pub const MAXCONN: u32 = 10;
|
|
}
|
|
|
|
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
|
let database_url = textsender_models::envy::environment::get_db_url().await.value;
|
|
println!("Database url: {database_url}");
|
|
|
|
PgPoolOptions::new()
|
|
.max_connections(connection_settings::MAXCONN)
|
|
.connect(&database_url)
|
|
.await
|
|
}
|
|
|
|
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");
|
|
}
|