Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: write sql migration files for wrappers #1114

Merged
merged 7 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ami-release-nix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
run: |
packer init stage2-nix-psql.pkr.hcl
GIT_SHA=${{github.sha}}
packer build -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" stage2-nix-psql.pkr.hcl
packer build -var "git_sha=${GIT_SHA}" -var "git-head-version=${GIT_SHA}" -var "packer-execution-id=${GITHUB_RUN_ID}" -var-file="development-arm.vars.pkr.hcl" -var-file="common-nix.vars.pkr.hcl" stage2-nix-psql.pkr.hcl

- name: Grab release version
id: process_release_version
Expand Down
2 changes: 1 addition & 1 deletion common-nix.vars.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
postgres-version = "15.6.1.110"
postgres-version = "15.6.1.111"
51 changes: 35 additions & 16 deletions nix/ext/wrappers/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,41 @@
, buildPgrxExtension_0_11_3
, cargo
, darwin
, jq
}:

let
gitTags = builtins.fromJSON (builtins.readFile (builtins.fetchurl {
url = "https://api.github.com/repos/supabase/wrappers/tags";
sha256 = "0am40yspir70wp8pik1c7qmfvbby3nyxza115pi9klp6fyv2s93j"; # Replace with actual hash
}));
in
buildPgrxExtension_0_11_3 rec {
pname = "supabase-wrappers";
version = "0.4.1";
inherit postgresql;

src = fetchFromGitHub {
owner = "supabase";
repo = "wrappers";
rev = "v${version}";
hash = "sha256-AU9Y43qEMcIBVBThu+Aor1HCtfFIg+CdkzK9IxVdkzM=";
};

nativeBuildInputs = [ pkg-config cargo ];

buildInputs = [ openssl ] ++ lib.optionals (stdenv.isDarwin) [
nativeBuildInputs = [ pkg-config cargo jq ];
buildInputs = [ openssl ] ++ lib.optionals (stdenv.isDarwin) [
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.SystemConfiguration
];

# Needed to get openssl-sys to use pkg-config.
OPENSSL_NO_VENDOR = 1;

CARGO="${cargo}/bin/cargo";

cargoLock = {
#TODO when we move to newer versions this lockfile will need to be sourced
# from ${src}/Cargo.lock
lockFile = "${src}/Cargo.lock";
outputHashes = {
"clickhouse-rs-1.0.0-alpha.1" = "sha256-0zmoUo/GLyCKDLkpBsnLAyGs1xz6cubJhn+eVqMEMaw=";
};
};
postPatch = "cp ${cargoLock.lockFile} Cargo.lock";

buildAndTestSubdir = "wrappers";
buildFeatures = [
"helloworld_fdw"
Expand All @@ -60,17 +58,38 @@ buildPgrxExtension_0_11_3 rec {
"cognito_fdw"
"wasm_fdw"
];

# FIXME (aseipp): disable the tests since they try to install .control
# files into the wrong spot, aside from that the one main test seems
# to work, though
doCheck = false;

preBuild = ''
echo "Processing git tags..."
echo '${builtins.toJSON gitTags}' | ${jq}/bin/jq -r '.[].name' | sort -rV > git_tags.txt
'';

postInstall = ''
echo "Creating SQL files for previous versions..."
current_version="${version}"
sql_file="$out/share/postgresql/extension/wrappers--$current_version.sql"

if [ -f "$sql_file" ]; then
while read -r tag; do
tag_version=$(echo "$tag" | sed 's/^v//')
if [ "$(printf '%s\n' "$tag_version" "$current_version" | sort -V | head -n1)" = "$tag_version" ] && [ "$tag_version" != "$current_version" ]; then
new_file="$out/share/postgresql/extension/wrappers--$tag_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 = "Various Foreign Data Wrappers (FDWs) for PostreSQL";
homepage = "https://github.com/supabase/wrappers";
maintainers = with maintainers; [ samrose ];
platforms = postgresql.meta.platforms;
license = licenses.postgresql;
};
}
}
Loading