Skip to content

Commit

Permalink
fix: sql migration files for pg_jsonschema (#1127)
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Rose <[email protected]>
  • Loading branch information
samrose and samrose authored Aug 16, 2024
1 parent 654389c commit e064bbc
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion nix/ext/pg_jsonschema.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ buildPgrxExtension_0_11_3 rec {

nativeBuildInputs = [ cargo ];
buildInputs = [ postgresql ];

# update the following array when the pg_jsonschema version is updated
# required to ensure that extensions update scripts from previous versions are generated

previousVersions = ["0.3.0" "0.2.0" "0.1.4" "0.1.4" "0.1.2" "0.1.1" "0.1.0"];
CARGO="${cargo}/bin/cargo";
env = lib.optionalAttrs stdenv.isDarwin {
POSTGRES_LIB = "${postgresql}/lib";
Expand All @@ -26,6 +29,31 @@ buildPgrxExtension_0_11_3 rec {
# to fix this a bit later.
doCheck = false;

preBuild = ''
echo "Processing git tags..."
echo '${builtins.concatStringsSep "," previousVersions}' | sed 's/,/\n/g' > git_tags.txt
'';

postInstall = ''
echo "Creating SQL files for previous versions..."
current_version="${version}"
sql_file="$out/share/postgresql/extension/pg_jsonschema--$current_version.sql"
if [ -f "$sql_file" ]; then
while read -r previous_version; do
if [ "$(printf '%s\n' "$previous_version" "$current_version" | sort -V | head -n1)" = "$previous_version" ] && [ "$previous_version" != "$current_version" ]; then
new_file="$out/share/postgresql/extension/pg_jsonschema--$previous_version--$current_version.sql"
echo "Creating $new_file"
cp "$sql_file" "$new_file"
fi
done < git_tags.txt
else
echo "Warning: $sql_file not found"
fi
rm git_tags.txt
'';


meta = with lib; {
description = "JSON Schema Validation for PostgreSQL";
homepage = "https://github.com/supabase/${pname}";
Expand Down

0 comments on commit e064bbc

Please sign in to comment.