From 975f4144d8d0fa0439b0511e4bea1f94fc822a5c Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 15 Apr 2025 14:50:32 -0400 Subject: [PATCH 1/6] feat: multi-ext-versios-pgrcron --- nix/ext/pg_cron.nix | 128 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 109 insertions(+), 19 deletions(-) diff --git a/nix/ext/pg_cron.nix b/nix/ext/pg_cron.nix index 792db7676..7b8c00e72 100644 --- a/nix/ext/pg_cron.nix +++ b/nix/ext/pg_cron.nix @@ -1,31 +1,121 @@ { lib, stdenv, fetchFromGitHub, postgresql }: -stdenv.mkDerivation rec { - pname = "pg_cron"; - version = "1.6.4"; +let + allVersions = { + "1.3.1" = { + rev = "v1.3.1"; + hash = "sha256-rXotNOtQNmA55ErNxGoNSKZ0pP1uxEVlDGITFHuqGG4="; + postPatch = '' + # Add necessary includes + substituteInPlace src/pg_cron.c \ + --replace '#include "postgres.h"' '#include "postgres.h" + #include "commands/async.h" + #include "miscadmin.h"' - buildInputs = [ postgresql ]; + # Update function calls to use PostgreSQL 15 APIs + substituteInPlace src/pg_cron.c \ + --replace 'ProcessCompletedNotifies();' '/* ProcessCompletedNotifies removed */' \ + --replace 'pg_analyze_and_rewrite(parsetree, sql, NULL, 0,NULL);' 'pg_analyze_and_rewrite_fixedparams(parsetree, sql, NULL, 0, NULL);' + ''; + }; + "1.4.2" = { + rev = "v1.4.2"; + hash = "sha256-P0Fd10Q1p+KrExb35G6otHpc6pD61WnMll45H2jkevM="; + }; + "1.6.4" = { + rev = "v1.6.4"; + hash = "sha256-t1DpFkPiSfdoGG2NgNT7g1lkvSooZoRoUrix6cBID40="; + }; + "1.5.2" = { + rev = "v1.5.2"; + hash = "sha256-+quVWbKJy6wXpL/zwTk5FF7sYwHA7I97WhWmPO/HSZ4="; + }; + }; + + mkPgCron = pgCronVersion: { rev, hash, postPatch ? "" }: stdenv.mkDerivation { + pname = "pg_cron"; + version = "${pgCronVersion}-pg${lib.versions.major postgresql.version}"; + + buildInputs = [ postgresql ]; + inherit postPatch; + + src = fetchFromGitHub { + owner = "citusdata"; + repo = "pg_cron"; + inherit rev hash; + }; + + buildPhase = '' + make PG_CONFIG=${postgresql}/bin/pg_config + + # Create version-specific SQL file + cp pg_cron.sql pg_cron--${pgCronVersion}.sql + + # Create versioned control file with modified module path + sed -e "/^default_version =/d" \ + -e "s|^module_pathname = .*|module_pathname = '\$libdir/pg_cron'|" \ + pg_cron.control > pg_cron--${pgCronVersion}.control + ''; - src = fetchFromGitHub { - owner = "citusdata"; - repo = pname; - rev = "v${version}"; - hash = "sha256-t1DpFkPiSfdoGG2NgNT7g1lkvSooZoRoUrix6cBID40="; + installPhase = '' + mkdir -p $out/{lib,share/postgresql/extension} + + # Install versioned library + install -Dm755 pg_cron${postgresql.dlSuffix} $out/lib/pg_cron-${pgCronVersion}${postgresql.dlSuffix} + + # Install version-specific files + install -Dm644 pg_cron--${pgCronVersion}.sql $out/share/postgresql/extension/ + install -Dm644 pg_cron--${pgCronVersion}.control $out/share/postgresql/extension/ + + # Install upgrade scripts + find . -name 'pg_cron--*--*.sql' -exec install -Dm644 {} $out/share/postgresql/extension/ \; + ''; }; + getVersions = pg: + if lib.versionAtLeast pg.version "17" + then { "1.6.4" = allVersions."1.6.4"; } + else allVersions; + + allVersionsForPg = lib.mapAttrs mkPgCron (getVersions postgresql); + +in +stdenv.mkDerivation { + pname = "pg_cron-all"; + version = "multi"; + + buildInputs = lib.attrValues allVersionsForPg; + + dontUnpack = true; + dontConfigure = true; + dontBuild = true; + installPhase = '' mkdir -p $out/{lib,share/postgresql/extension} - - cp *${postgresql.dlSuffix} $out/lib - cp *.sql $out/share/postgresql/extension - cp *.control $out/share/postgresql/extension + + # Install all versions + for drv in ${lib.concatStringsSep " " (lib.attrValues allVersionsForPg)}; do + ln -sv $drv/lib/* $out/lib/ + cp -v --no-clobber $drv/share/postgresql/extension/* $out/share/postgresql/extension/ || true + done + + # Create default symlinks + latest_control=$(ls -v $out/share/postgresql/extension/pg_cron--*.control | tail -n1) + latest_version=$(basename "$latest_control" | sed -E 's/pg_cron--([0-9.]+).control/\1/') + + # Create main control file with default_version + echo "default_version = '$latest_version'" > $out/share/postgresql/extension/pg_cron.control + cat "$latest_control" >> $out/share/postgresql/extension/pg_cron.control + + # Library symlink + ln -sfnv pg_cron-$latest_version${postgresql.dlSuffix} $out/lib/pg_cron${postgresql.dlSuffix} ''; meta = with lib; { - description = "Run Cron jobs through PostgreSQL"; - homepage = "https://github.com/citusdata/pg_cron"; - changelog = "https://github.com/citusdata/pg_cron/raw/v${version}/CHANGELOG.md"; - platforms = postgresql.meta.platforms; - license = licenses.postgresql; + description = "Run Cron jobs through PostgreSQL (multi-version compatible)"; + homepage = "https://github.com/citusdata/pg_cron"; + maintainers = with maintainers; [ samrose ]; + platforms = postgresql.meta.platforms; + license = licenses.postgresql; }; -} +} \ No newline at end of file From ae0241aeacb47cfd3b25f897297b85143d03e1d4 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 15 Apr 2025 15:33:34 -0400 Subject: [PATCH 2/6] feat: add version to drv and patch instead of postPatch rewrite --- nix/ext/pg_cron-1.3.1-pg15.patch | 31 +++++++++++++++++++++++++++++++ nix/ext/pg_cron.nix | 19 ++++--------------- 2 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 nix/ext/pg_cron-1.3.1-pg15.patch diff --git a/nix/ext/pg_cron-1.3.1-pg15.patch b/nix/ext/pg_cron-1.3.1-pg15.patch new file mode 100644 index 000000000..d3b6cd702 --- /dev/null +++ b/nix/ext/pg_cron-1.3.1-pg15.patch @@ -0,0 +1,31 @@ +diff --git a/src/pg_cron.c b/src/pg_cron.c +index e0ca973..4d51b2c 100644 +--- a/src/pg_cron.c ++++ b/src/pg_cron.c +@@ -14,6 +14,8 @@ + #include + + #include "postgres.h" ++#include "commands/async.h" ++#include "miscadmin.h" + #include "fmgr.h" + + /* these are always necessary for a bgworker */ +@@ -1908,7 +1910,7 @@ CronBackgroundWorker(Datum main_arg) + /* Post-execution cleanup. */ + disable_timeout(STATEMENT_TIMEOUT, false); + CommitTransactionCommand(); +- ProcessCompletedNotifies(); ++ /* ProcessCompletedNotifies removed */ + pgstat_report_activity(STATE_IDLE, command); + pgstat_report_stat(true); + +@@ -2025,7 +2027,7 @@ ExecuteSqlString(const char *sql) + */ + oldcontext = MemoryContextSwitchTo(parsecontext); + #if PG_VERSION_NUM >= 100000 +- querytree_list = pg_analyze_and_rewrite(parsetree, sql, NULL, 0,NULL); ++ querytree_list = pg_analyze_and_rewrite_fixedparams(parsetree, sql, NULL, 0, NULL); + #else + querytree_list = pg_analyze_and_rewrite(parsetree, sql, NULL, 0); + #endif diff --git a/nix/ext/pg_cron.nix b/nix/ext/pg_cron.nix index 7b8c00e72..a59cb5ae5 100644 --- a/nix/ext/pg_cron.nix +++ b/nix/ext/pg_cron.nix @@ -5,18 +5,7 @@ let "1.3.1" = { rev = "v1.3.1"; hash = "sha256-rXotNOtQNmA55ErNxGoNSKZ0pP1uxEVlDGITFHuqGG4="; - postPatch = '' - # Add necessary includes - substituteInPlace src/pg_cron.c \ - --replace '#include "postgres.h"' '#include "postgres.h" - #include "commands/async.h" - #include "miscadmin.h"' - - # Update function calls to use PostgreSQL 15 APIs - substituteInPlace src/pg_cron.c \ - --replace 'ProcessCompletedNotifies();' '/* ProcessCompletedNotifies removed */' \ - --replace 'pg_analyze_and_rewrite(parsetree, sql, NULL, 0,NULL);' 'pg_analyze_and_rewrite_fixedparams(parsetree, sql, NULL, 0, NULL);' - ''; + patches = [ ./pg_cron-1.3.1-pg15.patch ]; }; "1.4.2" = { rev = "v1.4.2"; @@ -32,12 +21,12 @@ let }; }; - mkPgCron = pgCronVersion: { rev, hash, postPatch ? "" }: stdenv.mkDerivation { + mkPgCron = pgCronVersion: { rev, hash, patches ? [] }: stdenv.mkDerivation { pname = "pg_cron"; version = "${pgCronVersion}-pg${lib.versions.major postgresql.version}"; buildInputs = [ postgresql ]; - inherit postPatch; + inherit patches; src = fetchFromGitHub { owner = "citusdata"; @@ -82,7 +71,7 @@ let in stdenv.mkDerivation { pname = "pg_cron-all"; - version = "multi"; + version = "multi-001"; #increment this if you change this package in any way buildInputs = lib.attrValues allVersionsForPg; From d0ff1f51cdfe958f9281b78bb5ca4bbc81c2643d Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 15 Apr 2025 15:34:48 -0400 Subject: [PATCH 3/6] chore: newline --- nix/ext/pg_cron.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/ext/pg_cron.nix b/nix/ext/pg_cron.nix index a59cb5ae5..a134dfb5e 100644 --- a/nix/ext/pg_cron.nix +++ b/nix/ext/pg_cron.nix @@ -107,4 +107,4 @@ stdenv.mkDerivation { platforms = postgresql.meta.platforms; license = licenses.postgresql; }; -} \ No newline at end of file +} From f06c35ac085a68817a0597cef93877c66b14f62f Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 15 Apr 2025 15:41:10 -0400 Subject: [PATCH 4/6] feat: auto create multi version --- nix/ext/pg_cron.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nix/ext/pg_cron.nix b/nix/ext/pg_cron.nix index a134dfb5e..b5e20732b 100644 --- a/nix/ext/pg_cron.nix +++ b/nix/ext/pg_cron.nix @@ -21,6 +21,9 @@ let }; }; + # Simple version string that concatenates all versions with dashes + versionString = "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings ["."] ["-"] v) (lib.attrNames allVersions)); + mkPgCron = pgCronVersion: { rev, hash, patches ? [] }: stdenv.mkDerivation { pname = "pg_cron"; version = "${pgCronVersion}-pg${lib.versions.major postgresql.version}"; @@ -71,7 +74,7 @@ let in stdenv.mkDerivation { pname = "pg_cron-all"; - version = "multi-001"; #increment this if you change this package in any way + version = versionString; buildInputs = lib.attrValues allVersionsForPg; From 9998bbc212a587d3dafc85b81bfa9ee9bda04b0e Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 15 Apr 2025 15:42:27 -0400 Subject: [PATCH 5/6] chore: do not re-intro maintainers here not needed --- nix/ext/pg_cron.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/ext/pg_cron.nix b/nix/ext/pg_cron.nix index b5e20732b..d42cff367 100644 --- a/nix/ext/pg_cron.nix +++ b/nix/ext/pg_cron.nix @@ -106,7 +106,6 @@ stdenv.mkDerivation { meta = with lib; { description = "Run Cron jobs through PostgreSQL (multi-version compatible)"; homepage = "https://github.com/citusdata/pg_cron"; - maintainers = with maintainers; [ samrose ]; platforms = postgresql.meta.platforms; license = licenses.postgresql; }; From a56ae1582e30120863f5ff608bc1ff73a8961db1 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 15 Apr 2025 21:21:04 -0400 Subject: [PATCH 6/6] chore: bump version --- ansible/vars.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ansible/vars.yml b/ansible/vars.yml index 4d3102a17..3cafa6028 100644 --- a/ansible/vars.yml +++ b/ansible/vars.yml @@ -9,9 +9,9 @@ postgres_major: # Full version strings for each major version postgres_release: - postgresorioledb-17: "17.0.1.065-orioledb" - postgres17: "17.4.1.015" - postgres15: "15.8.1.072" + postgresorioledb-17: "17.0.1.067-orioledb-rc-1" + postgres17: "17.4.1.017-rc-1" + postgres15: "15.8.1.074-rc-1" # Non Postgres Extensions pgbouncer_release: "1.19.0"