Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
postgresql-server-dev-15
sudo chmod a+rwx `/usr/lib/postgresql/15/bin/pg_config --pkglibdir` `/usr/lib/postgresql/15/bin/pg_config --sharedir`/extension /var/run/postgresql/

- run: cargo install cargo-pgrx --version 0.12.7
- run: cargo install cargo-pgrx --version 0.12.9
- run: cargo pgrx init --pg15 /usr/lib/postgresql/15/bin/pg_config

- name: Generate code coverage
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
extension_name:
- wrappers
pgrx_version:
- 0.12.7
- 0.12.9
postgres: [14, 15, 16, 17]
features:
- "all_fdws"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_supabase_wrappers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
postgresql-server-dev-15
sudo chmod a+rwx `/usr/lib/postgresql/15/bin/pg_config --pkglibdir` `/usr/lib/postgresql/15/bin/pg_config --sharedir`/extension /var/run/postgresql/

- run: cargo install cargo-pgrx --version 0.12.7
- run: cargo install cargo-pgrx --version 0.12.9
- run: cargo pgrx init --pg15 /usr/lib/postgresql/15/bin/pg_config

- name: Format code
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_wrappers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
postgresql-server-dev-15
sudo chmod a+rwx `/usr/lib/postgresql/15/bin/pg_config --pkglibdir` `/usr/lib/postgresql/15/bin/pg_config --sharedir`/extension /var/run/postgresql/

- run: cargo install cargo-pgrx --version 0.12.7
- run: cargo install cargo-pgrx --version 0.12.9
- run: cargo pgrx init --pg15 /usr/lib/postgresql/15/bin/pg_config

- name: Format code
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
postgresql-server-dev-15
sudo chmod a+rwx `/usr/lib/postgresql/15/bin/pg_config --pkglibdir` `/usr/lib/postgresql/15/bin/pg_config --sharedir`/extension /var/run/postgresql/

- run: cargo install cargo-pgrx --version 0.12.7
- run: cargo install cargo-pgrx --version 0.12.9
- run: cargo pgrx init --pg15 /usr/lib/postgresql/15/bin/pg_config
- run: cargo install cargo-component --version 0.13.2
- run: rustup target add wasm32-unknown-unknown
Expand Down
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions supabase-wrappers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ repository = "https://github.com/supabase/wrappers/tree/main/supabase-wrappers"
categories = ["database"]
keywords = ["database", "postgres", "postgresql", "extension"]

[lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(pgrx_embed)'] }

[features]
default = ["cshim", "pg15"]
cshim = ["pgrx/cshim"]
default = ["pg15"]
pg12 = ["pgrx/pg12", "pgrx-tests/pg12"]
pg13 = ["pgrx/pg13", "pgrx-tests/pg13"]
pg14 = ["pgrx/pg14", "pgrx-tests/pg14"]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15"]
Expand All @@ -21,17 +24,17 @@ pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
pg_test = []

[dependencies]
pgrx = { version = "=0.12.7", default-features = false }
pgrx = { version = "=0.12.9", default-features = false }
thiserror = "1.0.63"
tokio = { version = "1.40", features = ["rt", "net"] }
uuid = { version = "1.10.0" }
supabase-wrappers-macros = { version = "0.1", path = "../supabase-wrappers-macros" }

[dev-dependencies]
pgrx-tests = "=0.12.7"
pgrx-tests = "=0.12.9"

[package.metadata.docs.rs]
features = ["pg15", "cshim"]
features = ["pg15"]
no-default-features = true
# Enable `#[cfg(docsrs)]` (https://docs.rs/about/builds#cross-compiling)
rustc-args = ["--cfg", "docsrs"]
47 changes: 30 additions & 17 deletions supabase-wrappers/src/import_foreign_schema.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use pg_sys::{AsPgCStr, Oid};
use pgrx::list::List;
use pgrx::pg_sys::panic::ErrorReport;
use pgrx::{debug2, prelude::*, PgList};
use pgrx::{debug2, prelude::*};
use std::ffi::c_void;
use std::marker::PhantomData;

use crate::instance;
Expand Down Expand Up @@ -81,16 +83,26 @@ pub(super) extern "C" fn import_foreign_schema<E: Into<ErrorReport>, W: ForeignD
},

