Skip to content

Commit

Permalink
Make lantern_extras prefix reserved in pgrx
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngalstyan4 committed Oct 15, 2024
1 parent f8dbba5 commit a602574
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lantern_extras/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ pub unsafe extern "C" fn _PG_init() {
.set_restart_time(Some(Duration::from_secs(5)))
.enable_spi_access()
.load();
unsafe {
use pg_sys::AsPgCStr;
pg_sys::MarkGUCPrefixReserved("lantern_extras".as_pg_cstr());
}

GucRegistry::define_string_guc(
"lantern_extras.openai_token",
Expand Down Expand Up @@ -136,3 +140,21 @@ pub mod pg_test {
]
}
}

#[cfg(any(test, feature = "pg_test"))]
#[pg_schema]
pub mod tests {
use crate::*;

// note: this will not get to unwrap, since the failure in the result only represents
// failures in the SPI machinery.
// Postgres aborts the transaction and returns an error message to the client when the SPI
// query fails. So, the rust interface as no Error representation for a failed query.
// As a last resort we can ensure the test panics with the expected message.
// https://www.postgresql.org/docs/current/spi.html
#[pg_test]
#[should_panic(expected = "invalid configuration parameter name")]
fn lantern_extras_prefix_reserved() {
let res = Spi::run("SET lantern_extras.aldkjalsdkj_invalid_param = 42").unwrap();
}
}

0 comments on commit a602574

Please sign in to comment.