Skip to content

Commit bba3ceb

Browse files
committed
fix: generate sql migrations for tag versions
1 parent 6acd4c3 commit bba3ceb

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

nix/ext/pg_graphql.nix

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ buildPgrxExtension_0_11_3 rec {
1212
hash = "sha256-Q6XfcTKVOjo5pGy8QACc4QCHolKxEGU8e0TTC6Zg8go=";
1313
};
1414

15+
# update the following array when the pg_graphql version is updated
16+
# required to ensure that extensions update scripts from previous versions are generated
17+
previousVersions = [
18+
"1.5.6" "1.5.5" "1.5.4" "1.5.3" "1.5.2" "1.5.1" "1.5.0"
19+
"1.4.4" "1.4.3" "1.4.2" "1.4.1" "1.4.0" "1.3.0" "1.2.3" "1.2.2"
20+
"1.2.1" "1.2.0" "1.1.0" "1.0.2" "1.0.1" "1.0.0" "0.5.3"
21+
"0.5.2" "0.5.0" "0.4.1" "0.4.0" "0.3.3" "0.3.2" "0.3.1"
22+
"0.3.0" "0.2.1" "0.2.0" "0.1.5" "0.1.4" "0.1.3" "0.1.2"
23+
"0.1.1" "0.1.0"
24+
];
25+
1526
nativeBuildInputs = [ cargo ];
1627
buildInputs = [ postgresql ];
1728

@@ -27,6 +38,30 @@ buildPgrxExtension_0_11_3 rec {
2738
# to work, though
2839
doCheck = false;
2940

41+
preBuild = ''
42+
echo "Processing git tags..."
43+
echo '${builtins.concatStringsSep "," previousVersions}' | sed 's/,/\n/g' > git_tags.txt
44+
'';
45+
46+
postInstall = ''
47+
echo "Creating SQL files for previous versions..."
48+
current_version="${version}"
49+
sql_file="$out/share/postgresql/extension/pg_graphql--$current_version.sql"
50+
51+
if [ -f "$sql_file" ]; then
52+
while read -r previous_version; do
53+
if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then
54+
new_file="$out/share/postgresql/extension/pg_graphql--$previous_version--$current_version.sql"
55+
echo "Creating $new_file"
56+
cp "$sql_file" "$new_file"
57+
fi
58+
done < git_tags.txt
59+
else
60+
echo "Warning: $sql_file not found"
61+
fi
62+
rm git_tags.txt
63+
'';
64+
3065
meta = with lib; {
3166
description = "GraphQL support for PostreSQL";
3267
homepage = "https://github.com/supabase/${pname}";

0 commit comments

Comments
 (0)