App / src /db.rs
Devang Makwana
Deploy Rust backend to Hugging Face Spaces with LFS
c71a680
Raw
History Blame Contribute Delete
607 Bytes
use sqlx::postgres::PgPoolOptions;
use sqlx::PgPool;
use tracing::info;
pub async fn init_pool(database_url: &str) -> PgPool {
info!("Connecting to database...");
let pool = PgPoolOptions::new()
.max_connections(20)
.connect(database_url)
.await
.expect("Failed to connect to PostgreSQL");
info!("Database connected");
pool
}
pub async fn run_migrations(pool: &PgPool) {
info!("Running migrations...");
sqlx::migrate!("./migrations")
.run(pool)
.await
.expect("Failed to run migrations");
info!("Migrations complete");
}