mirror of
https://github.com/flibusta-apps/users_settings_server.git
synced 2026-03-03 15:10:51 +01:00
Run SQLx migrations on startup
This commit is contained in:
15
src/db.rs
15
src/db.rs
@@ -1,6 +1,7 @@
|
||||
use crate::config::CONFIG;
|
||||
|
||||
use sqlx::{postgres::PgPoolOptions, PgPool};
|
||||
use tracing::info;
|
||||
|
||||
pub async fn get_postgres_pool() -> PgPool {
|
||||
let database_url: String = format!(
|
||||
@@ -12,10 +13,20 @@ pub async fn get_postgres_pool() -> PgPool {
|
||||
CONFIG.postgres_db
|
||||
);
|
||||
|
||||
PgPoolOptions::new()
|
||||
let pool = PgPoolOptions::new()
|
||||
.max_connections(10)
|
||||
.acquire_timeout(std::time::Duration::from_secs(300))
|
||||
.connect(&database_url)
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
// Run migrations
|
||||
info!("Running database migrations...");
|
||||
sqlx::migrate!("./migrations")
|
||||
.run(&pool)
|
||||
.await
|
||||
.expect("Failed to run migrations");
|
||||
info!("Database migrations completed successfully");
|
||||
|
||||
pool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user