Skip to content

Commit e3232da

Browse files
committed
fix: write sql migration files for wrappers
1 parent 27500c7 commit e3232da

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

nix/ext/wrappers/default.nix

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,41 @@
77
, buildPgrxExtension_0_11_3
88
, cargo
99
, darwin
10+
, jq
1011
}:
1112

13+
let
14+
gitTags = builtins.fromJSON (builtins.readFile (builtins.fetchurl {
15+
url = "https://api.github.com/repos/supabase/wrappers/tags";
16+
sha256 = "0am40yspir70wp8pik1c7qmfvbby3nyxza115pi9klp6fyv2s93j"; # Replace with actual hash
17+
}));
18+
in
1219
buildPgrxExtension_0_11_3 rec {
1320
pname = "supabase-wrappers";
1421
version = "0.4.1";
1522
inherit postgresql;
16-
1723
src = fetchFromGitHub {
1824
owner = "supabase";
1925
repo = "wrappers";
2026
rev = "v${version}";
2127
hash = "sha256-AU9Y43qEMcIBVBThu+Aor1HCtfFIg+CdkzK9IxVdkzM=";
2228
};
23-
24-
nativeBuildInputs = [ pkg-config cargo ];
25-
26-
buildInputs = [ openssl ] ++ lib.optionals (stdenv.isDarwin) [
29+
nativeBuildInputs = [ pkg-config cargo jq ];
30+
buildInputs = [ openssl ] ++ lib.optionals (stdenv.isDarwin) [
2731
darwin.apple_sdk.frameworks.CoreFoundation
2832
darwin.apple_sdk.frameworks.Security
2933
darwin.apple_sdk.frameworks.SystemConfiguration
3034
];
31-
32-
# Needed to get openssl-sys to use pkg-config.
3335
OPENSSL_NO_VENDOR = 1;
3436

3537
CARGO="${cargo}/bin/cargo";
36-
3738
cargoLock = {
38-
#TODO when we move to newer versions this lockfile will need to be sourced
39-
# from ${src}/Cargo.lock
4039
lockFile = "${src}/Cargo.lock";
4140
outputHashes = {
4241
"clickhouse-rs-1.0.0-alpha.1" = "sha256-0zmoUo/GLyCKDLkpBsnLAyGs1xz6cubJhn+eVqMEMaw=";
4342
};
4443
};
4544
postPatch = "cp ${cargoLock.lockFile} Cargo.lock";
46-
4745
buildAndTestSubdir = "wrappers";
4846
buildFeatures = [
4947
"helloworld_fdw"
@@ -60,17 +58,38 @@ buildPgrxExtension_0_11_3 rec {
6058
"cognito_fdw"
6159
"wasm_fdw"
6260
];
63-
64-
# FIXME (aseipp): disable the tests since they try to install .control
65-
# files into the wrong spot, aside from that the one main test seems
66-
# to work, though
6761
doCheck = false;
6862

63+
preBuild = ''
64+
echo "Processing git tags..."
65+
echo '${builtins.toJSON gitTags}' | ${jq}/bin/jq -r '.[].name' | sort -rV > git_tags.txt
66+
'';
67+
68+
postInstall = ''
69+
echo "Creating SQL files for previous versions..."
70+
current_version="${version}"
71+
sql_file="$out/share/postgresql/extension/wrappers--$current_version.sql"
72+
73+
if [ -f "$sql_file" ]; then
74+
while read -r tag; do
75+
tag_version=$(echo "$tag" | sed 's/^v//')
76+
if [ "$(printf '%s\n' "$tag_version" "$current_version" | sort -V | head -n1)" = "$tag_version" ] && [ "$tag_version" != "$current_version" ]; then
77+
new_file="$out/share/postgresql/extension/wrappers--$tag_version--$current_version.sql"
78+
echo "Creating $new_file"
79+
cp "$sql_file" "$new_file"
80+
fi
81+
done < git_tags.txt
82+
else
83+
echo "Warning: $sql_file not found"
84+
fi
85+
rm git_tags.txt
86+
'';
87+
6988
meta = with lib; {
7089
description = "Various Foreign Data Wrappers (FDWs) for PostreSQL";
7190
homepage = "https://github.com/supabase/wrappers";
7291
maintainers = with maintainers; [ samrose ];
7392
platforms = postgresql.meta.platforms;
7493
license = licenses.postgresql;
7594
};
76-
}
95+
}

0 commit comments

Comments
 (0)