diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 25766d6..f9106b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,7 +42,7 @@ jobs: strategy: matrix: - pg-version: ['15'] + pg-version: ['17'] steps: - uses: actions/checkout@v4 @@ -95,4 +95,4 @@ jobs: uses: coverallsapp/github-action@v2.3.6 with: github-token: ${{ secrets.GITHUB_TOKEN }} - files: ./coverage.info + files: ./build-${{ matrix.pg-version }}/coverage.info diff --git a/.gitignore b/.gitignore index 8f76412..7106c66 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ test/expected/event_triggers.out *.gcda coverage.info coverage_html +test/init.conf diff --git a/Makefile b/Makefile index 90d92c6..426f08f 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,11 @@ +OS = $(shell uname -s) + +ifeq ($(OS), Linux) + DL_SUFFIX=so +else + DL_SUFFIX=dylib +endif + GREP ?= grep PG_CONFIG = pg_config @@ -25,6 +33,7 @@ SRC = $(wildcard src/*.c) OBJS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRC)) PG_VERSION = $(strip $(shell $(PG_CONFIG) --version | $(GREP) -oP '(?<=PostgreSQL )[0-9]+')) +PG_EQ15 = $(shell test $(PG_VERSION) -eq 15; echo $$?) PG_GE16 = $(shell test $(PG_VERSION) -ge 16; echo $$?) PG_GE14 = $(shell test $(PG_VERSION) -ge 14; echo $$?) SYSTEM = $(shell uname -s) @@ -47,7 +56,19 @@ EXTRA_CLEAN = $(GENERATED_OUT) PGXS := $(shell $(PG_CONFIG) --pgxs) -build: $(BUILD_DIR)/$(EXTENSION).so +build: $(BUILD_DIR)/$(EXTENSION).$(DL_SUFFIX) test/init.conf + +.PHONY: test/init.conf +test/init.conf: test/init.conf.in +ifeq ($(PG_EQ15), 0) + sed \ + -e '/<\/\?PG_EQ_15>/d' \ + $? > $@ +else + sed \ + -e '//,/<\/PG_EQ_15>/d' \ + $? > $@ +endif PG_CPPFLAGS := $(CPPFLAGS) -DTEST=1 @@ -58,7 +79,7 @@ $(BUILD_DIR)/.gitignore: $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(BUILD_DIR)/.gitignore $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ -$(BUILD_DIR)/$(EXTENSION).so: $(EXTENSION).so +$(BUILD_DIR)/$(EXTENSION).$(DL_SUFFIX): $(EXTENSION).$(DL_SUFFIX) mv $? $@ include $(PGXS) diff --git a/nix/plpgsql-check.nix b/nix/plpgsql-check.nix new file mode 100644 index 0000000..58d190c --- /dev/null +++ b/nix/plpgsql-check.nix @@ -0,0 +1,30 @@ +{ lib, stdenv, fetchFromGitHub, postgresql }: + +stdenv.mkDerivation rec { + pname = "plpgsql-check"; + version = "2.7.11"; + + src = fetchFromGitHub { + owner = "okbob"; + repo = "plpgsql_check"; + rev = "v${version}"; + hash = "sha256-vR3MvfmUP2QEAtXFpq0NCCKck3wZPD+H3QleHtyVQJs="; + }; + + buildInputs = [ postgresql ]; + + installPhase = '' + install -D -t $out *${postgresql.dlSuffix} + install -D -t $out *.sql + install -D -t $out *.control + ''; + + meta = with lib; { + description = "Linter tool for language PL/pgSQL"; + homepage = "https://github.com/okbob/plpgsql_check"; + changelog = "https://github.com/okbob/plpgsql_check/releases/tag/v${version}"; + platforms = postgresql.meta.platforms; + license = licenses.mit; + maintainers = [ maintainers.marsam ]; + }; +} diff --git a/nix/xpg.nix b/nix/xpg.nix index 3b3d8d4..6c81cd9 100644 --- a/nix/xpg.nix +++ b/nix/xpg.nix @@ -3,9 +3,9 @@ let dep = fetchFromGitHub { owner = "steve-chavez"; repo = "xpg"; - rev = "v1.2"; - sha256 = "sha256-7sP+exW5CSh8c9NW4f8yr4bLcN5hJDxU5eWa8PjoNZA="; + rev = "v1.3.0"; + sha256 = "sha256-jDELiBbnCpRXIpod7msnhMfGcrW0pR3snDQ5T81nO0I="; }; - xpg = (import dep).xpg; + xpg = import dep; in xpg diff --git a/shell.nix b/shell.nix index 7de5dcf..4181182 100644 --- a/shell.nix +++ b/shell.nix @@ -4,7 +4,14 @@ with import (builtins.fetchTarball { sha256 = "sha256:1lr1h35prqkd1mkmzriwlpvxcb34kmhc9dnr48gkm8hh089hifmx"; }) {}; mkShell { - buildInputs = [ - (callPackage ./nix/xpg.nix {inherit fetchFromGitHub;}) - ]; + buildInputs = + let + xpg = callPackage ./nix/xpg.nix {}; + pgsqlcheck15 = callPackage ./nix/plpgsql-check.nix { + postgresql = xpg.postgresql_15; + }; + in + [ + (xpg.xpgWithExtensions { exts15 = [ pgsqlcheck15 ]; }) + ]; } diff --git a/src/event_triggers.c b/src/event_triggers.c index e3ef62a..11225b1 100644 --- a/src/event_triggers.c +++ b/src/event_triggers.c @@ -8,7 +8,7 @@ void force_noop(FmgrInfo *finfo) { finfo->fn_addr = (PGFunction) noop; - finfo->fn_oid = InvalidOid; /* not a known function OID anymore */ + finfo->fn_oid = 38; /* put the int2in oid which is sure to exist, this avoids cache lookup errors. See https://github.com/supabase/supautils/pull/129*/ finfo->fn_nargs = 0; /* no arguments for noop */ finfo->fn_strict = false; finfo->fn_retset = false; diff --git a/test/init.conf b/test/init.conf.in similarity index 92% rename from test/init.conf rename to test/init.conf.in index 0fac0a4..1dde758 100644 --- a/test/init.conf +++ b/test/init.conf.in @@ -1,4 +1,7 @@ -shared_preload_libraries='supautils' + +shared_preload_libraries='plpgsql_check' + +session_preload_libraries = 'supautils' wal_level=logical supautils.reserved_roles='supabase_storage_admin, anon, reserved_but_not_yet_created, authenticator*'