Merge pull request #186276 from typetetris/feature/add-timescaledb-toolkit

timescaledb_toolkit: init at 1.14.0

authored by Mario Rodas and committed by GitHub dae678ad 93b31a9d

+301
+1
nixos/tests/all-tests.nix
··· 689 terminal-emulators = handleTest ./terminal-emulators.nix {}; 690 tiddlywiki = handleTest ./tiddlywiki.nix {}; 691 tigervnc = handleTest ./tigervnc.nix {}; 692 timezone = handleTest ./timezone.nix {}; 693 tinc = handleTest ./tinc {}; 694 tinydns = handleTest ./tinydns.nix {};
··· 689 terminal-emulators = handleTest ./terminal-emulators.nix {}; 690 tiddlywiki = handleTest ./tiddlywiki.nix {}; 691 tigervnc = handleTest ./tigervnc.nix {}; 692 + timescaledb = handleTest ./timescaledb.nix {}; 693 timezone = handleTest ./timezone.nix {}; 694 tinc = handleTest ./tinc {}; 695 tinydns = handleTest ./tinydns.nix {};
+93
nixos/tests/timescaledb.nix
···
··· 1 + # mostly copied from ./postgresql.nix as it seemed unapproriate to 2 + # test additional extensions for postgresql there. 3 + 4 + { system ? builtins.currentSystem 5 + , config ? { } 6 + , pkgs ? import ../.. { inherit system config; } 7 + }: 8 + 9 + with import ../lib/testing-python.nix { inherit system pkgs; }; 10 + with pkgs.lib; 11 + 12 + let 13 + postgresql-versions = import ../../pkgs/servers/sql/postgresql pkgs; 14 + test-sql = pkgs.writeText "postgresql-test" '' 15 + CREATE EXTENSION timescaledb; 16 + CREATE EXTENSION timescaledb_toolkit; 17 + 18 + CREATE TABLE sth ( 19 + time TIMESTAMPTZ NOT NULL, 20 + value DOUBLE PRECISION 21 + ); 22 + 23 + SELECT create_hypertable('sth', 'time'); 24 + 25 + INSERT INTO sth (time, value) VALUES 26 + ('2003-04-12 04:05:06 America/New_York', 1.0), 27 + ('2003-04-12 04:05:07 America/New_York', 2.0), 28 + ('2003-04-12 04:05:08 America/New_York', 3.0), 29 + ('2003-04-12 04:05:09 America/New_York', 4.0), 30 + ('2003-04-12 04:05:10 America/New_York', 5.0) 31 + ; 32 + 33 + WITH t AS ( 34 + SELECT 35 + time_bucket('1 day'::interval, time) AS dt, 36 + stats_agg(value) AS stats 37 + FROM sth 38 + GROUP BY time_bucket('1 day'::interval, time) 39 + ) 40 + SELECT 41 + average(stats) 42 + FROM t; 43 + ''; 44 + make-postgresql-test = postgresql-name: postgresql-package: makeTest { 45 + name = postgresql-name; 46 + meta = with pkgs.lib.maintainers; { 47 + maintainers = [ typetetris ]; 48 + }; 49 + 50 + nodes.machine = { ... }: 51 + { 52 + services.postgresql = { 53 + enable = true; 54 + package = postgresql-package; 55 + extraPlugins = with postgresql-package.pkgs; [ 56 + timescaledb 57 + timescaledb_toolkit 58 + ]; 59 + settings = { shared_preload_libraries = "timescaledb, timescaledb_toolkit"; }; 60 + }; 61 + }; 62 + 63 + testScript = '' 64 + def check_count(statement, lines): 65 + return 'test $(sudo -u postgres psql postgres -tAc "{}"|wc -l) -eq {}'.format( 66 + statement, lines 67 + ) 68 + 69 + 70 + machine.start() 71 + machine.wait_for_unit("postgresql") 72 + 73 + with subtest("Postgresql with extensions timescaledb and timescaledb_toolkit is available just after unit start"): 74 + machine.succeed( 75 + "sudo -u postgres psql -f ${test-sql}" 76 + ) 77 + 78 + machine.fail(check_count("SELECT * FROM sth;", 3)) 79 + machine.succeed(check_count("SELECT * FROM sth;", 5)) 80 + machine.fail(check_count("SELECT * FROM sth;", 4)) 81 + 82 + machine.shutdown() 83 + ''; 84 + 85 + }; 86 + applicablePostgresqlVersions = filterAttrs (_: value: versionAtLeast value.version "12") postgresql-versions; 87 + in 88 + mapAttrs' 89 + (name: package: { 90 + inherit name; 91 + value = make-postgresql-test name package; 92 + }) 93 + applicablePostgresqlVersions
+160
pkgs/development/tools/rust/cargo-pgx/buildPgxExtension.nix
···
··· 1 + # preBuildAndTest and some small other bits 2 + # taken from https://github.com/tcdi/pgx/blob/v0.4.5/nix/extension.nix 3 + # (but now heavily modified) 4 + # which uses MIT License with the following license file 5 + # 6 + # MIT License 7 + # 8 + # Portions Copyright 2019-2021 ZomboDB, LLC. 9 + # Portions Copyright 2021-2022 Technology Concepts & Design, Inc. <support@tcdi.com>. 10 + # All rights reserved. 11 + # 12 + # Permission is hereby granted, free of charge, to any person obtaining a copy 13 + # of this software and associated documentation files (the "Software"), to deal 14 + # in the Software without restriction, including without limitation the rights 15 + # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 + # copies of the Software, and to permit persons to whom the Software is 17 + # furnished to do so, subject to the following conditions: 18 + # 19 + # The above copyright notice and this permission notice shall be included in all 20 + # copies or substantial portions of the Software. 21 + # 22 + # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 + # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 + # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 + # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 + # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 + # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 + # SOFTWARE. 29 + 30 + { lib 31 + , cargo-pgx 32 + , pkg-config 33 + , rustPlatform 34 + , stdenv 35 + , Security 36 + , writeShellScriptBin 37 + }: 38 + 39 + # The idea behind: Use it mostly like rustPlatform.buildRustPackage and so 40 + # we hand most of the arguments down. 41 + # 42 + # Additional arguments are: 43 + # - `postgresql` postgresql package of the version of postgresql this extension should be build for. 44 + # Needs to be the build platform variant. 45 + # - `useFakeRustfmt` Whether to use a noop fake command as rustfmt. cargo-pgx tries to call rustfmt. 46 + # If the generated rust bindings aren't needed to use the extension, its a 47 + # unnecessary and heavy dependency. If you set this to true, you also 48 + # have to add `rustfmt` to `nativeBuildInputs`. 49 + 50 + { buildAndTestSubdir ? null 51 + , buildType ? "release" 52 + , buildFeatures ? [ ] 53 + , cargoBuildFlags ? [ ] 54 + , postgresql 55 + # cargo-pgx calls rustfmt on generated bindings, this is not strictly necessary, so we avoid the 56 + # dependency here. Set to false and provide rustfmt in nativeBuildInputs, if you need it, e.g. 57 + # if you include the generated code in the output via postInstall. 58 + , useFakeRustfmt ? true 59 + , ... 60 + } @ args: 61 + let 62 + rustfmtInNativeBuildInputs = lib.lists.any (dep: lib.getName dep == "rustfmt") (args.nativeBuildInputs or []); 63 + in 64 + 65 + assert lib.asserts.assertMsg ((args.installPhase or "") == "") 66 + "buildPgxExtensions overwrites the installPhase, so providing one does nothing"; 67 + assert lib.asserts.assertMsg ((args.buildPhase or "") == "") 68 + "buildPgxExtensions overwrites the buildPhase, so providing one does nothing"; 69 + assert lib.asserts.assertMsg (useFakeRustfmt -> !rustfmtInNativeBuildInputs) 70 + "The parameter useFakeRustfmt is set to true, but rustfmt is included in nativeBuildInputs. Either set useFakeRustfmt to false or remove rustfmt from nativeBuildInputs."; 71 + assert lib.asserts.assertMsg (!useFakeRustfmt -> rustfmtInNativeBuildInputs) 72 + "The parameter useFakeRustfmt is set to false, but rustfmt is not included in nativeBuildInputs. Either set useFakeRustfmt to true or add rustfmt from nativeBuildInputs."; 73 + 74 + let 75 + fakeRustfmt = writeShellScriptBin "rustfmt" '' 76 + exit 0 77 + ''; 78 + maybeDebugFlag = lib.optionalString (buildType != "release") "--debug"; 79 + maybeEnterBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) '' 80 + export CARGO_TARGET_DIR="$(pwd)/target" 81 + pushd "${buildAndTestSubdir}" 82 + ''; 83 + maybeLeaveBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) "popd"; 84 + 85 + pgxPostgresMajor = lib.versions.major postgresql.version; 86 + preBuildAndTest = '' 87 + export PGX_HOME=$(mktemp -d) 88 + export PGDATA="$PGX_HOME/data-${pgxPostgresMajor}/" 89 + cargo-pgx pgx init "--pg${pgxPostgresMajor}" ${postgresql}/bin/pg_config 90 + echo "unix_socket_directories = '$(mktemp -d)'" > "$PGDATA/postgresql.conf" 91 + 92 + # This is primarily for Mac or other Nix systems that don't use the nixbld user. 93 + export USER="$(whoami)" 94 + pg_ctl start 95 + createuser -h localhost --superuser --createdb "$USER" || true 96 + pg_ctl stop 97 + ''; 98 + 99 + argsForBuildRustPackage = builtins.removeAttrs args [ "postgresql" "useFakeRustfmt" ]; 100 + 101 + # so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because 102 + # we forgot parentheses 103 + finalArgs = argsForBuildRustPackage // { 104 + buildInputs = (args.buildInputs or [ ]) ++ lib.optionals stdenv.isDarwin [ Security ]; 105 + 106 + nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ 107 + cargo-pgx 108 + postgresql 109 + pkg-config 110 + rustPlatform.bindgenHook 111 + ] ++ lib.optionals useFakeRustfmt [ fakeRustfmt ]; 112 + 113 + buildPhase = '' 114 + runHook preBuild 115 + 116 + echo "Executing cargo-pgx buildPhase" 117 + ${preBuildAndTest} 118 + ${maybeEnterBuildAndTestSubdir} 119 + 120 + NIX_PGLIBDIR="${postgresql}/lib" \ 121 + PGX_BUILD_FLAGS="--frozen -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " cargoBuildFlags}" \ 122 + cargo-pgx pgx package \ 123 + --pg-config ${postgresql}/bin/pg_config \ 124 + ${maybeDebugFlag} \ 125 + --features "${builtins.concatStringsSep " " buildFeatures}" \ 126 + --out-dir "$out" 127 + 128 + ${maybeLeaveBuildAndTestSubdir} 129 + 130 + runHook postBuild 131 + ''; 132 + 133 + preCheck = preBuildAndTest + args.preCheck or ""; 134 + 135 + installPhase = '' 136 + runHook preInstall 137 + 138 + echo "Executing buildPgxExtension install" 139 + 140 + ${maybeEnterBuildAndTestSubdir} 141 + 142 + cargo-pgx pgx stop all 143 + 144 + mv $out/${postgresql}/* $out 145 + rm -rf $out/nix 146 + 147 + ${maybeLeaveBuildAndTestSubdir} 148 + 149 + runHook postInstall 150 + ''; 151 + 152 + PGX_PG_SYS_SKIP_BINDING_REWRITE = "1"; 153 + CARGO_BUILD_INCREMENTAL = "false"; 154 + RUST_BACKTRACE = "full"; 155 + 156 + checkNoDefaultFeatures = true; 157 + checkFeatures = (args.checkFeatures or [ ]) ++ [ "pg_test pg${pgxPostgresMajor}" ]; 158 + }; 159 + in 160 + rustPlatform.buildRustPackage finalArgs
+42
pkgs/servers/sql/postgresql/ext/timescaledb_toolkit.nix
···
··· 1 + { lib 2 + , fetchFromGitHub 3 + , buildPgxExtension 4 + , postgresql 5 + , stdenv 6 + , nixosTests 7 + }: 8 + 9 + buildPgxExtension rec { 10 + inherit postgresql; 11 + 12 + pname = "timescaledb_toolkit"; 13 + version = "1.14.0"; 14 + 15 + src = fetchFromGitHub { 16 + owner = "timescale"; 17 + repo = "timescaledb-toolkit"; 18 + rev = version; 19 + sha256 = "sha256-ADmYALsCzZGqTX0XSkCif7ndvXwa8nEqddQpty4hbZ0="; 20 + }; 21 + 22 + cargoSha256 = "sha256-ukjJ11LmfG+k8D20rj68i43gOWUN80nf3hIAjUWXihI="; 23 + buildAndTestSubdir = "extension"; 24 + 25 + passthru.tests = { 26 + timescaledb_toolkit = nixosTests.timescaledb; 27 + }; 28 + 29 + # tests take really long 30 + doCheck = false; 31 + 32 + meta = with lib; { 33 + description = "Provide additional tools to ease all things analytic when using TimescaleDB"; 34 + homepage = "https://github.com/timescale/timescaledb-toolkit"; 35 + maintainers = with maintainers; [ typetetris ]; 36 + platforms = postgresql.meta.platforms; 37 + license = licenses.asl20; 38 + 39 + # as it needs to be used with timescaledb, simply use the condition from there 40 + broken = versionOlder postgresql.version "12"; 41 + }; 42 + }
+2
pkgs/servers/sql/postgresql/packages.nix
··· 56 57 timescaledb = super.callPackage ./ext/timescaledb.nix { }; 58 59 tsearch_extras = super.callPackage ./ext/tsearch_extras.nix { }; 60 61 tds_fdw = super.callPackage ./ext/tds_fdw.nix { };
··· 56 57 timescaledb = super.callPackage ./ext/timescaledb.nix { }; 58 59 + timescaledb_toolkit = super.callPackage ./ext/timescaledb_toolkit.nix { }; 60 + 61 tsearch_extras = super.callPackage ./ext/tsearch_extras.nix { }; 62 63 tds_fdw = super.callPackage ./ext/tds_fdw.nix { };
+3
pkgs/top-level/all-packages.nix
··· 15951 cargo-pgx = callPackage ../development/tools/rust/cargo-pgx { 15952 inherit (darwin.apple_sdk.frameworks) Security; 15953 }; 15954 cargo-release = callPackage ../development/tools/rust/cargo-release { }; 15955 cargo-rr = callPackage ../development/tools/rust/cargo-rr { }; 15956 cargo-tarpaulin = callPackage ../development/tools/analysis/cargo-tarpaulin {
··· 15951 cargo-pgx = callPackage ../development/tools/rust/cargo-pgx { 15952 inherit (darwin.apple_sdk.frameworks) Security; 15953 }; 15954 + buildPgxExtension = callPackage ../development/tools/rust/cargo-pgx/buildPgxExtension.nix { 15955 + inherit (darwin.apple_sdk.frameworks) Security; 15956 + }; 15957 cargo-release = callPackage ../development/tools/rust/cargo-release { }; 15958 cargo-rr = callPackage ../development/tools/rust/cargo-rr { }; 15959 cargo-tarpaulin = callPackage ../development/tools/analysis/cargo-tarpaulin {