Skip to content

Commit e064bbc

Browse files
authored
fix: sql migration files for pg_jsonschema (#1127)
Co-authored-by: Sam Rose <[email protected]>
1 parent 654389c commit e064bbc

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

nix/ext/pg_jsonschema.nix

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ buildPgrxExtension_0_11_3 rec {
1414

1515
nativeBuildInputs = [ cargo ];
1616
buildInputs = [ postgresql ];
17-
17+
# update the following array when the pg_jsonschema version is updated
18+
# required to ensure that extensions update scripts from previous versions are generated
19+
20+
previousVersions = ["0.3.0" "0.2.0" "0.1.4" "0.1.4" "0.1.2" "0.1.1" "0.1.0"];
1821
CARGO="${cargo}/bin/cargo";
1922
env = lib.optionalAttrs stdenv.isDarwin {
2023
POSTGRES_LIB = "${postgresql}/lib";
@@ -26,6 +29,31 @@ buildPgrxExtension_0_11_3 rec {
2629
# to fix this a bit later.
2730
doCheck = false;
2831

32+
preBuild = ''
33+
echo "Processing git tags..."
34+
echo '${builtins.concatStringsSep "," previousVersions}' | sed 's/,/\n/g' > git_tags.txt
35+
'';
36+
37+
postInstall = ''
38+
echo "Creating SQL files for previous versions..."
39+
current_version="${version}"
40+
sql_file="$out/share/postgresql/extension/pg_jsonschema--$current_version.sql"
41+
42+
if [ -f "$sql_file" ]; then
43+
while read -r previous_version; do
44+
if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then
45+
new_file="$out/share/postgresql/extension/pg_jsonschema--$previous_version--$current_version.sql"
46+
echo "Creating $new_file"
47+
cp "$sql_file" "$new_file"
48+
fi
49+
done < git_tags.txt
50+
else
51+
echo "Warning: $sql_file not found"
52+
fi
53+
rm git_tags.txt
54+
'';
55+
56+
2957
meta = with lib; {
3058
description = "JSON Schema Validation for PostgreSQL";
3159
homepage = "https://github.com/supabase/${pname}";

0 commit comments

Comments
 (0)