Skip to content

Commit

Permalink
Update pgrx, clerk-rs, chrono; support Postgres 17
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Dec 6, 2024
1 parent ca461aa commit 4135ddf
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/extension_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
[package]
name = "clerk_fdw"
version = "0.3.2"
version = "0.3.3"
edition = "2021"
publish = false

[lib]
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"
50 changes: 45 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
20 changes: 10 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ impl From<ClerkFdwError> for ErrorReport {
type ClerkFdwResult<T> = Result<T, ClerkFdwError>;

impl ForeignDataWrapper<ClerkFdwError> for ClerkFdw {
fn new(options: &HashMap<String, String>) -> ClerkFdwResult<Self> {
let token = if let Some(access_token) = options.get("api_key") {
fn new(server: supabase_wrappers::prelude::ForeignServer) -> ClerkFdwResult<Self> {
let token = if let Some(access_token) = server.options.get("api_key") {
access_token.to_owned()
} else {
warning!("Cannot find api_key in options");
Expand Down Expand Up @@ -224,11 +224,11 @@ impl ForeignDataWrapper<ClerkFdwError> 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,
Expand All @@ -244,7 +244,7 @@ impl ForeignDataWrapper<ClerkFdwError> for ClerkFdw {
OrganizationMembership::list_organization_memberships(
&self.clerk_client,
&org.id,
Some(PAGE_SIZE as f32),
Some(PAGE_SIZE as u64),
None,
)
.await
Expand Down Expand Up @@ -287,7 +287,7 @@ impl ForeignDataWrapper<ClerkFdwError> 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 {
Expand All @@ -310,8 +310,8 @@ impl ForeignDataWrapper<ClerkFdwError> 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
Expand All @@ -327,8 +327,8 @@ impl ForeignDataWrapper<ClerkFdwError> 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,
)
Expand Down

0 comments on commit 4135ddf

Please sign in to comment.