table_list: {
let tables: PgList<pg_sys::RangeVar> = PgList::from_pg((*stmt).table_list);
tables
.iter_ptr()
.map(|item| {
std::ffi::CStr::from_ptr(item.as_mut().unwrap().relname)
.to_str()
.unwrap()
.to_string()
})
.collect()
pgrx::memcx::current_context(|mcx| {
let mut ret = Vec::new();

if let Some(tables) =
List::<*mut c_void>::downcast_ptr_in_memcx((*stmt).table_list, mcx)
{
ret = tables
.iter()
.map(|item| {
let rv = *item as *mut pg_sys::RangeVar;
std::ffi::CStr::from_ptr((*rv).relname)
.to_str()
.unwrap()
.to_string()
})
.collect();
}

ret
})
},

options: options_to_hashmap((*stmt).options).unwrap(),
Expand All @@ -102,10 +114,11 @@ pub(super) extern "C" fn import_foreign_schema<E: Into<ErrorReport>, W: ForeignD
.import_foreign_schema(import_foreign_schema_stmt);
}

let mut ret: PgList<std::ffi::c_char> = PgList::new();
for command in create_stmts {
ret.push(command.as_pg_cstr());
}

ret.into_pg()
pgrx::memcx::current_context(|mcx| {
let mut ret = List::<*mut c_void>::Nil;
for command in create_stmts {
ret.unstable_push_in_context(command.as_pg_cstr() as _, mcx);
}
ret.into_ptr()
})
}
46 changes: 27 additions & 19 deletions supabase-wrappers/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use pgrx::list::List;
use pgrx::pg_sys::panic::ErrorReport;
use pgrx::{pg_sys, PgList, PgSqlErrorCode};
use pgrx::{pg_sys, PgSqlErrorCode};
use std::collections::HashMap;
use std::ffi::c_void;
use std::ffi::CStr;
use thiserror::Error;

Expand Down Expand Up @@ -98,22 +100,28 @@ pub fn check_options_contain(opt_list: &[Option<String>], tgt: &str) -> Result<(
pub(super) unsafe fn options_to_hashmap(
options: *mut pg_sys::List,
) -> Result<HashMap<String, String>, OptionsError> {
let mut ret = HashMap::new();
let options: PgList<pg_sys::DefElem> = PgList::from_pg(options);
for option in options.iter_ptr() {
let name = CStr::from_ptr((*option).defname);
let value = CStr::from_ptr(pg_sys::defGetString(option));
let name = name.to_str().map_err(|_| {
OptionsError::OptionNameIsInvalidUtf8(
String::from_utf8_lossy(name.to_bytes()).to_string(),
)
})?;
let value = value.to_str().map_err(|_| {
OptionsError::OptionValueIsInvalidUtf8(
String::from_utf8_lossy(value.to_bytes()).to_string(),
)
})?;
ret.insert(name.to_string(), value.to_string());
}
Ok(ret)
pgrx::memcx::current_context(|mcx| {
let mut ret = HashMap::new();

if let Some(options) = List::<*mut c_void>::downcast_ptr_in_memcx(options, mcx) {
for option in options.iter() {
let option = *option as *mut pg_sys::DefElem;
let name = CStr::from_ptr((*option).defname);
let value = CStr::from_ptr(pg_sys::defGetString(option));
let name = name.to_str().map_err(|_| {
OptionsError::OptionNameIsInvalidUtf8(
String::from_utf8_lossy(name.to_bytes()).to_string(),
)
})?;
let value = value.to_str().map_err(|_| {
OptionsError::OptionValueIsInvalidUtf8(
String::from_utf8_lossy(value.to_bytes()).to_string(),
)
})?;
ret.insert(name.to_string(), value.to_string());
}
}

Ok(ret)
})
}
Loading
Loading