diff --git a/nix/ext/pgtap.nix b/nix/ext/pgtap.nix index a060c552b7..2953f62bc0 100644 --- a/nix/ext/pgtap.nix +++ b/nix/ext/pgtap.nix @@ -6,41 +6,129 @@ perl, perlPackages, which, + buildEnv, + fetchpatch2, }: - -stdenv.mkDerivation rec { +let pname = "pgtap"; - name = pname; - version = "1.2.0"; - src = fetchFromGitHub { - owner = "theory"; - repo = "pgtap"; - rev = "v${version}"; - hash = "sha256-lb0PRffwo6J5a6Hqw1ggvn0cW7gPZ02OEcLPi9ineI8="; - }; + # Load version configuration from external file + allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname}; + + # Filter versions compatible with current PostgreSQL version + supportedVersions = lib.filterAttrs ( + _: value: builtins.elem (lib.versions.major postgresql.version) value.postgresql + ) allVersions; + + # Derived version information + versions = lib.naturalSort (lib.attrNames supportedVersions); + latestVersion = + assert lib.assertMsg ( + versions != [ ] + ) "pgtap: no supported versions for PostgreSQL ${lib.versions.major postgresql.version}"; + lib.last versions; + numberOfVersions = builtins.length versions; + packages = builtins.attrValues ( + lib.mapAttrs (name: value: build name value.hash) supportedVersions + ); + repoOwner = "theory"; + + # Build function for individual versions + build = + version: hash: + stdenv.mkDerivation rec { + inherit pname version; + + src = fetchFromGitHub { + owner = repoOwner; + repo = pname; + rev = "v${version}"; + inherit hash; + }; + + nativeBuildInputs = [ + postgresql + perl + perlPackages.TAPParserSourceHandlerpgTAP + which + ]; + + patches = lib.optionals (version == "1.3.3") [ + # Fix error in upgrade script from 1.2.0 to 1.3.3 + (fetchpatch2 { + name = "pgtap-fix-upgrade-from-1.2.0-to-1.3.3.patch"; + url = "https://github.com/${repoOwner}/${pname}/pull/338.diff?full_index=1"; + hash = "sha256-AVRQyqCGoc0gcoMRWBJKMmUBjadGtWg7rvHmTq5rRpw="; + }) + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/{lib,share/postgresql/extension} + + # Create version-specific control file + if [[ -f src/pgtap${postgresql.dlSuffix} ]]; then + # For versions with shared library, set module_pathname + ext="$out/lib/${pname}-${version}${postgresql.dlSuffix}" + sed -e "/^default_version =/d" \ + -e "s|^module_pathname = .*|module_pathname = '$ext'|" \ + ${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control + else + # For SQL-only versions, remove module_pathname line entirely + sed -e "/^default_version =/d" \ + -e "/^module_pathname =/d" \ + ${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control + fi + + # Copy SQL file to install the specific version + cp sql/${pname}--${version}.sql $out/share/postgresql/extension + + if [[ -f src/pgtap${postgresql.dlSuffix} ]]; then + # Install the shared library with version suffix + install -Dm755 src/pgtap${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix} + fi + + # For the latest version, create default control file and symlink and copy SQL upgrade scripts + if [[ "${version}" == "${latestVersion}" ]]; then + { + echo "default_version = '${version}'" + cat $out/share/postgresql/extension/${pname}--${version}.control + } > $out/share/postgresql/extension/${pname}.control + cp sql/${pname}--*--*.sql $out/share/postgresql/extension + elif [[ "${version}" == "1.3.1" ]]; then + # 1.3.1 is the first and only version with a C extension + ln -sfn ${pname}-${version}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix} + fi + ''; + + meta = with lib; { + description = "A unit testing framework for PostgreSQL"; + longDescription = '' + pgTAP is a unit testing framework for PostgreSQL written in PL/pgSQL and PL/SQL. + It includes a comprehensive collection of TAP-emitting assertion functions, + as well as the ability to integrate with other TAP-emitting test frameworks. + It can also be used in the xUnit testing style. + ''; + homepage = "https://pgtap.org"; + inherit (postgresql.meta) platforms; + license = licenses.mit; + }; + }; +in +buildEnv { + name = pname; + paths = packages; - nativeBuildInputs = [ - postgresql - perl - perlPackages.TAPParserSourceHandlerpgTAP - which + pathsToLink = [ + "/lib" + "/share/postgresql/extension" ]; - installPhase = '' - install -D {sql/pgtap--${version}.sql,pgtap.control} -t $out/share/postgresql/extension - ''; - - meta = with lib; { - description = "A unit testing framework for PostgreSQL"; - longDescription = '' - pgTAP is a unit testing framework for PostgreSQL written in PL/pgSQL and PL/SQL. - It includes a comprehensive collection of TAP-emitting assertion functions, - as well as the ability to integrate with other TAP-emitting test frameworks. - It can also be used in the xUnit testing style. - ''; - homepage = "https://pgtap.org"; - inherit (postgresql.meta) platforms; - license = licenses.mit; + passthru = { + inherit versions numberOfVersions; + pname = "${pname}-all"; + version = + "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions); }; } diff --git a/nix/ext/tests/default.nix b/nix/ext/tests/default.nix index b0918ae22b..d3e6540edb 100644 --- a/nix/ext/tests/default.nix +++ b/nix/ext/tests/default.nix @@ -368,6 +368,7 @@ builtins.listToAttrs ( "pg_stat_monitor" "pg_tle" "pgaudit" + "pgtap" "postgis" "vector" "wal2json" diff --git a/nix/ext/versions.json b/nix/ext/versions.json index b35c6c40b9..0fca984cd0 100644 --- a/nix/ext/versions.json +++ b/nix/ext/versions.json @@ -786,6 +786,28 @@ "hash": "sha256-STJVvvrLVLe1JevNu6u6EftzAWv+X+J8lu66su7Or2s=" } }, + "pgtap": { + "1.2.0": { + "postgresql": [ + "15" + ], + "hash": "sha256-lb0PRffwo6J5a6Hqw1ggvn0cW7gPZ02OEcLPi9ineI8=" + }, + "1.3.1": { + "postgresql": [ + "15", + "17" + ], + "hash": "sha256-HOgCb1CCfsfbMbMMWuzFJ4B8CfVm9b0sI2zBY3/kqyI=" + }, + "1.3.3": { + "postgresql": [ + "15", + "17" + ], + "hash": "sha256-YgvfLGF7pLVcCKD66NnWAydDxtoYHH1DpLiYTEKHJ0E=" + } + }, "pg_tle": { "1.0.1": { "postgresql": [ diff --git a/nix/tests/expected/z_15_ext_interface.out b/nix/tests/expected/z_15_ext_interface.out index c68d842109..b456af76cc 100644 --- a/nix/tests/expected/z_15_ext_interface.out +++ b/nix/tests/expected/z_15_ext_interface.out @@ -2231,7 +2231,6 @@ order by pgtap | public | _pg_sv_type_array | oid[] | name[] pgtap | public | _prokind | p_oid oid | "char" pgtap | public | _query | text | text - pgtap | public | _quote_ident_like | text, text | text pgtap | public | _refine_vol | text | text pgtap | public | _relcomp | text, text, text, text, text | text pgtap | public | _relcomp | text, text, text, text | text @@ -2244,6 +2243,7 @@ order by pgtap | public | _returns | name, name[] | text pgtap | public | _returns | name | text pgtap | public | _returns | name, name | text + pgtap | public | _retval | text | text pgtap | public | _rexists | character[], name, name | boolean pgtap | public | _rexists | character, name | boolean pgtap | public | _rexists | character[], name | boolean @@ -2272,6 +2272,7 @@ order by pgtap | public | _type_func | "char", name, name, name[] | boolean pgtap | public | _type_func | "char", name, name[] | boolean pgtap | public | _type_func | "char", name, name | boolean + pgtap | public | _typename | name | text pgtap | public | _types_are | name, name[], text, character[] | text pgtap | public | _types_are | name[], text, character[] | text pgtap | public | _unalike | boolean, anyelement, text, text | text @@ -2341,10 +2342,12 @@ order by pgtap | public | col_is_null | schema_name name, table_name name, column_name name, description text | text pgtap | public | col_is_pk | name, name, name, text | text pgtap | public | col_is_pk | name, name[], text | text + pgtap | public | col_is_pk | name, name, name[] | text pgtap | public | col_is_pk | name, name[] | text pgtap | public | col_is_pk | name, name, text | text pgtap | public | col_is_pk | name, name, name[], text | text pgtap | public | col_is_pk | name, name | text + pgtap | public | col_is_pk | name, name, name | text pgtap | public | col_is_unique | name, name, name, text | text pgtap | public | col_is_unique | name, name[], text | text pgtap | public | col_is_unique | name, name, name[] | text @@ -2458,6 +2461,7 @@ order by pgtap | public | foreign_tables_are | name[], text | text pgtap | public | foreign_tables_are | name, name[], text | text pgtap | public | foreign_tables_are | name, name[] | text + pgtap | public | format_type_string | text | text pgtap | public | function_lang_is | name, name, name, text | text pgtap | public | function_lang_is | name, name, text | text pgtap | public | function_lang_is | name, name[], name, text | text @@ -2570,6 +2574,7 @@ order by pgtap | public | has_pk | name, name, text | text pgtap | public | has_pk | name, text | text pgtap | public | has_pk | name | text + pgtap | public | has_pk | name, name | text pgtap | public | has_relation | name, name, text | text pgtap | public | has_relation | name, text | text pgtap | public | has_relation | name | text @@ -5293,7 +5298,7 @@ order by xml2 | public | xpath_table | text, text, text, text, text | SETOF record xml2 | public | xslt_process | text, text | text xml2 | public | xslt_process | text, text, text | text -(5121 rows) +(5126 rows) /* diff --git a/nix/tests/expected/z_17_ext_interface.out b/nix/tests/expected/z_17_ext_interface.out index 1b09ed17e5..40eb5a7298 100644 --- a/nix/tests/expected/z_17_ext_interface.out +++ b/nix/tests/expected/z_17_ext_interface.out @@ -2216,7 +2216,6 @@ order by pgtap | public | _pg_sv_type_array | oid[] | name[] pgtap | public | _prokind | p_oid oid | "char" pgtap | public | _query | text | text - pgtap | public | _quote_ident_like | text, text | text pgtap | public | _refine_vol | text | text pgtap | public | _relcomp | text, text, text, text, text | text pgtap | public | _relcomp | text, text, text, text | text @@ -2229,6 +2228,7 @@ order by pgtap | public | _returns | name, name[] | text pgtap | public | _returns | name | text pgtap | public | _returns | name, name | text + pgtap | public | _retval | text | text pgtap | public | _rexists | character[], name, name | boolean pgtap | public | _rexists | character, name | boolean pgtap | public | _rexists | character[], name | boolean @@ -2257,6 +2257,7 @@ order by pgtap | public | _type_func | "char", name, name, name[] | boolean pgtap | public | _type_func | "char", name, name[] | boolean pgtap | public | _type_func | "char", name, name | boolean + pgtap | public | _typename | name | text pgtap | public | _types_are | name, name[], text, character[] | text pgtap | public | _types_are | name[], text, character[] | text pgtap | public | _unalike | boolean, anyelement, text, text | text @@ -2326,10 +2327,12 @@ order by pgtap | public | col_is_null | schema_name name, table_name name, column_name name, description text | text pgtap | public | col_is_pk | name, name, name, text | text pgtap | public | col_is_pk | name, name[], text | text + pgtap | public | col_is_pk | name, name, name[] | text pgtap | public | col_is_pk | name, name[] | text pgtap | public | col_is_pk | name, name, text | text pgtap | public | col_is_pk | name, name, name[], text | text pgtap | public | col_is_pk | name, name | text + pgtap | public | col_is_pk | name, name, name | text pgtap | public | col_is_unique | name, name, name, text | text pgtap | public | col_is_unique | name, name[], text | text pgtap | public | col_is_unique | name, name, name[] | text @@ -2443,6 +2446,7 @@ order by pgtap | public | foreign_tables_are | name[], text | text pgtap | public | foreign_tables_are | name, name[], text | text pgtap | public | foreign_tables_are | name, name[] | text + pgtap | public | format_type_string | text | text pgtap | public | function_lang_is | name, name, name, text | text pgtap | public | function_lang_is | name, name, text | text pgtap | public | function_lang_is | name, name[], name, text | text @@ -2555,6 +2559,7 @@ order by pgtap | public | has_pk | name, name, text | text pgtap | public | has_pk | name, text | text pgtap | public | has_pk | name | text + pgtap | public | has_pk | name, name | text pgtap | public | has_relation | name, name, text | text pgtap | public | has_relation | name, text | text pgtap | public | has_relation | name | text @@ -4937,7 +4942,7 @@ order by xml2 | public | xpath_table | text, text, text, text, text | SETOF record xml2 | public | xslt_process | text, text | text xml2 | public | xslt_process | text, text, text | text -(4778 rows) +(4783 rows) /* diff --git a/nix/tests/expected/z_orioledb-17_ext_interface.out b/nix/tests/expected/z_orioledb-17_ext_interface.out index 4dafb1c87b..916ddba005 100644 --- a/nix/tests/expected/z_orioledb-17_ext_interface.out +++ b/nix/tests/expected/z_orioledb-17_ext_interface.out @@ -2261,7 +2261,6 @@ order by pgtap | public | _pg_sv_type_array | oid[] | name[] pgtap | public | _prokind | p_oid oid | "char" pgtap | public | _query | text | text - pgtap | public | _quote_ident_like | text, text | text pgtap | public | _refine_vol | text | text pgtap | public | _relcomp | text, text, text, text, text | text pgtap | public | _relcomp | text, text, text, text | text @@ -2274,6 +2273,7 @@ order by pgtap | public | _returns | name, name[] | text pgtap | public | _returns | name | text pgtap | public | _returns | name, name | text + pgtap | public | _retval | text | text pgtap | public | _rexists | character[], name, name | boolean pgtap | public | _rexists | character, name | boolean pgtap | public | _rexists | character[], name | boolean @@ -2302,6 +2302,7 @@ order by pgtap | public | _type_func | "char", name, name, name[] | boolean pgtap | public | _type_func | "char", name, name[] | boolean pgtap | public | _type_func | "char", name, name | boolean + pgtap | public | _typename | name | text pgtap | public | _types_are | name, name[], text, character[] | text pgtap | public | _types_are | name[], text, character[] | text pgtap | public | _unalike | boolean, anyelement, text, text | text @@ -2371,10 +2372,12 @@ order by pgtap | public | col_is_null | schema_name name, table_name name, column_name name, description text | text pgtap | public | col_is_pk | name, name, name, text | text pgtap | public | col_is_pk | name, name[], text | text + pgtap | public | col_is_pk | name, name, name[] | text pgtap | public | col_is_pk | name, name[] | text pgtap | public | col_is_pk | name, name, text | text pgtap | public | col_is_pk | name, name, name[], text | text pgtap | public | col_is_pk | name, name | text + pgtap | public | col_is_pk | name, name, name | text pgtap | public | col_is_unique | name, name, name, text | text pgtap | public | col_is_unique | name, name[], text | text pgtap | public | col_is_unique | name, name, name[] | text @@ -2488,6 +2491,7 @@ order by pgtap | public | foreign_tables_are | name[], text | text pgtap | public | foreign_tables_are | name, name[], text | text pgtap | public | foreign_tables_are | name, name[] | text + pgtap | public | format_type_string | text | text pgtap | public | function_lang_is | name, name, name, text | text pgtap | public | function_lang_is | name, name, text | text pgtap | public | function_lang_is | name, name[], name, text | text @@ -2600,6 +2604,7 @@ order by pgtap | public | has_pk | name, name, text | text pgtap | public | has_pk | name, text | text pgtap | public | has_pk | name | text + pgtap | public | has_pk | name, name | text pgtap | public | has_relation | name, name, text | text pgtap | public | has_relation | name, text | text pgtap | public | has_relation | name | text @@ -4982,7 +4987,7 @@ order by xml2 | public | xpath_table | text, text, text, text, text | SETOF record xml2 | public | xslt_process | text, text | text xml2 | public | xslt_process | text, text, text | text -(4822 rows) +(4827 rows) /*