Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Sam/psql 16 (#47)
Browse files Browse the repository at this point in the history
* feat: pg 15, pg 16, cargo pgrx 0.11.2

* fix: versions

* fix: version correction

* fix: formatting of scripts

* chore: cleanup comment

* fix: version correction

* fix: just appeared to be a typo in the shebang that prevented nix app from running

* feat: rm citus and work toward completing 15-16 updates

* fix: reference the Cargo.lock that has the data we need to do this build

* fix: update CI to build correct versions
  • Loading branch information
samrose authored Feb 28, 2024
1 parent 72cddc5 commit 5a50e55
Show file tree
Hide file tree
Showing 20 changed files with 294 additions and 121 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ result*
# shell history
.history
container.sh
sbom.spdx.json
sbom.cdx.json
sbom.csv
graph*.png
46 changes: 46 additions & 0 deletions ext/0001-build-Allow-using-V8-from-system.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
diff --git a/Makefile b/Makefile
index 38879cc..6e78eeb 100644
--- a/Makefile
+++ b/Makefile
@@ -20,6 +20,7 @@ OBJS = $(SRCS:.cc=.o)
MODULE_big = plv8-$(PLV8_VERSION)
EXTENSION = plv8
PLV8_DATA = plv8.control plv8--$(PLV8_VERSION).sql $(wildcard upgrade/*.sql)
+USE_SYSTEM_V8 = 0


# Platform detection
@@ -41,6 +42,7 @@ PGXS := $(shell $(PG_CONFIG) --pgxs)
PG_VERSION_NUM := $(shell cat `$(PG_CONFIG) --includedir-server`/pg_config*.h \
| perl -ne 'print $$1 and exit if /PG_VERSION_NUM\s+(\d+)/')

+ifeq ($(USE_SYSTEM_V8),0)
AUTOV8_DIR = build/v8
AUTOV8_OUT = build/v8/out.gn/obj
AUTOV8_STATIC_LIBS = -lv8_libplatform -lv8_libbase
@@ -66,6 +68,7 @@ v8:
make -f Makefiles/Makefile.macos v8
endif
endif
+endif

# enable direct jsonb conversion by default
CCFLAGS += -DJSONB_DIRECT_CONVERSION
@@ -83,6 +86,7 @@ ifdef BIGINT_GRACEFUL
endif


+ifeq ($(USE_SYSTEM_V8),0)
# We're gonna build static link. Rip it out after include Makefile
SHLIB_LINK := $(filter-out -lv8, $(SHLIB_LINK))

@@ -101,6 +105,7 @@ else
SHLIB_LINK += -lrt -std=c++14
endif
endif
+endif

DATA = $(PLV8_DATA)
ifndef DISABLE_DIALECT
--
2.37.3
8 changes: 5 additions & 3 deletions ext/citus.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{ lib, curl, lz4, zstd, krb5, icu, stdenv, fetchFromGitHub, postgresql }:

#FIXME we have decided deactivate this for now, as it is not used in production
# if we decide to use it later we may need to look at this documentation
# https://docs.citusdata.com/en/stable/admin_guide/upgrading_citus.html#upgrading-postgresql-version-from-15-to-16
stdenv.mkDerivation rec {
pname = "citus";
version = "12.0.0";
version = "12.1.2";

buildInputs = [ curl lz4 zstd krb5 icu.dev postgresql];

src = fetchFromGitHub {
owner = "citusdata";
repo = pname;
rev = "refs/tags/v${version}";
hash = "sha256-HH9/slsCRe2yIVIqwR8sDyqXFonf8BHhJhLzHNv1CF0=";
hash = "sha256-0uYNMLAYigtGlDRvOEkQeC5i58QfXcdSVjTQwWVFX+8=";
};

installPhase = ''
Expand Down
8 changes: 4 additions & 4 deletions ext/pg_graphql.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

buildPgrxExtension rec {
pname = "pg_graphql";
version = "unstable-1.4.0";
version = "unstable-1.5.0";
inherit postgresql;

src = fetchFromGitHub {
owner = "supabase";
repo = pname;
rev = "v1.4.0";
hash = "sha256-vpMNN7xKCFCqCsMHNOpWbeNYfUCREszBLSxPl3iBFLM=";
rev = "v1.5.0";
hash = "sha256-28ANRZyF22qF2YAxNAAkPfGOM3+xiO6IHdXsTp0CTQE=";
};

cargoHash = "sha256-jB5cV6r4sf3TBlR9Zsrb7hZp25fIc0DcKvIetYut2ZU=";
cargoHash = "sha256-CUiGs0m9aUeqjpdPyOSjz91cP7TT6kjJqnw7ImGnQuo=";

# FIXME (aseipp): disable the tests since they try to install .control
# files into the wrong spot, aside from that the one main test seems
Expand Down
8 changes: 4 additions & 4 deletions ext/pg_jsonschema.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

buildPgrxExtension rec {
pname = "pg_jsonschema";
version = "unstable-0.2.0";
version = "unstable-e8c331f106a7970eaa406b844c83c259ff2f0e84";
inherit postgresql;

src = fetchFromGitHub {
owner = "supabase";
repo = pname;
rev = "v0.2.0";
hash = "sha256-57gZbUVi8P4EB8T0P19JBVXcetQcr6IxuIx96NNFA/0=";
rev = "e8c331f106a7970eaa406b844c83c259ff2f0e84";
hash = "sha256-Z88cKMhkCkLKaeP5oFMJNxojIPfrOyPTBfCM0TKOi0E=";
};

cargoHash = "sha256-GXzoAOwDwGbHNWOJvaGdOvkU8L/ei703590ClkrDN+Y=";
cargoHash = "sha256-i05gkqyBIH+xkAognSKouyA08B2kKZ/W94t5QgG/BHA=";

# FIXME (aseipp): testsuite tries to write files into /nix/store; we'll have
# to fix this a bit later.
Expand Down
14 changes: 7 additions & 7 deletions ext/pg_stat_monitor.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ let
#
# this seems to all be cleaned up in version 2.0 of the extension, so ideally
# we could upgrade to it later on and nuke this.
sqlFilename = if lib.versionOlder postgresql.version "14"
then "pg_stat_monitor--1.0.13.sql.in"
else "pg_stat_monitor--1.0.14.sql.in";
# sqlFilename = if lib.versionOlder postgresql.version "14"
# then "pg_stat_monitor--1.0.13.sql.in"
# else "pg_stat_monitor--1.0.14.sql.in";

in stdenv.mkDerivation rec {
pname = "pg_stat_monitor";
version = "1.0.1";
version = "2.0.4";

buildInputs = [ postgresql ];

src = fetchFromGitHub {
owner = "percona";
repo = pname;
rev = "refs/tags/${version}";
hash = "sha256-sQEpIknAFOmvNTX2G23X4BvMdy3Ms7sXx7hLZt8jyUk=";
hash = "sha256-57Ji/KltIHNf81OxT0+4JIDqydST5RKMqrybNBZochg=";
};

makeFlags = [ "USE_PGXS=1" ];

installPhase = ''
mkdir -p $out/{lib,share/postgresql/extension}
cp ${sqlFilename} pg_stat_monitor--1.0.sql
cp pg_stat_monitor--2.0.sql pg_stat_monitor--1.0--2.0.sql
cp *.so $out/lib
cp *.sql $out/share/postgresql/extension
Expand All @@ -45,6 +45,6 @@ in stdenv.mkDerivation rec {
maintainers = with maintainers; [ thoughtpolice ];
platforms = postgresql.meta.platforms;
license = licenses.postgresql;
broken = lib.versionOlder postgresql.version "13";
broken = lib.versionOlder postgresql.version "15";
};
}
4 changes: 2 additions & 2 deletions ext/pgsql-http.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

stdenv.mkDerivation rec {
pname = "pgsql-http";
version = "1.5.0";
version = "1.6.0";

buildInputs = [ curl postgresql ];

src = fetchFromGitHub {
owner = "pramsey";
repo = pname;
rev = "refs/tags/v${version}";
hash = "sha256-+N/CXm4arRgvhglanfvO0FNOBUWV5RL8mn/9FpNvcjY=";
hash = "sha256-CPHfx7vhWfxkXsoKTzyFuTt47BPMvzi/pi1leGcuD60=";
};

installPhase = ''
Expand Down
146 changes: 146 additions & 0 deletions ext/plv8.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{ stdenv
, lib
, fetchFromGitHub
, v8
, perl
, postgresql
# For test
, runCommand
, coreutils
, gnugrep
}:

stdenv.mkDerivation (finalAttrs: {
pname = "plv8";
# plv8 latest is https://github.com/plv8/plv8/releases/tag/v3.2.2
# FIXME we need to increment this build toward 3.2.2
# 3.1.7 is the highest version that can be built with pg 16
version = "3.1.7";

src = fetchFromGitHub {
owner = "plv8";
repo = "plv8";
rev = "v${finalAttrs.version}";
hash = "sha256-kTID3Zo3YwNZUno8kdQE7ihtiddsIAZNuBN91IKgaC4=";
};

patches = [
# Allow building with system v8.
# https://github.com/plv8/plv8/pull/505 (rejected)
./0001-build-Allow-using-V8-from-system.patch
];

nativeBuildInputs = [
perl
];

buildInputs = [
v8
postgresql
];

buildFlags = [ "all" ];

makeFlags = [
# Nixpkgs build a v8 monolith instead of separate v8_libplatform.
"USE_SYSTEM_V8=1"
"SHLIB_LINK=-lv8"
"V8_OUTDIR=${v8}/lib"
];

installFlags = [
# PGXS only supports installing to postgresql prefix so we need to redirect this
"DESTDIR=${placeholder "out"}"
];

# No configure script.
dontConfigure = true;

postPatch = ''
patchShebangs ./generate_upgrade.sh
# https://github.com/plv8/plv8/pull/506
substituteInPlace generate_upgrade.sh \
--replace " 2.3.10 " " 2.3.10 2.3.11 2.3.12 2.3.13 2.3.14 2.3.15 "
'';

postInstall = ''
# Move the redirected to proper directory.
# There appear to be no references to the install directories
# so changing them does not cause issues.
mv "$out/nix/store"/*/* "$out"
rmdir "$out/nix/store"/* "$out/nix/store" "$out/nix"
'';

passthru = {
tests =
let
postgresqlWithSelf = postgresql.withPackages (_: [
finalAttrs.finalPackage
]);
in {
smoke = runCommand "plv8-smoke-test" {} ''
export PATH=${lib.makeBinPath [
postgresqlWithSelf
coreutils
gnugrep
]}
db="$PWD/testdb"
initdb "$db"
postgres -k "$db" -D "$db" &
pid="$!"
for i in $(seq 1 100); do
if psql -h "$db" -d postgres -c "" 2>/dev/null; then
break
elif ! kill -0 "$pid"; then
exit 1
else
sleep 0.1
fi
done
psql -h "$db" -d postgres -c 'CREATE EXTENSION plv8; DO $$ plv8.elog(NOTICE, plv8.version); $$ LANGUAGE plv8;' 2> "$out"
grep -q "${finalAttrs.version}" "$out"
kill -0 "$pid"
'';

regression = stdenv.mkDerivation {
name = "plv8-regression";
inherit (finalAttrs) src patches nativeBuildInputs buildInputs dontConfigure;

buildPhase = ''
runHook preBuild
# The regression tests need to be run in the order specified in the Makefile.
echo -e "include Makefile\nprint_regress_files:\n\t@echo \$(REGRESS)" > Makefile.regress
REGRESS_TESTS=$(make -f Makefile.regress print_regress_files)
${postgresql}/lib/pgxs/src/test/regress/pg_regress \
--bindir='${postgresqlWithSelf}/bin' \
--temp-instance=regress-instance \
--dbname=contrib_regression \
$REGRESS_TESTS
runHook postBuild
'';

installPhase = ''
runHook preInstall
touch "$out"
runHook postInstall
'';
};
};
};

meta = with lib; {
description = "V8 Engine Javascript Procedural Language add-on for PostgreSQL";
homepage = "https://plv8.github.io/";
maintainers = with maintainers; [ marsam ];
platforms = [ "x86_64-linux" "aarch64-linux" ];
license = licenses.postgresql;
broken = postgresql.jitSupport;
};
})
15 changes: 8 additions & 7 deletions ext/wrappers/default.nix
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
{ lib, stdenv, fetchFromGitHub, openssl, pkg-config
, postgresql, buildPgrxExtension_0_11_0
, postgresql, buildPgrxExtension_0_11_2
}:

buildPgrxExtension_0_11_0 rec {
buildPgrxExtension_0_11_2 rec {
pname = "supabase-wrappers";
version = "unstable-2024-02-14";
version = "unstable-2024-02-26";
inherit postgresql;

src = fetchFromGitHub {
owner = "supabase";
repo = "wrappers";
rev = "v0.2.0";
hash = "sha256-F+S5uyubL3Tb3RTJ08Zf9gN8oLE/WkCWFA8RcKkDqes=";
#rev pinned for now to the HEAD of the main branch to achieve cargo-pgrx 0.11.2 compat
rev = "5b5c2622268c75bec834a38b2ff967f781511188";
hash = "sha256-VwEFJD0yD+gvXCTzq9NfjCPEkh/lDQdEOPfk8LwK4z4=";
};

nativeBuildInputs = [ pkg-config ];
buildInputs = [ openssl ];

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

cargoLock = {
lockFile = "${src}/wrappers/Cargo.lock";
lockFile = "${src}/Cargo.lock";
outputHashes = {
"clickhouse-rs-1.0.0-alpha.1" = "sha256-0zmoUo/GLyCKDLkpBsnLAyGs1xz6cubJhn+eVqMEMaw=";
};
Expand Down
Loading

0 comments on commit 5a50e55

Please sign in to comment.