forklaunch 1.33.0

Launch faster with forklaunch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! PostgreSQL connection and schema migration for the IAM stores.
use crate::{domain::services::PostgresIamService, error::Result};
use sqlx::{PgPool, postgres::PgPoolOptions};
use forklaunch_core::config;

/// Connect with the restricted runtime role; privileged roles are rejected by the stores.
pub async fn connect() -> Result<PgPool> {
    let url: String = config::required("DATABASE_URL")?;
    Ok(PgPoolOptions::new().max_connections(10).connect(&url).await.map_err(|_| "Unable to connect to PostgreSQL")?)
}

/// Apply migrations with a schema-owner `DATABASE_URL`.
pub async fn migrate() -> Result<()> {
    let pool = connect().await?;
    PostgresIamService::migrate(&pool).await?;
    pool.close().await;
    Ok(())
}