add PG_SCHEMA support

This commit is contained in:
Ruben Fiszel
2025-03-03 11:25:20 +01:00
parent 40d4a4cf54
commit c3ee7d554e
+10
View File
@@ -59,6 +59,10 @@ impl Authable for Authed {
}
}
lazy_static::lazy_static! {
pub static ref PG_SCHEMA: Option<String> = std::env::var("PG_SCHEMA").ok();
}
impl UserDB {
pub fn new(db: DB) -> Self {
Self { db }
@@ -95,6 +99,12 @@ impl UserDB {
.execute(&mut *tx)
.await?;
if let Some(schema) = PG_SCHEMA.as_ref() {
sqlx::query(&format!("SET LOCAL search_path TO {}", schema))
.execute(&mut *tx)
.await?;
}
sqlx::query!(
"SELECT set_config('session.user', $1, true)",
authed.username()