Skip to content

Commit 176e28b

Browse files
committed
Build pg_graphql 1.4.2 using pgrx 0.10.2
1 parent 8796278 commit 176e28b

File tree

5 files changed

+42
-40
lines changed

5 files changed

+42
-40
lines changed

nix/cargo-pgrx/buildPgrxExtension.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@ let
9494
export PGRX_HOME=$(mktemp -d)
9595
export PGDATA="$PGRX_HOME/data-${pgrxPostgresMajor}/"
9696
cargo-pgrx pgrx init "--pg${pgrxPostgresMajor}" ${lib.getDev postgresql}/bin/pg_config
97-
echo "unix_socket_directories = '$(mktemp -d)'" > "$PGDATA/postgresql.conf"
97+
98+
# unix sockets work in sandbox, too.
99+
export PGHOST="$(mktemp -d)"
100+
cat > "$PGDATA/postgresql.conf" <<EOF
101+
listen_addresses = '''
102+
unix_socket_directories = '$PGHOST'
103+
EOF
98104
99105
# This is primarily for Mac or other Nix systems that don't use the nixbld user.
100106
export USER="$(whoami)"

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

@@ -141,6 +104,23 @@ buildEnv {
141104
"/share/postgresql/extension"
142105
];
143106
postBuild = ''
107+
create_sql_files() {
108+
PREVIOUS_VERSION=""
109+
while IFS= read -r i; do
110+
FILENAME=$(basename "$i")
111+
DIRNAME=$(dirname "$i")
112+
VERSION="$(grep -oE '[0-9]+\.[0-9]+\.[0-9]+' <<< $FILENAME)"
113+
if [[ "$PREVIOUS_VERSION" != "" ]]; then
114+
echo "Processing $i"
115+
MIGRATION_FILENAME="$DIRNAME/''${FILENAME/$VERSION/$PREVIOUS_VERSION--$VERSION}"
116+
cp "$i" "$MIGRATION_FILENAME"
117+
fi
118+
PREVIOUS_VERSION="$VERSION"
119+
done < <(find $out -name '*.sql' | sort -V)
120+
}
121+
122+
create_sql_files
123+
144124
# checks
145125
(set -x
146126
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
@@ -1,5 +1,13 @@
11
{
22
"pg_graphql": {
3+
"1.4.2": {
4+
"postgresql": [
5+
"15"
6+
],
7+
"hash": "sha256-/JweVmfcWqDtFeP3tBl/g6hlqAqbwPHpcHdX9HeqZuU=",
8+
"pgrx": "0.10.2",
9+
"rust": "1.70.0"
10+
},
311
"1.4.4": {
412
"postgresql": [
513
"15"

0 commit comments

Comments
 (0)