feat: propagate origin and trigger to cdc and changes

This commit is contained in:
2026-06-05 18:48:46 -04:00
parent 4cc5245336
commit 8c430d42e3
5 changed files with 88 additions and 2 deletions

View File

@ -85,6 +85,14 @@ impl DatabaseExecutor for MockExecutor {
Ok("2026-03-10T00:00:00Z".to_string())
}
fn auth_origin(&self) -> Result<Option<Value>, String> {
Ok(None)
}
fn punc_trigger(&self) -> Result<Option<String>, String> {
Ok(None)
}
#[cfg(test)]
fn get_queries(&self) -> Vec<String> {
MOCK_STATE.with(|state| state.borrow().captured_queries.clone())

View File

@ -20,6 +20,12 @@ pub trait DatabaseExecutor: Send + Sync {
/// Returns the current transaction timestamp
fn timestamp(&self) -> Result<String, String>;
/// Returns the current auth.origin session context if configured
fn auth_origin(&self) -> Result<Option<Value>, String>;
/// Returns the current punc.name session context if configured
fn punc_trigger(&self) -> Result<Option<String>, String>;
#[cfg(test)]
fn get_queries(&self) -> Vec<String>;

View File

@ -150,4 +150,46 @@ impl DatabaseExecutor for SpiExecutor {
})
})
}
fn auth_origin(&self) -> Result<Option<Value>, String> {
self.transact(|| {
Spi::connect(|client| {
let mut tup_table = client
.select(
"SELECT NULLIF(current_setting('auth.origin', true), '')::jsonb",
None,
&[],
)
.map_err(|e| format!("SPI Select Error: {}", e))?;
if let Some(row) = tup_table.next() {
if let Ok(Some(jsonb)) = row.get::<pgrx::JsonB>(1) {
return Ok(Some(jsonb.0));
}
}
Ok(None)
})
})
}
fn punc_trigger(&self) -> Result<Option<String>, String> {
self.transact(|| {
Spi::connect(|client| {
let mut tup_table = client
.select(
"SELECT NULLIF(current_setting('punc.name', true), '')",
None,
&[],
)
.map_err(|e| format!("SPI Select Error: {}", e))?;
if let Some(row) = tup_table.next() {
if let Ok(val_opt) = row.get::<String>(1) {
return Ok(val_opt);
}
}
Ok(None)
})
})
}
}

View File

@ -206,6 +206,16 @@ impl Database {
self.executor.timestamp()
}
/// Returns the current auth.origin session context if configured
pub fn auth_origin(&self) -> Result<Option<Value>, String> {
self.executor.auth_origin()
}
/// Returns the current punc.name session context if configured
pub fn punc_trigger(&self) -> Result<Option<String>, String> {
self.executor.punc_trigger()
}
pub fn compile(&mut self, errors: &mut Vec<crate::drop::Error>) {
// Phase 1: Registration
self.collect_schemas(errors);