diff --git a/.github/workflows/extension_ci.yml b/.github/workflows/extension_ci.yml index a4da7f1..3c25d6a 100644 --- a/.github/workflows/extension_ci.yml +++ b/.github/workflows/extension_ci.yml @@ -83,7 +83,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - pg-version: [14, 15, 16] + pg-version: [14, 15, 16, 17] steps: - uses: actions/checkout@v2 - name: Install Rust stable toolchain diff --git a/Cargo.toml b/Cargo.toml index 92eee4a..445c978 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "clerk_fdw" -version = "0.3.2" +version = "0.3.3" edition = "2021" publish = false @@ -8,21 +8,22 @@ publish = false crate-type = ["cdylib"] [features] -default = ["pg16"] +default = ["pg17"] pg14 = ["pgrx/pg14", "pgrx-tests/pg14", "supabase-wrappers/pg14"] pg15 = ["pgrx/pg15", "pgrx-tests/pg15", "supabase-wrappers/pg15"] pg16 = ["pgrx/pg16", "pgrx-tests/pg16", "supabase-wrappers/pg16"] +pg17 = ["pgrx/pg17", "pgrx-tests/pg17", "supabase-wrappers/pg17"] pg_test = [] [dependencies] backoff = { version = "0.4.0", features = ["tokio"] } -chrono = "0.4.26" -clerk-rs = "0.3.0" -pgrx = "=0.11.3" +chrono = "0.4.38" +clerk-rs = "0.4.0" +pgrx = "=0.12.6" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -supabase-wrappers = { git = "https://github.com/supabase/wrappers.git", default-features = false } +supabase-wrappers = { version = "0.1.20", default-features = false } tokio = { version = "1", features = ["full"] } [dev-dependencies] -pgrx-tests = "=0.11.3" +pgrx-tests = "=0.12.6" diff --git a/Makefile b/Makefile index e8a8f52..2ea4ce8 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,54 @@ -PGRX_POSTGRES ?= pg16 -DISTNAME = $(shell grep -m 1 '^name' Trunk.toml | sed -e 's/[^"]*"\([^"]*\)",\{0,1\}/\1/') +PG_CONFIG ?= $(shell which pg_config) +PGRXV = $(shell perl -nE '/^pgrx\s+=\s"=?([^"]+)/ && do { say $$1; exit }' Cargo.toml) +PGV = $(shell perl -E 'shift =~ /(\d+)/ && say $$1' "$(shell $(PG_CONFIG) --version)") +DISTNAME = $(shell grep -m 1 '^name' Trunk.toml | sed -e 's/[^"]*"\([^"]*\)",\{0,1\}/\1/') DISTVERSION = $(shell grep -m 1 '^version' Trunk.toml | sed -e 's/[^"]*"\([^"]*\)",\{0,1\}/\1/') +all: package + +.DEFAULT_GOAL: package # Build for the PostgreSQL cluster identified by pg_config. +package: + @cargo pgrx package --pg-config "$(PG_CONFIG)" + +.PHONY: install # Install jsonschema into the PostgreSQL cluster identified by pg_config. +install: + @cargo pgrx install --release --pg-config "$(PG_CONFIG)" + +.PHONY: test # Run the full test suite against the PostgreSQL version identified by pg_config. +test: + @cargo test --all --no-default-features --features "pg$(PGV) pg_test" -- --nocapture + +clean: + @rm -rf META.json $(DISTNAME)-$(DISTVERSION).zip + +.PHONY: pg-version # Print the current PGRX version from Cargo.toml +pgrx-version: + @echo $(PGRXV) + +.PHONY: pg-version # Print the current Postgres version reported by pg_config. +pg-version: Cargo.toml + @echo $(PGV) + +.PHONY: install-pgrx # Install the version of PGRX specified in Cargo.toml. +install-pgrx: Cargo.toml + @cargo install --locked cargo-pgrx --version "$(PGRXV)" + +.PHONY: pgrx-init # Initialize pgrx for the PostgreSQL version identified by pg_config. +pgrx-init: Cargo.toml + @cargo pgrx init "--pg$(PGV)"="$(PG_CONFIG)" + +.PHONY: lint # Format and lint. +lint: + @cargo fmt --all --check + @cargo clippy --features "pg$(PGV)" --no-default-features + +# Create the PGXN META.json file. META.json: META.json.in Cargo.toml @sed "s/@CARGO_VERSION@/$(DISTVERSION)/g" $< > $@ +# Create a PGXN-compatible zip file. $(DISTNAME)-$(DISTVERSION).zip: META.json git archive --format zip --prefix $(DISTNAME)-$(DISTVERSION)/ --add-file $< -o $(DISTNAME)-$(DISTVERSION).zip HEAD +## pgxn-zip: Create a PGXN-compatible zip file. pgxn-zip: $(DISTNAME)-$(DISTVERSION).zip - -clean: - @rm -rf META.json $(DISTNAME)-$(DISTVERSION).zip \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index e2b1f85..263f5bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -184,8 +184,8 @@ impl From for ErrorReport { type ClerkFdwResult = Result; impl ForeignDataWrapper for ClerkFdw { - fn new(options: &HashMap) -> ClerkFdwResult { - let token = if let Some(access_token) = options.get("api_key") { + fn new(server: supabase_wrappers::prelude::ForeignServer) -> ClerkFdwResult { + let token = if let Some(access_token) = server.options.get("api_key") { access_token.to_owned() } else { warning!("Cannot find api_key in options"); @@ -224,11 +224,11 @@ impl ForeignDataWrapper for ClerkFdw { let run = self.rt.block_on(async { if obj == "organization_memberships" { // Get all organizations first - let mut offset: f32 = 0.0; + let mut offset: u64 = 0; loop { let org_resp = Organization::list_organizations( &self.clerk_client, - Some(PAGE_SIZE as f32), + Some(PAGE_SIZE as u64), Some(offset), None, None, @@ -244,7 +244,7 @@ impl ForeignDataWrapper for ClerkFdw { OrganizationMembership::list_organization_memberships( &self.clerk_client, &org.id, - Some(PAGE_SIZE as f32), + Some(PAGE_SIZE as u64), None, ) .await @@ -287,7 +287,7 @@ impl ForeignDataWrapper for ClerkFdw { info!("clerk_fdw: finished fetching all memberships, total={}", result.len()); break; } else { - offset += PAGE_SIZE as f32; + offset += PAGE_SIZE as u64; info!("clerk_fdw: fetching more organizations, offset={}", offset); } } else { @@ -310,8 +310,8 @@ impl ForeignDataWrapper for ClerkFdw { None, None, None, - Some(PAGE_SIZE as f32), - Some(offset as f32), + Some(PAGE_SIZE as u64), + Some(offset as u64), None, ) .await @@ -327,8 +327,8 @@ impl ForeignDataWrapper for ClerkFdw { "organizations" => { match Organization::list_organizations( &self.clerk_client, - Some(PAGE_SIZE as f32), - Some(offset as f32), + Some(PAGE_SIZE as u64), + Some(offset as u64), None, None, )