Skip to content

Commit a23a36d

Browse files
jfrochesamrose
authored andcommitted
Build pg_graphql 1.4.2 using pgrx 0.10.2
1 parent 57502a8 commit a23a36d

File tree

4 files changed

+35
-39
lines changed

4 files changed

+35
-39
lines changed

nix/cargo-pgrx/mkPgrxExtension.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ let
2626
let
2727
pgrx =
2828
versions.${pgrxVersion}
29-
or (throw "Unsupported pgrx version ${pgrxVersion}. Available versions: ${builtins.attrNames versions}. Change 'nix/cargo-pgrx/versions.json' to add support for new versions.");
29+
or (throw "Unsupported pgrx version ${pgrxVersion}. Available versions: ${builtins.toString (builtins.attrNames versions)}. Change 'nix/cargo-pgrx/versions.json' to add support for new versions.");
3030
mapping = {
3131
inherit (pgrx) hash;
3232
cargoHash =
3333
pgrx.rust."${rustVersion}".cargoHash
34-
or (throw "Unsupported rust version ${rustVersion} for pgrx version ${pgrxVersion}. Available Rust versions: ${builtins.attrNames pgrx.rust}. Change 'nix/cargo-pgrx/versions.json' to add support for new versions.");
34+
or (throw "Unsupported rust version ${rustVersion} for pgrx version ${pgrxVersion}. Available Rust versions: ${builtins.toString (builtins.attrNames pgrx.rust)}. Change 'nix/cargo-pgrx/versions.json' to add support for new versions.");
3535
};
3636
in
3737
mkCargoPgrx {

nix/cargo-pgrx/versions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
{
2+
"0.10.2": {
3+
"hash": "sha256-FqjfbJmSy5UCpPPPk4bkEyvQCnaH9zYtkI7txgIn+ls=",
4+
"rust": {
5+
"1.70.0": {
6+
"cargoHash": "sha256-syZ3cQq8qDHBLvqmNDGoxeK6zXHJ47Jwkw3uhaXNCzI="
7+
}
8+
}
9+
},
210
"0.11.2": {
311
"hash": "sha256-8NlpMDFaltTIA8G4JioYm8LaPJ2RGKH5o6sd6lBHmmM=",
412
"rust": {

nix/ext/pg_graphql.nix

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ let
1515
version: hash: rustVersion: pgrxVersion:
1616
let
1717
cargo = rust-bin.stable.${rustVersion}.default;
18-
previousVersions = lib.filter (v: v != version) versions; # FIXME
1918
mkPgrxExtension = callPackages ../cargo-pgrx/mkPgrxExtension.nix {
2019
inherit rustVersion pgrxVersion;
2120
};
@@ -42,50 +41,15 @@ let
4241
# Setting RUSTFLAGS in env to ensure it's available for all phases
4342
env = lib.optionalAttrs stdenv.isDarwin {
4443
POSTGRES_LIB = "${postgresql}/lib";
45-
PGPORT = toString (
46-
5430
47-
+ (if builtins.match ".*_.*" postgresql.version != null then 1 else 0)
48-
# +1 for OrioleDB
49-
+ ((builtins.fromJSON (builtins.substring 0 2 postgresql.version)) - 15) * 2
50-
); # +2 for each major version
5144
RUSTFLAGS = "-C link-arg=-undefined -C link-arg=dynamic_lookup";
5245
NIX_BUILD_CORES = "4"; # Limit parallel jobs
5346
CARGO_BUILD_JOBS = "4"; # Limit cargo parallelism
5447
};
5548
CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_DEBUG = true;
5649

57-
preBuild = ''
58-
echo "Processing git tags..."
59-
echo '${builtins.concatStringsSep "," previousVersions}' | sed 's/,/\n/g' > git_tags.txt
60-
'';
61-
6250
postInstall = ''
6351
mv $out/lib/${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix}
6452
65-
create_sql_files() {
66-
echo "Creating SQL files for previous versions..."
67-
current_version="${version}"
68-
sql_file="$out/share/postgresql/extension/${pname}--$current_version.sql"
69-
70-
if [ -f "$sql_file" ]; then
71-
while read -r previous_version; do
72-
if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then
73-
new_file="$out/share/postgresql/extension/${pname}--$previous_version--$current_version.sql"
74-
sed -i 's/create\s\+function/CREATE OR REPLACE FUNCTION/Ig' "$sql_file"
75-
echo "Creating $new_file"
76-
{
77-
echo "DROP EVENT TRIGGER IF EXISTS graphql_watch_ddl;"
78-
echo "DROP EVENT TRIGGER IF EXISTS graphql_watch_drop;"
79-
cat $sql_file
80-
} > "$new_file"
81-
fi
82-
done < git_tags.txt
83-
else
84-
echo "Warning: $sql_file not found"
85-
fi
86-
rm git_tags.txt
87-
}
88-
8953
create_control_files() {
9054
sed -e "/^default_version =/d" \
9155
-e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}'|" \
@@ -101,7 +65,6 @@ let
10165
fi
10266
}
10367
104-
create_sql_files
10568
create_control_files
10669
'';
10770

@@ -138,6 +101,23 @@ buildEnv {
138101
"/share/postgresql/extension"
139102
];
140103
postBuild = ''
104+
create_sql_files() {
105+
PREVIOUS_VERSION=""
106+
while IFS= read -r i; do
107+
FILENAME=$(basename "$i")
108+
DIRNAME=$(dirname "$i")
109+
VERSION="$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+' <<< $FILENAME)"
110+
if [[ "$PREVIOUS_VERSION" != "" ]]; then
111+
echo "Processing $i"
112+
MIGRATION_FILENAME="$DIRNAME/''${FILENAME/$VERSION/$PREVIOUS_VERSION--$VERSION}"
113+
cp "$i" "$MIGRATION_FILENAME"
114+
fi
115+
PREVIOUS_VERSION="$VERSION"
116+
done < <(find $out -name '*.sql' | sort -V)
117+
}
118+
119+
create_sql_files
120+
141121
# checks
142122
(set -x
143123
test "$(ls -A $out/lib/${pname}*${postgresql.dlSuffix} | wc -l)" = "${

nix/ext/versions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@
7575
}
7676
},
7777
"pg_graphql": {
78+
"1.4.2": {
79+
"postgresql": [
80+
"15"
81+
],
82+
"hash": "sha256-/JweVmfcWqDtFeP3tBl/g6hlqAqbwPHpcHdX9HeqZuU=",
83+
"pgrx": "0.10.2",
84+
"rust": "1.70.0"
85+
},
7886
"1.4.4": {
7987
"postgresql": [
8088
"15"

0 commit comments

Comments
 (0)