-
-
Notifications
You must be signed in to change notification settings - Fork 175
feat: multi-ext-versions-pgrcron #1549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 28 commits
054c599
c8aefa8
45d5fce
c29cb2d
8d64f01
684420f
7ea04ee
6248e88
e26afc5
de12b8b
e7b7245
5af1724
fb3fee2
67a8076
2bd7b6d
4535b50
66515f8
7c00cd2
7990c3c
90d79b4
1f4f065
4e5c3f4
4ab837e
b8c9e31
65ef069
c2631e8
164752b
2f7f8f0
caa684a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <sys/resource.h> | ||
|
||
#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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,147 @@ | ||
{ 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="; | ||
patches = [ ./pg_cron-1.3.1-pg15.patch ]; | ||
}; | ||
"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="; | ||
}; | ||
}; | ||
|
||
# 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}"; | ||
|
||
buildInputs = [ postgresql ]; | ||
inherit patches; | ||
|
||
src = fetchFromGitHub { | ||
owner = "citusdata"; | ||
repo = "pg_cron"; | ||
inherit rev hash; | ||
}; | ||
|
||
buildInputs = [ postgresql ]; | ||
buildPhase = '' | ||
make PG_CONFIG=${postgresql}/bin/pg_config | ||
|
||
# Create version-specific SQL file | ||
cp pg_cron.sql pg_cron--${pgCronVersion}.sql | ||
|
||
src = fetchFromGitHub { | ||
owner = "citusdata"; | ||
repo = pname; | ||
rev = "v${version}"; | ||
hash = "sha256-t1DpFkPiSfdoGG2NgNT7g1lkvSooZoRoUrix6cBID40="; | ||
# 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 | ||
''; | ||
|
||
installPhase = '' | ||
mkdir -p $out/{lib,share/postgresql/extension,bin} | ||
|
||
# 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a light derivation so maybe |
||
pname = "pg_cron-all"; | ||
version = versionString; | ||
|
||
buildInputs = lib.attrValues allVersionsForPg; | ||
|
||
dontUnpack = true; | ||
dontConfigure = true; | ||
dontBuild = true; | ||
|
||
installPhase = '' | ||
mkdir -p $out/{lib,share/postgresql/extension} | ||
mkdir -p $out/{lib,share/postgresql/extension,bin} | ||
|
||
# Install all versions | ||
for drv in ${lib.concatStringsSep " " (lib.attrValues allVersionsForPg)}; do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be able to just use |
||
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} | ||
|
||
# Create version switcher script | ||
cat > $out/bin/switch_pg_cron_version <<'EOF' | ||
#!/bin/sh | ||
set -e | ||
|
||
if [ $# -ne 1 ]; then | ||
echo "Usage: $0 <version>" | ||
echo "Example: $0 1.4.2" | ||
exit 1 | ||
fi | ||
|
||
VERSION=$1 | ||
LIB_DIR=$(dirname "$0")/../lib | ||
|
||
# Use platform-specific extension | ||
if [ "$(uname)" = "Darwin" ]; then | ||
EXT=".dylib" | ||
else | ||
EXT=".so" | ||
fi | ||
|
||
# Check if version exists | ||
if [ ! -f "$LIB_DIR/pg_cron-$VERSION$EXT" ]; then | ||
echo "Error: Version $VERSION not found" | ||
exit 1 | ||
fi | ||
|
||
# Update library symlink | ||
ln -sfnv "pg_cron-$VERSION$EXT" "$LIB_DIR/pg_cron$EXT" | ||
|
||
echo "Successfully switched pg_cron to version $VERSION" | ||
EOF | ||
Comment on lines
+105
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are other extensions going to do the same thing? If so, could there be a "generic" wrapper that could have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There may be one other extension that does something similar but I am not sure yet if it will be generic enough to re-use |
||
|
||
cp *${postgresql.dlSuffix} $out/lib | ||
cp *.sql $out/share/postgresql/extension | ||
cp *.control $out/share/postgresql/extension | ||
chmod +x $out/bin/switch_pg_cron_version | ||
''; | ||
|
||
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"; | ||
platforms = postgresql.meta.platforms; | ||
samrose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
license = licenses.postgresql; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of specifying the rev's and inheriting them, wouldn't it be better to just do
tag = "v${version}"
in thesrc
?