feat: propagate origin and trigger to cdc and changes
This commit is contained in:
@ -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())
|
||||
|
||||
@ -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>;
|
||||
|
||||
|
||||
@ -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)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user