From c3ee7d554edb69a9404624c612a41b120b676a2c Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Mon, 3 Mar 2025 11:25:20 +0100 Subject: [PATCH] add PG_SCHEMA support --- backend/windmill-common/src/db.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/windmill-common/src/db.rs b/backend/windmill-common/src/db.rs index a669c36173..96be430e73 100644 --- a/backend/windmill-common/src/db.rs +++ b/backend/windmill-common/src/db.rs @@ -59,6 +59,10 @@ impl Authable for Authed { } } +lazy_static::lazy_static! { + pub static ref PG_SCHEMA: Option = 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()