diff --git a/ansible/vars.yml b/ansible/vars.yml index c72e5b1ba..f75dc903d 100644 --- a/ansible/vars.yml +++ b/ansible/vars.yml @@ -10,9 +10,9 @@ postgres_major: # Full version strings for each major version postgres_release: - postgresorioledb-17: "17.6.0.021-orioledb" - postgres17: "17.6.1.064" - postgres15: "15.14.1.064" + postgresorioledb-17: "17.6.0.021-orioledb-update-nixpkgs-1" + postgres17: "17.6.1.064-update-nixpkgs-1" + postgres15: "15.14.1.064-update-nixpkgs-1" # Non Postgres Extensions pgbouncer_release: 1.19.0 diff --git a/flake.lock b/flake.lock index a28edf942..bef513c6a 100644 --- a/flake.lock +++ b/flake.lock @@ -1,13 +1,33 @@ { "nodes": { + "devshell": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1764011051, + "narHash": "sha256-M7SZyPZiqZUR/EiiBJnmyUbOi5oE/03tCeFrTiUZchI=", + "owner": "numtide", + "repo": "devshell", + "rev": "17ed8d9744ebe70424659b0ef74ad6d41fc87071", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "lastModified": 1761588595, + "narHash": "sha256-XKUZz9zewJNUj46b4AJdiRZJAvSZ0Dqj2BNfXvFlJC4=", "owner": "edolstra", "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "rev": "f387cd2afec9419c8ee37694406ca490c3f34ee5", "type": "github" }, "original": { @@ -21,32 +41,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1749398372, - "narHash": "sha256-tYBdgS56eXYaWVW3fsnPQ/nFlgWi/Z2Ymhyu21zVM98=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "9305fe4e5c2a6fcf5ba6a3ff155720fbe4076569", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, - "flake-parts_2": { - "inputs": { - "nixpkgs-lib": [ - "nix-eval-jobs", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1759362264, - "narHash": "sha256-wfG0S7pltlYyZTM+qqlhJ7GMw2fTF4mLKCIVhLii/4M=", + "lastModified": 1763759067, + "narHash": "sha256-LlLt2Jo/gMNYAwOgdRQBrsRoOz7BPRkzvNaI/fzXi2Q=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "758cf7296bee11f1706a574c77d072b8a7baa881", + "rev": "2cccadc7357c0ba201788ae99c4dfa90728ef5e0", "type": "github" }, "original": { @@ -60,11 +59,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1705309234, - "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { @@ -82,11 +81,11 @@ ] }, "locked": { - "lastModified": 1750779888, - "narHash": "sha256-wibppH3g/E2lxU43ZQHC5yA/7kIKLGxVEnsnVK1BtRg=", + "lastModified": 1765016596, + "narHash": "sha256-rhSqPNxDVow7OQKi4qS5H8Au0P4S3AYbawBSmJNUtBQ=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "16ec914f6fb6f599ce988427d9d94efddf25fe6d", + "rev": "548fc44fca28a5e81c5d6b846e555e6b9c2a5a3c", "type": "github" }, "original": { @@ -155,39 +154,17 @@ "type": "github" } }, - "nix-fast-build": { + "nix-eval-jobs": { "inputs": { "flake-parts": [ "flake-parts" ], - "nixpkgs": [ - "nixpkgs" - ], + "nix": "nix", + "nixpkgs": "nixpkgs", "treefmt-nix": [ "treefmt-nix" ] }, - "locked": { - "lastModified": 1763868605, - "narHash": "sha256-wO8Lk66GPQeSpzXUzXCBpe2Pj1De17xByrROXxnwIPY=", - "owner": "Mic92", - "repo": "nix-fast-build", - "rev": "0c7fd47fb587250e931a01c6645ab5c0cd737af8", - "type": "github" - }, - "original": { - "owner": "Mic92", - "repo": "nix-fast-build", - "type": "github" - } - }, - "nix-eval-jobs": { - "inputs": { - "flake-parts": "flake-parts_2", - "nix": "nix", - "nixpkgs": "nixpkgs_2", - "treefmt-nix": "treefmt-nix" - }, "locked": { "lastModified": 1760478325, "narHash": "sha256-hA+NOH8KDcsuvH7vJqSwk74PyZP3MtvI/l+CggZcnTc=", @@ -204,19 +181,16 @@ }, "nix2container": { "inputs": { - "flake-utils": [ - "flake-utils" - ], "nixpkgs": [ "nixpkgs" ] }, "locked": { - "lastModified": 1708764364, - "narHash": "sha256-+pOtDvmuVTg0Gi58hKDUyrNla5NbyUvt3Xs3gLR0Fws=", + "lastModified": 1761716996, + "narHash": "sha256-vdOuy2pid2/DasUgb08lDOswdPJkN5qjXfBYItVy/R4=", "owner": "nlewo", "repo": "nix2container", - "rev": "c891f90d2e3c48a6b33466c96e4851e0fc0cf455", + "rev": "e5496ab66e9de9e3f67dc06f692dfbc471b6316e", "type": "github" }, "original": { @@ -226,69 +200,6 @@ } }, "nixpkgs": { - "locked": { - "lastModified": 1712666087, - "narHash": "sha256-WwjUkWsjlU8iUImbivlYxNyMB1L5YVqE8QotQdL9jWc=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "a76c4553d7e741e17f289224eda135423de0491d", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs-go124": { - "locked": { - "lastModified": 1754085309, - "narHash": "sha256-3RTSdhnqTcxS5wjKNEBpbt0hiSKfBZiQPlWHn90N1qQ=", - "owner": "Nixos", - "repo": "nixpkgs", - "rev": "d2ac4dfa61fba987a84a0a81555da57ae0b9a2b0", - "type": "github" - }, - "original": { - "owner": "Nixos", - "repo": "nixpkgs", - "rev": "d2ac4dfa61fba987a84a0a81555da57ae0b9a2b0", - "type": "github" - } - }, - "nixpkgs-lib": { - "locked": { - "lastModified": 1750555020, - "narHash": "sha256-/MjivcZIz8dyLOTFdJzS5Yazt2QCePQBh8uZooODaYw=", - "owner": "nix-community", - "repo": "nixpkgs.lib", - "rev": "6fb7349157ee1bffd053b1fdd454aa74ff7b4aee", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "nixpkgs.lib", - "type": "github" - } - }, - "nixpkgs-pgbackrest": { - "locked": { - "lastModified": 1761373498, - "narHash": "sha256-Q/uhWNvd7V7k1H1ZPMy/vkx3F8C13ZcdrKjO7Jv7v0c=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "6a08e6bb4e46ff7fcbb53d409b253f6bad8a28ce", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable-small", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { "locked": { "lastModified": 315532800, "narHash": "sha256-vhAtaRMIQiEghARviANBmSnhGz9Qf2IQJ+nQgsDXnVs=", @@ -301,67 +212,63 @@ "url": "https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz" } }, - "nixpkgs_3": { + "nixpkgs-lib": { "locked": { - "lastModified": 1697269602, - "narHash": "sha256-dSzV7Ud+JH4DPVD9od53EgDrxUVQOcSj4KGjggCDVJI=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "9cb540e9c1910d74a7e10736277f6eb9dff51c81", + "lastModified": 1761765539, + "narHash": "sha256-b0yj6kfvO8ApcSE+QmA6mUfu8IYG6/uU28OFn4PaC8M=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "719359f4562934ae99f5443f20aa06c2ffff91fc", "type": "github" }, "original": { - "owner": "NixOS", - "repo": "nixpkgs", + "owner": "nix-community", + "repo": "nixpkgs.lib", "type": "github" } }, - "nixpkgs_4": { + "nixpkgs-oldstable": { "locked": { "lastModified": 1712666087, "narHash": "sha256-WwjUkWsjlU8iUImbivlYxNyMB1L5YVqE8QotQdL9jWc=", - "owner": "nixos", + "owner": "NixOS", "repo": "nixpkgs", "rev": "a76c4553d7e741e17f289224eda135423de0491d", "type": "github" }, "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", + "owner": "NixOS", "repo": "nixpkgs", + "rev": "a76c4553d7e741e17f289224eda135423de0491d", "type": "github" } }, - "nixpkgs_5": { + "nixpkgs_2": { "locked": { - "lastModified": 1744536153, - "narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11", - "type": "github" + "lastModified": 1765186076, + "narHash": "sha256-fO54fp5kvvF8znmtV8QGwOsaBcB0NcFP41nC5Bhy/TM=", + "rev": "addf7cf5f383a3101ecfba091b98d0a1263dc9b8", + "type": "tarball", + "url": "https://releases.nixos.org/nixos/unstable/nixos-26.05pre908783.addf7cf5f383/nixexprs.tar.xz?lastModified=1765186076&rev=addf7cf5f383a3101ecfba091b98d0a1263dc9b8" }, "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" + "type": "tarball", + "url": "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz" } }, "root": { "inputs": { + "devshell": "devshell", "flake-parts": "flake-parts", "flake-utils": "flake-utils", "git-hooks": "git-hooks", "nix-editor": "nix-editor", - "nix-fast-build": "nix-fast-build", - "nix2container": "nix2container", - "nixpkgs": "nixpkgs", "nix-eval-jobs": "nix-eval-jobs", - "nixpkgs-go124": "nixpkgs-go124", - "nixpkgs-pgbackrest": "nixpkgs-pgbackrest", + "nix2container": "nix2container", + "nixpkgs": "nixpkgs_2", + "nixpkgs-oldstable": "nixpkgs-oldstable", "rust-overlay": "rust-overlay", - "treefmt-nix": "treefmt-nix_2" + "treefmt-nix": "treefmt-nix" } }, "rust-overlay": { @@ -371,11 +278,11 @@ ] }, "locked": { - "lastModified": 1764038373, - "narHash": "sha256-M6w2wNBRelcavoDAyFL2iO4NeWknD40ASkH1S3C0YGM=", + "lastModified": 1765248027, + "narHash": "sha256-ngar+yP06x3+2k2Iey29uU0DWx5ur06h3iPBQXlU+yI=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "ab3536fe850211a96673c6ffb2cb88aab8071cc9", + "rev": "7b50ad68415ae5be7ee4cc68fa570c420741b644", "type": "github" }, "original": { @@ -400,38 +307,17 @@ } }, "treefmt-nix": { - "inputs": { - "nixpkgs": [ - "nix-eval-jobs", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1760120816, - "narHash": "sha256-gq9rdocpmRZCwLS5vsHozwB6b5nrOBDNc2kkEaTXHfg=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "761ae7aff00907b607125b2f57338b74177697ed", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" - } - }, - "treefmt-nix_2": { "inputs": { "nixpkgs": [ "nixpkgs" ] }, "locked": { - "lastModified": 1750931469, - "narHash": "sha256-0IEdQB1nS+uViQw4k3VGUXntjkDp7aAlqcxdewb/hAc=", + "lastModified": 1762938485, + "narHash": "sha256-AlEObg0syDl+Spi4LsZIBrjw+snSVU4T8MOeuZJUJjM=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "ac8e6f32e11e9c7f153823abc3ab007f2a65d3e1", + "rev": "5b4ee75aeefd1e2d5a1cc43cf6ba65eba75e83e4", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index efd0b7e9e..2145185d1 100644 --- a/flake.nix +++ b/flake.nix @@ -7,28 +7,28 @@ ]; }; inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + devshell.url = "github:numtide/devshell"; + devshell.inputs.nixpkgs.follows = "nixpkgs"; + flake-parts.url = "github:hercules-ci/flake-parts"; flake-utils.url = "github:numtide/flake-utils"; - nix2container.url = "github:nlewo/nix2container"; - nix2container.inputs.nixpkgs.follows = "nixpkgs"; - nix2container.inputs.flake-utils.follows = "flake-utils"; - nix-editor.url = "github:snowfallorg/nix-editor"; - nix-editor.inputs.utils.follows = "flake-utils"; + git-hooks.inputs.nixpkgs.follows = "nixpkgs"; + git-hooks.url = "github:cachix/git-hooks.nix"; nix-editor.inputs.nixpkgs.follows = "nixpkgs"; - rust-overlay.url = "github:oxalica/rust-overlay"; + nix-editor.inputs.utils.follows = "flake-utils"; + nix-editor.url = "github:snowfallorg/nix-editor"; + nix-eval-jobs.inputs.flake-parts.follows = "flake-parts"; + nix-eval-jobs.inputs.treefmt-nix.follows = "treefmt-nix"; + nix-eval-jobs.url = "github:nix-community/nix-eval-jobs"; + nix2container.inputs.nixpkgs.follows = "nixpkgs"; + nix2container.url = "github:nlewo/nix2container"; + # Pin to a specific nixpkgs version that has compatible v8 and curl versions + # for extensions that require older package versions + nixpkgs-oldstable.url = "github:NixOS/nixpkgs/a76c4553d7e741e17f289224eda135423de0491d"; + nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"; rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; - nix-fast-build.url = "github:Mic92/nix-fast-build"; - nix-fast-build.inputs.flake-parts.follows = "flake-parts"; - nix-fast-build.inputs.nixpkgs.follows = "nixpkgs"; - nix-fast-build.inputs.treefmt-nix.follows = "treefmt-nix"; - flake-parts.url = "github:hercules-ci/flake-parts"; - treefmt-nix.url = "github:numtide/treefmt-nix"; + rust-overlay.url = "github:oxalica/rust-overlay"; treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; - git-hooks.url = "github:cachix/git-hooks.nix"; - git-hooks.inputs.nixpkgs.follows = "nixpkgs"; - nixpkgs-go124.url = "github:Nixos/nixpkgs/d2ac4dfa61fba987a84a0a81555da57ae0b9a2b0"; - nixpkgs-pgbackrest.url = "github:nixos/nixpkgs/nixos-unstable-small"; - nix-eval-jobs.url = "github:nix-community/nix-eval-jobs"; + treefmt-nix.url = "github:numtide/treefmt-nix"; }; outputs = diff --git a/migrations/schema-15.sql b/migrations/schema-15.sql index 20ecd988f..8f64dbda3 100644 --- a/migrations/schema-15.sql +++ b/migrations/schema-15.sql @@ -637,7 +637,7 @@ COMMENT ON TABLE auth.users IS 'Auth: Stores user login data within a secure sch -- CREATE TABLE public.schema_migrations ( - version character varying(128) NOT NULL + version character varying NOT NULL ); diff --git a/migrations/schema-17.sql b/migrations/schema-17.sql index da641e799..8017d8841 100644 --- a/migrations/schema-17.sql +++ b/migrations/schema-17.sql @@ -638,7 +638,7 @@ COMMENT ON TABLE auth.users IS 'Auth: Stores user login data within a secure sch -- CREATE TABLE public.schema_migrations ( - version character varying(128) NOT NULL + version character varying NOT NULL ); diff --git a/migrations/schema-orioledb-17.sql b/migrations/schema-orioledb-17.sql index 3c5e0ce56..b594bd502 100644 --- a/migrations/schema-orioledb-17.sql +++ b/migrations/schema-orioledb-17.sql @@ -652,7 +652,7 @@ COMMENT ON TABLE auth.users IS 'Auth: Stores user login data within a secure sch -- CREATE TABLE public.schema_migrations ( - version character varying(128) NOT NULL + version character varying NOT NULL ); diff --git a/nix/apps.nix b/nix/apps.nix index 75eaae49e..e277b7291 100644 --- a/nix/apps.nix +++ b/nix/apps.nix @@ -1,11 +1,11 @@ { ... }: { perSystem = - { self', ... }: + { self', lib, ... }: let - mkApp = attrName: binName: { + mkApp = attrName: { type = "app"; - program = "${self'.packages."${attrName}"}/bin/${binName}"; + program = lib.getExe self'.packages."${attrName}"; }; in { @@ -13,20 +13,20 @@ # these are distinct from the things that can be built with 'nix build', # so they need to be listed here too. apps = { - start-server = mkApp "start-server" "start-postgres-server"; - start-client = mkApp "start-client" "start-postgres-client"; - start-replica = mkApp "start-replica" "start-postgres-replica"; - # migrate-postgres = mkApp "migrate-tool" "migrate-postgres"; - # sync-exts-versions = mkApp "sync-exts-versions" "sync-exts-versions"; - pg-restore = mkApp "pg-restore" "pg-restore"; - local-infra-bootstrap = mkApp "local-infra-bootstrap" "local-infra-bootstrap"; - dbmate-tool = mkApp "dbmate-tool" "dbmate-tool"; - update-readme = mkApp "update-readme" "update-readme"; - show-commands = mkApp "show-commands" "show-commands"; - build-test-ami = mkApp "build-test-ami" "build-test-ami"; - run-testinfra = mkApp "run-testinfra" "run-testinfra"; - cleanup-ami = mkApp "cleanup-ami" "cleanup-ami"; - trigger-nix-build = mkApp "trigger-nix-build" "trigger-nix-build"; + start-server = mkApp "start-server"; + start-client = mkApp "start-client"; + start-replica = mkApp "start-replica"; + # migrate-postgres = mkApp "migrate-tool"; + # sync-exts-versions = mkApp "sync-exts-versions"; + pg-restore = mkApp "pg-restore"; + local-infra-bootstrap = mkApp "local-infra-bootstrap"; + dbmate-tool = mkApp "dbmate-tool"; + update-readme = mkApp "update-readme"; + show-commands = mkApp "show-commands"; + build-test-ami = mkApp "build-test-ami"; + run-testinfra = mkApp "run-testinfra"; + cleanup-ami = mkApp "cleanup-ami"; + trigger-nix-build = mkApp "trigger-nix-build"; }; }; } diff --git a/nix/cargo-pgrx/buildPgrxExtension.nix b/nix/cargo-pgrx/buildPgrxExtension.nix index 828dd7f02..a316015a5 100644 --- a/nix/cargo-pgrx/buildPgrxExtension.nix +++ b/nix/cargo-pgrx/buildPgrxExtension.nix @@ -32,7 +32,6 @@ pkg-config, rustPlatform, stdenv, - darwin, writeShellScriptBin, defaultBindgenHook, }: @@ -86,6 +85,27 @@ let fakeRustfmt = writeShellScriptBin "rustfmt" '' exit 0 ''; + + # Rustc wrapper for pgrx < 0.12.0 to filter out empty postmaster_stub.rs arguments + # This fixes an issue that causes build failures. + # Fixed upstream in pgcentralfoundation/pgrx#1435 and #1441, available from pgrx >= 0.12. + rustcWrapper = writeShellScriptBin "rustc" '' + # ORIGINAL_RUSTC is set in the buildPhase before this wrapper is added to PATH + original_rustc="''${ORIGINAL_RUSTC:-rustc}" + filtered_args=() + for arg in "$@"; do + if [[ -z "$arg" ]]; then + continue + fi + if [[ "$arg" =~ postmaster_stub\.rs$ ]]; then + if [[ ! -s "$arg" ]]; then + continue + fi + fi + filtered_args+=("$arg") + done + exec "$original_rustc" "''${filtered_args[@]}" + ''; maybeDebugFlag = lib.optionalString (buildType != "release") "--debug"; maybeEnterBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) '' export CARGO_TARGET_DIR="$(pwd)/target" @@ -94,6 +114,10 @@ let maybeLeaveBuildAndTestSubdir = lib.optionalString (buildAndTestSubdir != null) "popd"; pgrxBinaryName = if builtins.compareVersions "0.7.4" cargo-pgrx.version >= 0 then "pgx" else "pgrx"; + # The rustc wrapper is only needed for pgrx < 0.12.0 + # fixed upstream in pgcentralfoundation/pgrx#1435 and #1441 + needsRustcWrapper = builtins.compareVersions cargo-pgrx.version "0.12.0" < 0; + pgrxPostgresMajor = lib.versions.major postgresql.version; preBuildAndTest = '' export PGRX_HOME=$(mktemp -d) @@ -124,9 +148,7 @@ let # so we don't accidentally `(rustPlatform.buildRustPackage argsForBuildRustPackage) // { ... }` because # we forgot parentheses finalArgs = argsForBuildRustPackage // { - buildInputs = - (args.buildInputs or [ ]) - ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.Security ]; + buildInputs = (args.buildInputs or [ ]); nativeBuildInputs = (args.nativeBuildInputs or [ ]) @@ -147,6 +169,13 @@ let export PGRX_BUILD_FLAGS="--frozen -j $NIX_BUILD_CORES ${builtins.concatStringsSep " " cargoBuildFlags}" export PGX_BUILD_FLAGS="$PGRX_BUILD_FLAGS" + + ${lib.optionalString needsRustcWrapper '' + export ORIGINAL_RUSTC="$(command -v ${stdenv.cc.targetPrefix}rustc || command -v rustc)" + export PATH="${rustcWrapper}/bin:$PATH" + export RUSTC="${rustcWrapper}/bin/rustc" + ''} + ${lib.optionalString stdenv.hostPlatform.isDarwin ''RUSTFLAGS="''${RUSTFLAGS:+''${RUSTFLAGS} }-Clink-args=-Wl,-undefined,dynamic_lookup"''} \ cargo ${pgrxBinaryName} package \ --pg-config ${lib.getDev postgresql}/bin/pg_config \ diff --git a/nix/cargo-pgrx/default.nix b/nix/cargo-pgrx/default.nix index 86dfa4c19..87dbf6fe1 100644 --- a/nix/cargo-pgrx/default.nix +++ b/nix/cargo-pgrx/default.nix @@ -1,6 +1,5 @@ { lib, - darwin, fetchCrate, openssl, pkg-config, @@ -34,9 +33,7 @@ let src = fetchCrate { inherit version pname hash; }; inherit cargoHash; nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ pkg-config ]; - buildInputs = - lib.optionals stdenv.hostPlatform.isLinux [ openssl ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.Security ]; + buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ openssl ]; OPENSSL_DIR = "${openssl.dev}"; OPENSSL_INCLUDE_DIR = "${openssl.dev}/include"; @@ -73,17 +70,17 @@ in cargo-pgrx_0_12_6 = mkCargoPgrx { version = "0.12.6"; hash = "sha256-7aQkrApALZe6EoQGVShGBj0UIATnfOy2DytFj9IWdEA="; - cargoHash = "sha256-Di4UldQwAt3xVyvgQT1gUhdvYUVp7n/a72pnX45kP0w="; + cargoHash = "sha256-pnMxWWfvr1/AEp8DvG4awig8zjdHizJHoZ5RJA8CL08="; }; cargo-pgrx_0_12_9 = mkCargoPgrx { version = "0.12.9"; hash = "sha256-aR3DZAjeEEAjLQfZ0ZxkjLqTVMIEbU0UiZ62T4BkQq8="; - cargoHash = "sha256-KTKcol9qSNLQZGW32e6fBb6cPkUGItknyVpLdBYqrBY="; + cargoHash = "sha256-yZpD3FriL9UbzRtdFkfIfFfYIrRPYxr/lZ5rb0YBTPc="; }; cargo-pgrx_0_14_3 = mkCargoPgrx { version = "0.14.3"; hash = "sha256-3TsNpEqNm3Uol5XPW1i0XEbP2fF2+RKB2d7lO6BDnvQ="; - cargoHash = "sha256-Ny7j56pwB+2eEK62X0nWfFKQy5fBz+Q1oyvecivxLkk="; + cargoHash = "sha256-LZUXhjMxkBs3O5feH4X5NQC7Qk4Ja6M5+sAYaSCikrY="; }; inherit mkCargoPgrx; } diff --git a/nix/cargo-pgrx/versions.json b/nix/cargo-pgrx/versions.json index 422bd749c..7f28c940b 100644 --- a/nix/cargo-pgrx/versions.json +++ b/nix/cargo-pgrx/versions.json @@ -3,7 +3,7 @@ "hash": "sha256-O4eHVbJBudybsPab+zr2eXnfheREMqLAHAKm2GDbfrs=", "rust": { "1.82.0": { - "cargoHash": "sha256-MucGrA3qXgJOcT2LMNmoNOhQi8QA3LuqgZEHKycLCCo=" + "cargoHash": "sha256-lcnUVO8dJET5g6wM1YgTsj4uP4I3vVZy5PWBKIsvLB8=" } } }, @@ -11,7 +11,7 @@ "hash": "sha256-t/gdlrBeP6KFkBFJiZUa8KKVJVYMf6753vQGKJdytss=", "rust": { "1.82.0": { - "cargoHash": "sha256-muce9wT4LAJmfNLWWEShARnpZgglXe/KrfxlitmGgXk=" + "cargoHash": "sha256-bLS/pKJnwgcp38wAHej6vOkzVb/E2UHRCQ/OMDI6GqU=" } } }, @@ -19,7 +19,7 @@ "hash": "sha256-GpXQUOBuojAqPXyRR+k8AVW2XzBbn6V0+2dhP4w4Vs8=", "rust": { "1.70.0": { - "cargoHash": "sha256-YbwGh3tbt8W9/VOu11fTWO9fRMUlrwJnG4wxUHuyX10=" + "cargoHash": "sha256-TGeHOA5kRZ7KclRfYj6V+/ZbPiPx/4xUyKxNm4o7ubM=" } } }, @@ -27,7 +27,7 @@ "hash": "sha256-uDBq7tUZ9f8h5nlRFR1mv4+Ty1OFtAk5P7OTNQPI1gI=", "rust": { "1.70.0": { - "cargoHash": "sha256-YTkjqMNF+cz5XtELh7+l8KwvRoVKQP7t98nkJwkW218=" + "cargoHash": "sha256-uc1/zWMLt5U0egsf3xu/5RxouSl0m+81qY+ZZd8BSxU=" } } }, @@ -35,10 +35,10 @@ "hash": "sha256-FqjfbJmSy5UCpPPPk4bkEyvQCnaH9zYtkI7txgIn+ls=", "rust": { "1.70.0": { - "cargoHash": "sha256-syZ3cQq8qDHBLvqmNDGoxeK6zXHJ47Jwkw3uhaXNCzI=" + "cargoHash": "sha256-VlxXXSwegKGYIO3r3XtclwdtkJNz4r5H35Tkkw0nl9c=" }, "1.76.0": { - "cargoHash": "sha256-syZ3cQq8qDHBLvqmNDGoxeK6zXHJ47Jwkw3uhaXNCzI=" + "cargoHash": "sha256-VlxXXSwegKGYIO3r3XtclwdtkJNz4r5H35Tkkw0nl9c=" } } }, @@ -46,13 +46,13 @@ "hash": "sha256-8NlpMDFaltTIA8G4JioYm8LaPJ2RGKH5o6sd6lBHmmM=", "rust": { "1.70.0": { - "cargoHash": "sha256-qTb3JV3u42EilaK2jP9oa5D09mkuHyRbGGRs9Rg4TzI=" + "cargoHash": "sha256-TMuJ7kyMckCT4JJVWuEE14HpD5uw3Vjym96GA71vOMo=" }, "1.76.0": { - "cargoHash": "sha256-qTb3JV3u42EilaK2jP9oa5D09mkuHyRbGGRs9Rg4TzI=" + "cargoHash": "sha256-TMuJ7kyMckCT4JJVWuEE14HpD5uw3Vjym96GA71vOMo=" }, "1.85.1": { - "cargoHash": "sha256-CbU5B0pvB9ApTZOdYP/ZwuIG8bqGzk/ING2PCM0q2bQ=" + "cargoHash": "sha256-TMuJ7kyMckCT4JJVWuEE14HpD5uw3Vjym96GA71vOMo=" } } }, @@ -60,10 +60,10 @@ "hash": "sha256-UHIfwOdXoJvR4Svha6ud0FxahP1wPwUtviUwUnTmLXU=", "rust": { "1.76.0": { - "cargoHash": "sha256-j4HnD8Zt9uhlV5N7ldIy9564o9qFEqs5KfXHmnQ1WEw=" + "cargoHash": "sha256-giL077I5VzWJ+fAbxqp/Oc28Qjc7ontVm7of5LQz+uY=" }, "1.85.1": { - "cargoHash": "sha256-KBlT3FARjGcbtHIGDoC6ir3aNXXfDRmIoy990SOqoFg=" + "cargoHash": "sha256-giL077I5VzWJ+fAbxqp/Oc28Qjc7ontVm7of5LQz+uY=" } } }, @@ -71,10 +71,10 @@ "hash": "sha256-7aQkrApALZe6EoQGVShGBj0UIATnfOy2DytFj9IWdEA=", "rust": { "1.80.0": { - "cargoHash": "sha256-Di4UldQwAt3xVyvgQT1gUhdvYUVp7n/a72pnX45kP0w=" + "cargoHash": "sha256-pnMxWWfvr1/AEp8DvG4awig8zjdHizJHoZ5RJA8CL08=" }, "1.81.0": { - "cargoHash": "sha256-Di4UldQwAt3xVyvgQT1gUhdvYUVp7n/a72pnX45kP0w=" + "cargoHash": "sha256-pnMxWWfvr1/AEp8DvG4awig8zjdHizJHoZ5RJA8CL08=" } } }, @@ -82,13 +82,13 @@ "hash": "sha256-aR3DZAjeEEAjLQfZ0ZxkjLqTVMIEbU0UiZ62T4BkQq8=", "rust": { "1.81.0": { - "cargoHash": "sha256-53HKhvsKLTa2JCByLEcK3UzWXoM+LTatd98zvS1C9no=" + "cargoHash": "sha256-yZpD3FriL9UbzRtdFkfIfFfYIrRPYxr/lZ5rb0YBTPc=" }, "1.84.0": { - "cargoHash": "sha256-KTKcol9qSNLQZGW32e6fBb6cPkUGItknyVpLdBYqrBY=" + "cargoHash": "sha256-yZpD3FriL9UbzRtdFkfIfFfYIrRPYxr/lZ5rb0YBTPc=" }, "1.87.0": { - "cargoHash": "sha256-KTKcol9qSNLQZGW32e6fBb6cPkUGItknyVpLdBYqrBY=" + "cargoHash": "sha256-yZpD3FriL9UbzRtdFkfIfFfYIrRPYxr/lZ5rb0YBTPc=" } } }, @@ -96,7 +96,7 @@ "hash": "sha256-3TsNpEqNm3Uol5XPW1i0XEbP2fF2+RKB2d7lO6BDnvQ=", "rust": { "1.87.0": { - "cargoHash": "sha256-Ny7j56pwB+2eEK62X0nWfFKQy5fBz+Q1oyvecivxLkk=" + "cargoHash": "sha256-LZUXhjMxkBs3O5feH4X5NQC7Qk4Ja6M5+sAYaSCikrY=" } } }, @@ -104,7 +104,7 @@ "hash": "sha256-emNR7fXNVD9sY/Mdno7mwpH6l/7AD28cBUsFRn9je50=", "rust": { "1.87.0": { - "cargoHash": "sha256-pK6OxRNubcWhohLvIJIliRtaHSIQOhQp7Q9brPygZYA=" + "cargoHash": "sha256-3eyBDWDoCzSU0tbab8qbjSnBkkN0oOgd7YbuyHLEHYw=" } } }, @@ -112,9 +112,8 @@ "hash": "sha256-AjoBr+/sEPdzbD0wLUNVm2syCySkGaFOFQ70TST1U9w=", "rust": { "1.88.0": { - "cargoHash": "sha256-uWj/V2lJa6HF2GlHX+i5RbSMZFOxZsBzOf6okKDb0j8=" + "cargoHash": "sha256-95DHq5GLnAqb3bbKwwaeBeKEmkfRh81ZTRaJ7L59DAg=" } } } - } diff --git a/nix/checks.nix b/nix/checks.nix index 948d56acf..81c3a20ed 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -2,10 +2,9 @@ { perSystem = { - lib, self', - system, pkgs, + lib, ... }: let @@ -172,7 +171,6 @@ start-postgres-server-bin which getkey-script - supabase-groonga python3 netcat ]; @@ -258,7 +256,7 @@ export HTTP_MOCK_PORT #First we need to create a generic pg cluster for pgtap tests and run those - export GRN_PLUGINS_DIR=${pkgs.supabase-groonga}/lib/groonga/plugins + export GRN_PLUGINS_DIR=${pgroonga.passthru.groonga}/lib/groonga/plugins PGTAP_CLUSTER=$(mktemp -d) log info "Creating temporary PostgreSQL cluster at $PGTAP_CLUSTER" log_cmd initdb --locale=C --username=supabase_admin -D "$PGTAP_CLUSTER" @@ -391,10 +389,9 @@ ); inherit (self'.packages) wal-g-2 - dbmate-tool - packer pg_regress ; + devShell = self'.devShells.default; } // pkgs.lib.optionalAttrs (pkgs.stdenv.isLinux) ( { @@ -411,7 +408,6 @@ inherit self; inherit pkgs; }) - ) - // pkgs.lib.optionalAttrs (system == "x86_64-linux") ({ devShell = self'.devShells.default; }); + ); }; } diff --git a/nix/devShells.nix b/nix/devShells.nix index 03768a770..ef464b949 100644 --- a/nix/devShells.nix +++ b/nix/devShells.nix @@ -5,6 +5,7 @@ pkgs, self', config, + lib, ... }: let @@ -34,7 +35,7 @@ in { devShells = { - default = pkgs.mkShell { + default = pkgs.devshell.mkShell { packages = with pkgs; [ @@ -45,26 +46,99 @@ shellcheck ansible ansible-lint - self'.packages.packer - - self'.packages.start-server - self'.packages.start-client - self'.packages.start-replica - self'.packages.migrate-tool - self'.packages.sync-exts-versions - self'.packages.build-test-ami - self'.packages.run-testinfra - self'.packages.cleanup-ami + aws-vault + packer dbmate nushell pythonEnv config.treefmt.build.wrapper ] ++ self'.packages.docs.nativeBuildInputs; - shellHook = '' - export HISTFILE=.history - ${config.pre-commit.installationScript} - ''; + devshell.startup.pre-commit.text = config.pre-commit.installationScript; + commands = [ + { + name = "fmt"; + help = "Format code"; + command = "nix fmt"; + category = "check"; + } + { + name = "check"; + help = "Run all checks"; + command = "nix flake -L check -v"; + category = "check"; + } + { + name = "lint"; + help = "Lint code"; + command = "pre-commit run --all-files"; + category = "check"; + } + { + name = "watch"; + help = "Watch for file changes and run all checks"; + command = + let + watchExec = lib.getExe pkgs.watchexec; + nixFastBuild = '' + ${lib.getExe pkgs.nix} run github:Mic92/nix-fast-build -- \ + --skip-cached --retries=2 --no-download --option warn-dirty false \ + --option accept-flake-config true --no-link \ + --flake ".#checks.${pkgs.stdenv.hostPlatform.system}" + ''; + in + "${watchExec} --on-busy-update=queue -w . --ignore '.jj/*' --timings -- ${nixFastBuild}"; + category = "check"; + } + { + name = "cleanup-ami"; + help = "Deregister AMIs by name"; + command = "${lib.getExe self'.packages.cleanup-ami} $@"; + category = "ami"; + } + { + name = "build-test-ami"; + help = "Build AMI images for PostgreSQL testing"; + command = "${lib.getExe self'.packages.build-test-ami} $@"; + category = "ami"; + } + { + name = "sync-exts-versions"; + help = "Update extensions versions"; + command = "${lib.getExe self'.packages.sync-exts-versions}"; + category = "extension"; + } + { + name = "start-postgres-server"; + help = "Start a local Postgres server"; + command = "${lib.getExe pkgs.nix} run .#start-server -- $@"; + category = "postgres"; + } + { + name = "start-postgres-client"; + help = "Start an interactive psql with the specified Postgres version"; + command = "${lib.getExe pkgs.nix} run .#start-client -- $@"; + category = "postgres"; + } + { + name = "start-postgres-replica"; + help = "Start a local Postgres replica server"; + command = "${lib.getExe pkgs.nix} run .#start-replica -- $@"; + category = "postgres"; + } + { + name = "migrate-postgres"; + help = "Run database migrations"; + command = "${lib.getExe pkgs.nix} run .#migrate-tool -- $@"; + category = "postgres"; + } + { + name = "dbmate-tool"; + help = "Run dbmate against specified local Postgres database"; + command = "${lib.getExe pkgs.nix} run .#dbmate-tool -- $@"; + category = "postgres"; + } + ]; }; cargo-pgrx_0_11_3 = mkCargoPgrxDevShell { pgrxVersion = "0_11_3"; diff --git a/nix/ext/gdal.nix b/nix/ext/gdal.nix index 739f7e432..c4dba3e69 100644 --- a/nix/ext/gdal.nix +++ b/nix/ext/gdal.nix @@ -47,15 +47,14 @@ stdenv.mkDerivation rec { zlib ]; - cmakeFlags = - [ - "-DGDAL_USE_INTERNAL_LIBS=OFF" - "-DGEOTIFF_INCLUDE_DIR=${lib.getDev libgeotiff}/include" - "-DGEOTIFF_LIBRARY_RELEASE=${lib.getLib libgeotiff}/lib/libgeotiff${stdenv.hostPlatform.extensions.sharedLibrary}" - "-DBUILD_PYTHON_BINDINGS=OFF" - ] - ++ lib.optionals (!stdenv.isDarwin) [ "-DCMAKE_SKIP_BUILD_RPATH=ON" ] - ++ lib.optionals stdenv.isDarwin [ "-DCMAKE_BUILD_WITH_INSTALL_NAME_DIR=ON" ]; + cmakeFlags = [ + "-DGDAL_USE_INTERNAL_LIBS=OFF" + "-DGEOTIFF_INCLUDE_DIR=${lib.getDev libgeotiff}/include" + "-DGEOTIFF_LIBRARY_RELEASE=${lib.getLib libgeotiff}/lib/libgeotiff${stdenv.hostPlatform.extensions.sharedLibrary}" + "-DBUILD_PYTHON_BINDINGS=OFF" + ] + ++ lib.optionals (!stdenv.isDarwin) [ "-DCMAKE_SKIP_BUILD_RPATH=ON" ] + ++ lib.optionals stdenv.isDarwin [ "-DCMAKE_BUILD_WITH_INSTALL_NAME_DIR=ON" ]; enableParallelBuilding = true; diff --git a/nix/ext/pg_jsonschema/default.nix b/nix/ext/pg_jsonschema/default.nix index 1a2e8ee58..426c53dea 100644 --- a/nix/ext/pg_jsonschema/default.nix +++ b/nix/ext/pg_jsonschema/default.nix @@ -6,7 +6,6 @@ fetchFromGitHub, postgresql, rust-bin, - darwin, }: let pname = "pg_jsonschema"; @@ -45,10 +44,9 @@ let nativeBuildInputs = [ cargo ]; buildInputs = [ postgresql - ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.SystemConfiguration ]; + ]; # 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.1" "0.3.0" @@ -84,7 +82,17 @@ let cargo pgrx init --pg${lib.versions.major postgresql.version} $PGRX_HOME/${lib.versions.major postgresql.version}/bin/pg_config ''; - doCheck = true; + # Tests are disabled for specific versions because pgrx tests require + # `cargo pgrx install --test` which fails in the nix sandbox due to + # write permission restrictions. Unlike pg_graphql which has a custom + # installcheck script, pg_jsonschema only has pgrx cargo tests. + # See: https://github.com/supabase/pg_jsonschema/blob/v0.3.3/src/lib.rs#L45-L195 + doCheck = + !(builtins.elem version [ + "0.2.0" + "0.3.1" + "0.3.3" + ]); preBuild = '' echo "Processing git tags..." diff --git a/nix/ext/pg_net.nix b/nix/ext/pg_net.nix index 229971a81..60304138d 100644 --- a/nix/ext/pg_net.nix +++ b/nix/ext/pg_net.nix @@ -3,13 +3,16 @@ lib, stdenv, fetchFromGitHub, - curl, postgresql, libuv, makeWrapper, switch-ext-version, + curl_8_6, }: +let + curl = curl_8_6; +in let pname = "pg_net"; build = @@ -20,7 +23,8 @@ let buildInputs = [ curl postgresql - ] ++ lib.optional (version == "0.6") libuv; + ] + ++ lib.optional (version == "0.6") libuv; src = fetchFromGitHub { owner = "supabase"; @@ -45,7 +49,14 @@ let rm sql/pg_net--0.5.1--0.6.sql ''; - env.NIX_CFLAGS_COMPILE = lib.optionalString (lib.versionOlder version "0.19.1") "-Wno-error"; + env.NIX_CFLAGS_COMPILE = + if (lib.versionOlder version "0.19.1") then + "-Wno-error" + else if (version == "0.19.5" && stdenv.isDarwin && stdenv.isAarch64) then + # Fix for dangling pointer warning in src/core.c:177 on aarch64-darwin with newer clang + "-Wno-error=dangling-assignment" + else + ""; installPhase = '' mkdir -p $out/{lib,share/postgresql/extension} diff --git a/nix/ext/pgaudit.nix b/nix/ext/pgaudit.nix index 7660f2bd1..55dd237f7 100644 --- a/nix/ext/pgaudit.nix +++ b/nix/ext/pgaudit.nix @@ -184,22 +184,20 @@ buildEnv { echo "Found control version: $controlVer from package ${pkg}" # Create migrations from control version to all supported versions on this PG major - ${ - lib.concatMapStringsSep "\n" (targetVer: '' - # Skip if control version equals target version - if [[ "$controlVer" != "${targetVer}" ]]; then - # Skip if migration already exists - if [[ ! -f "$out/share/postgresql/extension/${pname}--$controlVer--${targetVer}.sql" ]]; then - # Create symlink to migration if target SQL exists - if [[ -f "$out/share/postgresql/extension/${pname}--${targetVer}.sql" ]]; then - echo "Creating migration symlink from control version $controlVer to ${targetVer}" - ln -s "$out/share/postgresql/extension/${pname}--${targetVer}.sql" \ - "$out/share/postgresql/extension/${pname}--$controlVer--${targetVer}.sql" - fi + ${lib.concatMapStringsSep "\n" (targetVer: '' + # Skip if control version equals target version + if [[ "$controlVer" != "${targetVer}" ]]; then + # Skip if migration already exists + if [[ ! -f "$out/share/postgresql/extension/${pname}--$controlVer--${targetVer}.sql" ]]; then + # Create symlink to migration if target SQL exists + if [[ -f "$out/share/postgresql/extension/${pname}--${targetVer}.sql" ]]; then + echo "Creating migration symlink from control version $controlVer to ${targetVer}" + ln -s "$out/share/postgresql/extension/${pname}--${targetVer}.sql" \ + "$out/share/postgresql/extension/${pname}--$controlVer--${targetVer}.sql" fi fi - '') versions - } + fi + '') versions} fi '') packages} diff --git a/nix/ext/pgroonga/default.nix b/nix/ext/pgroonga/default.nix index 22a8c2dfc..70878ce9d 100644 --- a/nix/ext/pgroonga/default.nix +++ b/nix/ext/pgroonga/default.nix @@ -9,10 +9,13 @@ makeWrapper, xxHash, buildEnv, - supabase-groonga, mecab-naist-jdic, + callPackage, }: let + # Import groonga locally since it's only used by pgroonga + supabase-groonga = callPackage ./groonga.nix { }; + pname = "pgroonga"; # Load version configuration from external file @@ -57,7 +60,8 @@ let msgpack-c supabase-groonga mecab - ] ++ lib.optionals stdenv.isDarwin [ xxHash ]; + ] + ++ lib.optionals stdenv.isDarwin [ xxHash ]; propagatedBuildInputs = [ supabase-groonga @@ -170,7 +174,13 @@ buildEnv { ''; passthru = { - inherit versions numberOfVersions pname; + inherit + versions + numberOfVersions + pname + supabase-groonga + ; + groonga = supabase-groonga; version = "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings [ "." ] [ "-" ] v) versions); }; diff --git a/nix/packages/groonga/default.nix b/nix/ext/pgroonga/groonga.nix similarity index 90% rename from nix/packages/groonga/default.nix rename to nix/ext/pgroonga/groonga.nix index bef491109..c6d734db6 100644 --- a/nix/packages/groonga/default.nix +++ b/nix/ext/pgroonga/groonga.nix @@ -36,21 +36,20 @@ stdenv.mkDerivation (finalAttrs: { pkg-config makeWrapper ]; - buildInputs = - [ - rapidjson - xxHash - zstd - mecab - kytea - msgpack-c - ] - ++ lib.optionals lz4Support [ lz4 ] - ++ lib.optional zlibSupport [ zlib ] - ++ lib.optionals suggestSupport [ - zeromq - libevent - ]; + buildInputs = [ + rapidjson + xxHash + zstd + mecab + kytea + msgpack-c + ] + ++ lib.optionals lz4Support [ lz4 ] + ++ lib.optional zlibSupport [ zlib ] + ++ lib.optionals suggestSupport [ + zeromq + libevent + ]; cmakeFlags = [ "-DWITH_MECAB=ON" "-DMECAB_DICDIR=${mecab-naist-jdic}/lib/mecab/dic/naist-jdic" diff --git a/nix/ext/pgrouting.nix b/nix/ext/pgrouting/default.nix similarity index 87% rename from nix/ext/pgrouting.nix rename to nix/ext/pgrouting/default.nix index 48833791e..a05101dd8 100644 --- a/nix/ext/pgrouting.nix +++ b/nix/ext/pgrouting/default.nix @@ -12,7 +12,7 @@ let pname = "pgrouting"; # Load version configuration from external file - allVersions = (builtins.fromJSON (builtins.readFile ./versions.json)).${pname}; + allVersions = (builtins.fromJSON (builtins.readFile ../versions.json)).${pname}; # Filter versions compatible with current PostgreSQL version supportedVersions = lib.filterAttrs ( @@ -49,18 +49,24 @@ let inherit hash; }; + patches = lib.optionals (version == "3.4.1" && lib.versionAtLeast postgresql.version "17") [ + ./pgrouting-3.4.1-pg17.patch + ]; + #disable compile time warnings for incompatible pointer types only on macos and pg16 NIX_CFLAGS_COMPILE = lib.optionalString ( stdenv.isDarwin && lib.versionAtLeast postgresql.version "16" ) "-Wno-error=int-conversion -Wno-error=incompatible-pointer-types"; - cmakeFlags = - [ "-DPOSTGRESQL_VERSION=${postgresql.version}" ] - ++ lib.optionals (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") [ - "-DCMAKE_MACOSX_RPATH=ON" - "-DCMAKE_SHARED_MODULE_SUFFIX=.dylib" - "-DCMAKE_SHARED_LIBRARY_SUFFIX=.dylib" - ]; + cmakeFlags = [ + "-DPOSTGRESQL_VERSION=${postgresql.version}" + "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" + ] + ++ lib.optionals (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") [ + "-DCMAKE_MACOSX_RPATH=ON" + "-DCMAKE_SHARED_MODULE_SUFFIX=.dylib" + "-DCMAKE_SHARED_LIBRARY_SUFFIX=.dylib" + ]; preConfigure = lib.optionalString (stdenv.isDarwin && lib.versionAtLeast postgresql.version "16") '' export DLSUFFIX=.dylib diff --git a/nix/ext/pgrouting/pgrouting-3.4.1-pg17.patch b/nix/ext/pgrouting/pgrouting-3.4.1-pg17.patch new file mode 100644 index 000000000..5f86e6c57 --- /dev/null +++ b/nix/ext/pgrouting/pgrouting-3.4.1-pg17.patch @@ -0,0 +1,39 @@ +From ce195442200452ae50b63528647e3837e9f121e0 Mon Sep 17 00:00:00 2001 +From: Yvan Sraka +Date: Thu, 4 Dec 2025 19:33:44 +0100 +Subject: [PATCH] Fix PostgreSQL 17 compatibility in SPI_getvalue calls + +SPI_getvalue already returns a char* in PostgreSQL 17, so wrapping +it in DatumGetCString (which expects a Datum) causes a compilation +error. This patch removes the unnecessary DatumGetCString wrapper +in both get_check_data.c and trsp.c files. +--- + src/common/get_check_data.c | 2 +- + src/trsp/trsp.c | 4 ++-- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/common/get_check_data.c b/src/common/get_check_data.c +index 85ea70d..82a81d1 100644 +--- a/src/common/get_check_data.c ++++ b/src/common/get_check_data.c +@@ -304,5 +304,5 @@ pgr_SPI_getFloat8(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { + */ + char* + pgr_SPI_getText(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info) { +- return DatumGetCString(SPI_getvalue(*tuple, *tupdesc, info.colNumber)); ++ return SPI_getvalue(*tuple, *tupdesc, info.colNumber); + } +diff --git a/src/trsp/trsp.c b/src/trsp/trsp.c +index 7f9397a..52b68dd 100644 +--- a/src/trsp/trsp.c ++++ b/src/trsp/trsp.c +@@ -114,8 +114,8 @@ fetch_restrict(HeapTuple *tuple, TupleDesc *tupdesc, + if (isnull) + elog(ERROR, "to_cost contains a null value"); + rest->to_cost = DatumGetFloat8(binval); +- char *str = DatumGetCString(SPI_getvalue(*tuple, *tupdesc, +- restrict_columns->via_path)); ++ char *str = SPI_getvalue(*tuple, *tupdesc, ++ restrict_columns->via_path); + + // PGR_DBG("restriction: %f, %i, %s", rest->to_cost, rest->target_id, str); diff --git a/nix/ext/plv8/default.nix b/nix/ext/plv8/default.nix index d858405ed..50927521b 100644 --- a/nix/ext/plv8/default.nix +++ b/nix/ext/plv8/default.nix @@ -2,7 +2,6 @@ stdenv, lib, fetchFromGitHub, - v8, perl, postgresql, # For passthru test on various systems, and local development on macos @@ -10,11 +9,11 @@ # to nixpkgs clang, xcbuild, - darwin, patchelf, buildEnv, nodejs_20, libcxx, + v8_oldstable, }: let @@ -36,6 +35,9 @@ let lib.mapAttrs (name: value: build name value.hash) supportedVersions ); + # plv8 3.1 requires an older version of v8 (we cannot use nodejs.libv8) + v8 = v8_oldstable; + # Build function for individual versions build = version: hash: @@ -43,6 +45,8 @@ let inherit pname version; #version = "3.1.10"; + v8 = (if (builtins.compareVersions "3.1.10" version >= 0) then v8 else nodejs_20.libv8); + src = fetchFromGitHub { owner = "plv8"; repo = "plv8"; @@ -50,49 +54,43 @@ let inherit hash; }; - patches = - [ - # Allow building with system v8. - # https://github.com/plv8/plv8/pull/505 (rejected) - ./0001-build-Allow-using-V8-from-system-${version}.patch - ] - ++ lib.optionals (builtins.compareVersions "3.1.10" version >= 0) [ - # Apply https://github.com/plv8/plv8/pull/552/ patch to fix extension upgrade problems - ./0001-fix-upgrade-related-woes-with-GUC-redefinitions-${version}.patch - ]; + patches = [ + # Allow building with system v8. + # https://github.com/plv8/plv8/pull/505 (rejected) + ./0001-build-Allow-using-V8-from-system-${version}.patch + ] + ++ lib.optionals (builtins.compareVersions "3.1.10" version >= 0) [ + # Apply https://github.com/plv8/plv8/pull/552/ patch to fix extension upgrade problems + ./0001-fix-upgrade-related-woes-with-GUC-redefinitions-${version}.patch + ]; - nativeBuildInputs = - [ perl ] - ++ lib.optionals stdenv.isDarwin [ - clang - xcbuild - ]; + nativeBuildInputs = [ + perl + ] + ++ lib.optionals stdenv.isDarwin [ + clang + xcbuild + ]; - buildInputs = - [ - (if (builtins.compareVersions "3.1.10" version >= 0) then v8 else nodejs_20.libv8) - postgresql - ] - ++ lib.optionals stdenv.isDarwin [ - darwin.apple_sdk.frameworks.CoreFoundation - darwin.apple_sdk.frameworks.Kerberos - ]; + buildInputs = [ + (if (builtins.compareVersions "3.1.10" version >= 0) then v8 else nodejs_20.libv8) + postgresql + ]; buildFlags = [ "all" ]; - makeFlags = - [ - # Nixpkgs build a v8 monolith instead of separate v8_libplatform. - "USE_SYSTEM_V8=1" - "V8_OUTDIR=${v8}/lib" - "PG_CONFIG=${postgresql}/bin/pg_config" - ] - ++ lib.optionals stdenv.isDarwin [ - "CC=${clang}/bin/clang" - "CXX=${clang}/bin/clang++" - "SHLIB_LINK=-L${v8}/lib -lv8_monolith -Wl,-rpath,${v8}/lib" - ] - ++ lib.optionals (!stdenv.isDarwin) [ "SHLIB_LINK=-lv8" ]; + makeFlags = [ + # Nixpkgs build a v8 monolith instead of separate v8_libplatform. + "USE_SYSTEM_V8=1" + "V8_OUTDIR=${v8}/lib" + "PG_CONFIG=${postgresql}/bin/pg_config" + ] + ++ lib.optionals stdenv.isDarwin [ + "CC=${clang}/bin/clang" + "CXX=${clang}/bin/clang++" + "SHLIB_LINK=-L${v8}/lib -lv8_monolith -Wl,-rpath,${v8}/lib -Wl,-headerpad_max_install_names" + ] + ++ lib.optionals (!stdenv.isDarwin) [ "SHLIB_LINK=-lv8" ]; NIX_LDFLAGS = lib.optionals stdenv.isDarwin [ "-L${postgresql}/lib" @@ -101,15 +99,14 @@ let "-lpq" "-lpgcommon" "-lpgport" - "-F${darwin.apple_sdk.frameworks.CoreFoundation}/Library/Frameworks" "-framework" "CoreFoundation" - "-F${darwin.apple_sdk.frameworks.Kerberos}/Library/Frameworks" "-framework" "Kerberos" "-undefined" "dynamic_lookup" "-flat_namespace" + "-headerpad_max_install_names" ]; # No configure script. @@ -144,11 +141,9 @@ let install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/$LIB_NAME ''} - ${ - lib.optionalString (!stdenv.isDarwin) '' - ${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${libcxx}/lib" $out/lib/$LIB_NAME - '' - } + ${lib.optionalString (!stdenv.isDarwin) '' + ${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${libcxx}/lib" $out/lib/$LIB_NAME + ''} else ${lib.optionalString stdenv.isDarwin '' install_name_tool -add_rpath "${v8}/lib" $out/lib/$LIB_NAME @@ -157,11 +152,9 @@ let install_name_tool -change @rpath/libv8_monolith.dylib ${v8}/lib/libv8_monolith.dylib $out/lib/$LIB_NAME ''} - ${ - lib.optionalString (!stdenv.isDarwin) '' - ${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${libcxx}/lib" $out/lib/$LIB_NAME - '' - } + ${lib.optionalString (!stdenv.isDarwin) '' + ${patchelf}/bin/patchelf --set-rpath "${v8}/lib:${postgresql}/lib:${libcxx}/lib" $out/lib/$LIB_NAME + ''} fi # plv8 3.2.x removed support for coffeejs and livescript diff --git a/nix/ext/postgis.nix b/nix/ext/postgis.nix index cdf48fb24..3989e8aae 100644 --- a/nix/ext/postgis.nix +++ b/nix/ext/postgis.nix @@ -16,10 +16,10 @@ nixosTests, callPackage, buildEnv, + sfcgal, }: let - sfcgal = callPackage ../packages/sfcgal.nix { }; gdal = callPackage ./gdal.nix { inherit postgresql; }; pname = "postgis"; @@ -79,7 +79,8 @@ let protobufc pcre2.dev sfcgal - ] ++ lib.optional stdenv.isDarwin libiconv; + ] + ++ lib.optional stdenv.isDarwin libiconv; nativeBuildInputs = [ perl pkg-config diff --git a/nix/ext/tests/default.nix b/nix/ext/tests/default.nix index 57644ee7f..fe6aa0276 100644 --- a/nix/ext/tests/default.nix +++ b/nix/ext/tests/default.nix @@ -29,6 +29,9 @@ let inherit (postgresql) version psqlSchema; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; + installedExtensions = [ (installedExtension majorVersion) ]; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ @@ -165,7 +168,7 @@ let server.wait_for_unit("multi-user.target") server.wait_for_unit("postgresql.service") - test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, ext_schema) + test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, ext_schema, lib_name) test.create_schema() with subtest("Check upgrade path with postgresql 15"): diff --git a/nix/ext/tests/http.nix b/nix/ext/tests/http.nix index f465da254..1477b6c4a 100644 --- a/nix/ext/tests/http.nix +++ b/nix/ext/tests/http.nix @@ -19,8 +19,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/lib.py b/nix/ext/tests/lib.py index d04f830fd..26bd42d49 100644 --- a/nix/ext/tests/lib.py +++ b/nix/ext/tests/lib.py @@ -5,7 +5,7 @@ installation, upgrades, and version verification of PostgreSQL extensions. """ -from typing import Sequence, Mapping +from typing import Sequence, Mapping, Optional from pathlib import Path from test_driver.machine import Machine @@ -21,6 +21,7 @@ def __init__( sql_test_dir: Path, support_upgrade: bool = True, schema: str = "public", + lib_name: Optional[str] = None, ): """Initialize the PostgreSQL extension test framework. @@ -30,6 +31,7 @@ def __init__( versions: Mapping of PostgreSQL versions to available extension versions sql_test_dir: Directory containing SQL test files for pg_regress support_upgrade: Whether the extension supports in-place upgrades + lib_name: Name of the shared library (defaults to extension_name) """ self.vm = vm self.extension_name = extension_name @@ -37,6 +39,7 @@ def __init__( self.support_upgrade = support_upgrade self.sql_test_dir = sql_test_dir self.schema = schema + self.lib_name = lib_name or extension_name def create_schema(self): self.run_sql(f"CREATE SCHEMA IF NOT EXISTS {self.schema};") @@ -93,9 +96,9 @@ def assert_version_matches(self, expected_version: str): AssertionError: If the installed version does not match the expected version """ installed_version = self.get_installed_version() - assert ( - installed_version == expected_version - ), f"Expected version {expected_version}, but found {installed_version}" + assert installed_version == expected_version, ( + f"Expected version {expected_version}, but found {installed_version}" + ) def check_upgrade_path(self, pg_version: str): """Test the complete upgrade path for a PostgreSQL version. @@ -163,9 +166,9 @@ def check_switch_extension_with_background_worker( f"No versions available for PostgreSQL version {pg_version}" ) last_version = available_versions[-1] - assert ext_version.endswith( - f"{last_version}.so" - ), f"Expected {self.extension_name} version {last_version}, but found {ext_version}" + assert ext_version.endswith(f"{self.lib_name}-{last_version}.so"), ( + f"Expected {self.extension_name} version {last_version}, but found {ext_version}" + ) # Switch to the first version first_version = available_versions[0] @@ -173,17 +176,17 @@ def check_switch_extension_with_background_worker( # Check that we are using the first version now ext_version = self.vm.succeed(f"readlink -f {extension_lib_path}").strip() - assert ext_version.endswith( - f"{first_version}.so" - ), f"Expected {self.extension_name} version {first_version}, but found {ext_version}" + assert ext_version.endswith(f"{self.lib_name}-{first_version}.so"), ( + f"Expected {self.extension_name} version {first_version}, but found {ext_version}" + ) # Switch to the last version self.vm.succeed(f"switch_{self.extension_name}_version {last_version}") # Check that we are using the last version now ext_version = self.vm.succeed(f"readlink -f {extension_lib_path}").strip() - assert ext_version.endswith( - f"{last_version}.so" - ), f"Expected {self.extension_name} version {last_version}, but found {ext_version}" + assert ext_version.endswith(f"{self.lib_name}-{last_version}.so"), ( + f"Expected {self.extension_name} version {last_version}, but found {ext_version}" + ) def check_pg_regress(self, pg_regress: Path, pg_version: str, test_name: str): """Run pg_regress tests for the extension on a given PostgreSQL version. diff --git a/nix/ext/tests/orioledb.nix b/nix/ext/tests/orioledb.nix index 7d0475cef..cc1b09b98 100644 --- a/nix/ext/tests/orioledb.nix +++ b/nix/ext/tests/orioledb.nix @@ -15,8 +15,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (self.legacyPackages.${pkgs.system}."psql_orioledb-17".exts.orioledb) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/pg_plan_filter.nix b/nix/ext/tests/pg_plan_filter.nix index c9efb4809..677c30ae3 100644 --- a/nix/ext/tests/pg_plan_filter.nix +++ b/nix/ext/tests/pg_plan_filter.nix @@ -19,8 +19,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/pg_repack.nix b/nix/ext/tests/pg_repack.nix index ff06a9b45..c02674d74 100644 --- a/nix/ext/tests/pg_repack.nix +++ b/nix/ext/tests/pg_repack.nix @@ -19,8 +19,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/pg_safeupdate.nix b/nix/ext/tests/pg_safeupdate.nix index 1c7e09c7f..a4431cfa5 100644 --- a/nix/ext/tests/pg_safeupdate.nix +++ b/nix/ext/tests/pg_safeupdate.nix @@ -19,8 +19,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/pgjwt.nix b/nix/ext/tests/pgjwt.nix index ef2e6b935..aede7e9a0 100644 --- a/nix/ext/tests/pgjwt.nix +++ b/nix/ext/tests/pgjwt.nix @@ -19,8 +19,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/pgmq.nix b/nix/ext/tests/pgmq.nix index b0c432921..7d96e057c 100644 --- a/nix/ext/tests/pgmq.nix +++ b/nix/ext/tests/pgmq.nix @@ -19,8 +19,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/pgroonga.nix b/nix/ext/tests/pgroonga.nix index abfef8804..1968655da 100644 --- a/nix/ext/tests/pgroonga.nix +++ b/nix/ext/tests/pgroonga.nix @@ -19,8 +19,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ @@ -81,9 +84,8 @@ self.inputs.nixpkgs.lib.nixos.runTest { self.packages.${pkgs.system}.mecab-naist-jdic }/lib/mecab/dic/naist-jdic"; systemd.services.postgresql.environment.MECAB_CONFIG = "${pkgs.mecab}/bin/mecab-config"; - systemd.services.postgresql.environment.GRN_PLUGINS_DIR = "${ - self.packages.${pkgs.system}.supabase-groonga - }/lib/groonga/plugins"; + systemd.services.postgresql.environment.GRN_PLUGINS_DIR = + "${(installedExtension "15").passthru.groonga}/lib/groonga/plugins"; specialisation.postgresql17.configuration = { services.postgresql = { diff --git a/nix/ext/tests/pgrouting.nix b/nix/ext/tests/pgrouting.nix index f4550b576..3fe656977 100644 --- a/nix/ext/tests/pgrouting.nix +++ b/nix/ext/tests/pgrouting.nix @@ -12,20 +12,22 @@ let majorVersion = lib.versions.major postgresql.version; pkg = pkgs.buildEnv { name = "postgresql-${majorVersion}-${pname}"; - paths = - [ - postgresql - postgresql.lib - (installedExtension majorVersion) - (self.legacyPackages.${pkgs.system}."psql_${majorVersion}".exts.postgis) - ] - ++ lib.optional (postgresql.isOrioleDB) ( - self.legacyPackages.${pkgs.system}."psql_orioledb-17".exts.orioledb - ); + paths = [ + postgresql + postgresql.lib + (installedExtension majorVersion) + (self.legacyPackages.${pkgs.system}."psql_${majorVersion}".exts.postgis) + ] + ++ lib.optional (postgresql.isOrioleDB) ( + self.legacyPackages.${pkgs.system}."psql_orioledb-17".exts.orioledb + ); passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/pgsodium.nix b/nix/ext/tests/pgsodium.nix index 0eae3c0a0..8fb945eeb 100644 --- a/nix/ext/tests/pgsodium.nix +++ b/nix/ext/tests/pgsodium.nix @@ -20,8 +20,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/plpgsql_check.nix b/nix/ext/tests/plpgsql_check.nix index 4d964ad9f..422a37982 100644 --- a/nix/ext/tests/plpgsql_check.nix +++ b/nix/ext/tests/plpgsql_check.nix @@ -19,8 +19,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/plv8.nix b/nix/ext/tests/plv8.nix index 26a349637..38c3a51b1 100644 --- a/nix/ext/tests/plv8.nix +++ b/nix/ext/tests/plv8.nix @@ -20,8 +20,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/postgis.nix b/nix/ext/tests/postgis.nix index f20e2de24..68bcbe381 100644 --- a/nix/ext/tests/postgis.nix +++ b/nix/ext/tests/postgis.nix @@ -19,8 +19,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/tests/timescaledb.nix b/nix/ext/tests/timescaledb.nix index 0cea7a507..16a286f15 100644 --- a/nix/ext/tests/timescaledb.nix +++ b/nix/ext/tests/timescaledb.nix @@ -19,8 +19,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ @@ -85,12 +88,12 @@ self.inputs.nixpkgs.lib.nixos.runTest { support_upgrade = True sql_test_directory = Path("${../../tests}") - test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade) + test = PostgresExtensionTest(server, extension_name, versions, sql_test_directory, support_upgrade, "public", "timescaledb-loader") with subtest("Check upgrade path with postgresql 15"): test.check_upgrade_path("15") with subtest("Test switch_${pname}_version"): - test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/${pname}.so"), "15") + test.check_switch_extension_with_background_worker(Path("${psql_15}/lib/timescaledb-loader.so"), "15") ''; } diff --git a/nix/ext/tests/vault.nix b/nix/ext/tests/vault.nix index a3f9cb24f..763f85f84 100644 --- a/nix/ext/tests/vault.nix +++ b/nix/ext/tests/vault.nix @@ -20,8 +20,11 @@ let ]; passthru = { inherit (postgresql) version psqlSchema; + installedExtensions = [ (installedExtension majorVersion) ]; lib = pkg; withPackages = _: pkg; + withJIT = pkg; + withoutJIT = pkg; }; nativeBuildInputs = [ pkgs.makeWrapper ]; pathsToLink = [ diff --git a/nix/ext/timescaledb.nix b/nix/ext/timescaledb.nix index 91605a48c..765ca5267 100644 --- a/nix/ext/timescaledb.nix +++ b/nix/ext/timescaledb.nix @@ -39,7 +39,8 @@ let "-DREGRESS_CHECKS=OFF" "-DTAP_CHECKS=OFF" "-DAPACHE_ONLY=1" - ] ++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ]; + ] + ++ lib.optionals stdenv.isDarwin [ "-DLINTER=OFF" ]; postPatch = '' for x in CMakeLists.txt sql/CMakeLists.txt; do @@ -107,6 +108,7 @@ let EXT_LOADER_TO_USE="$EXT_WRAPPER_LIB/$EXT_NAME-loader-$VERSION${postgresql.dlSuffix}" if [ -f "$EXT_LOADER_TO_USE" ]; then ln -sfnv "$EXT_LOADER_TO_USE" "$EXT_WRAPPER_LIB/$EXT_NAME${postgresql.dlSuffix}" + ln -sfnv "$EXT_LOADER_TO_USE" "$EXT_WRAPPER_LIB/$EXT_NAME-loader${postgresql.dlSuffix}" fi ''; }; @@ -124,6 +126,9 @@ buildEnv { # Create symlink from the latest versioned loader to timescaledb.so ln -sfn ${pname}-loader-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix} + # Create symlink for timescaledb-loader.so (used by background worker tests) + ln -sfn ${pname}-loader-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}-loader${postgresql.dlSuffix} + # The versioned extension libraries (timescaledb-VERSION.so) are already in place # checks - we should have loader files and versioned extension files @@ -142,6 +147,7 @@ buildEnv { passthru = { inherit versions numberOfVersions switch-ext-version; hasBackgroundWorker = true; + libName = "timescaledb-loader"; defaultSettings = { shared_preload_libraries = [ "timescaledb" ]; }; diff --git a/nix/ext/vault.nix b/nix/ext/vault.nix index cb90882a7..537febc0b 100644 --- a/nix/ext/vault.nix +++ b/nix/ext/vault.nix @@ -44,31 +44,30 @@ let inherit hash; }; - installPhase = - '' - mkdir -p $out/{lib,share/postgresql/extension} + installPhase = '' + mkdir -p $out/{lib,share/postgresql/extension} - # Create version-specific control file - sed -e "/^default_version =/d" \ - -e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}'|" \ - ${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control + # Create version-specific control file + sed -e "/^default_version =/d" \ + -e "s|^module_pathname = .*|module_pathname = '\$libdir/${pname}'|" \ + ${pname}.control > $out/share/postgresql/extension/${pname}--${version}.control - '' - # for versions <= 0.2.8, we don't have a library to install - + lib.optionalString (builtins.compareVersions "0.2.8" version < 0) '' - # Install shared library with version suffix - mv ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix} + '' + # for versions <= 0.2.8, we don't have a library to install + + lib.optionalString (builtins.compareVersions "0.2.8" version < 0) '' + # Install shared library with version suffix + mv ${pname}${postgresql.dlSuffix} $out/lib/${pname}-${version}${postgresql.dlSuffix} - # For the latest version, copy the sql files - if [[ "${version}" == "${latestVersion}" ]]; then - install -D -t $out/share/postgresql/extension sql/*.sql - { - echo "default_version = '${latestVersion}'" - cat $out/share/postgresql/extension/${pname}--${latestVersion}.control - } > $out/share/postgresql/extension/${pname}.control - fi - ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix} - ''; + # For the latest version, copy the sql files + if [[ "${version}" == "${latestVersion}" ]]; then + install -D -t $out/share/postgresql/extension sql/*.sql + { + echo "default_version = '${latestVersion}'" + cat $out/share/postgresql/extension/${pname}--${latestVersion}.control + } > $out/share/postgresql/extension/${pname}.control + fi + ln -sfn ${pname}-${latestVersion}${postgresql.dlSuffix} $out/lib/${pname}${postgresql.dlSuffix} + ''; meta = with lib; { description = "Store encrypted secrets in PostgreSQL"; diff --git a/nix/ext/wal2json.nix b/nix/ext/wal2json.nix index bd1e8ddd8..43ddab8df 100644 --- a/nix/ext/wal2json.nix +++ b/nix/ext/wal2json.nix @@ -10,7 +10,7 @@ let pname = "wal2json"; build = - version: rev: hash: + version: _rev: hash: stdenv.mkDerivation rec { inherit version pname; diff --git a/nix/ext/wrappers/default.nix b/nix/ext/wrappers/default.nix index c9f22dc4a..696358ea4 100644 --- a/nix/ext/wrappers/default.nix +++ b/nix/ext/wrappers/default.nix @@ -7,7 +7,6 @@ pkg-config, postgresql, buildEnv, - darwin, rust-bin, git, }: @@ -37,17 +36,10 @@ let cargo git ]; - buildInputs = - [ - openssl - postgresql - ] - ++ lib.optionals stdenv.isDarwin [ - darwin.apple_sdk.frameworks.CoreFoundation - darwin.apple_sdk.frameworks.CoreServices - darwin.apple_sdk.frameworks.Security - darwin.apple_sdk.frameworks.SystemConfiguration - ]; + buildInputs = [ + openssl + postgresql + ]; NIX_LDFLAGS = "-L${postgresql}/lib -lpq"; diff --git a/nix/nixpkgs.nix b/nix/nixpkgs.nix index 005dd80aa..34ba4bd60 100644 --- a/nix/nixpkgs.nix +++ b/nix/nixpkgs.nix @@ -10,6 +10,20 @@ overlays = [ (import inputs.rust-overlay) self.overlays.default + ( + let + # Provide older versions of packages required by some extensions + oldstable = import inputs.nixpkgs-oldstable { + inherit system; + config.allowUnfree = true; + }; + in + _final: _prev: { + curl_8_6 = oldstable.curl; + v8_oldstable = oldstable.v8; + } + ) + inputs.devshell.overlays.default ]; }; }; diff --git a/nix/overlays/default.nix b/nix/overlays/default.nix index 9c28c1082..046116cc2 100644 --- a/nix/overlays/default.nix +++ b/nix/overlays/default.nix @@ -10,7 +10,7 @@ postgresql_15 postgresql_17 postgresql_orioledb-17 - supabase-groonga + switch-ext-version mecab-naist-jdic ; @@ -19,7 +19,6 @@ cargo-pgrx = final.callPackage ../cargo-pgrx/default.nix { inherit (final) lib; - inherit (final) darwin; inherit (final) fetchCrate; inherit (final) openssl; inherit (final) pkg-config; diff --git a/nix/packages/build-test-ami.nix b/nix/packages/build-test-ami.nix index 9a1d4c5d6..99a16869a 100644 --- a/nix/packages/build-test-ami.nix +++ b/nix/packages/build-test-ami.nix @@ -1,23 +1,29 @@ -{ pkgs, runCommand }: -runCommand "build-test-ami" - { - buildInputs = with pkgs; [ - packer - awscli2 - yq - jq - openssl - git - coreutils - aws-vault - ]; - } - '' - mkdir -p $out/bin - cat > $out/bin/build-test-ami << 'EOL' - #!/usr/bin/env bash - set -euo pipefail - +{ + writeShellApplication, + packer, + awscli2, + yq, + jq, + openssl, + gitMinimal, + coreutils, + aws-vault, + python3, +}: +writeShellApplication { + name = "build-test-ami"; + runtimeInputs = [ + packer + awscli2 + yq + jq + openssl + gitMinimal + coreutils + aws-vault + python3 + ]; + text = '' show_help() { cat << EOF Usage: build-test-ami [--help] @@ -52,30 +58,6 @@ runCommand "build-test-ami" exit 0 fi - export PATH="${ - pkgs.lib.makeBinPath ( - with pkgs; - [ - packer - awscli2 - yq - jq - openssl - git - coreutils - aws-vault - ] - ) - }:$PATH" - - # Check for required tools - for cmd in packer aws-vault yq jq openssl; do - if ! command -v $cmd &> /dev/null; then - echo "Error: $cmd is required but not found" - exit 1 - fi - done - # Check AWS Vault profile if [ -z "''${AWS_VAULT:-}" ]; then echo "Error: AWS_VAULT environment variable must be set with the profile name" @@ -140,18 +122,18 @@ runCommand "build-test-ami" VENV_DIR=$(mktemp -d) trap 'rm -rf "$VENV_DIR"' EXIT HUP INT QUIT TERM python3 -m venv "$VENV_DIR" + # shellcheck source=/dev/null source "$VENV_DIR/bin/activate" # Install required Python packages echo "Installing required Python packages..." - pip install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest paramiko requests + pip install boto3 'boto3-stubs[essential]' docker ec2instanceconnectcli pytest paramiko requests # Run the tests with aws-vault echo "Running tests for AMI: $RANDOM_STRING using AWS Vault profile: $AWS_VAULT_PROFILE" - aws-vault exec $AWS_VAULT_PROFILE -- pytest -vv -s testinfra/test_ami_nix.py + aws-vault exec "$AWS_VAULT_PROFILE" -- pytest -vv -s testinfra/test_ami_nix.py # Deactivate virtual environment (cleanup is handled by trap) deactivate - EOL - chmod +x $out/bin/build-test-ami - '' + ''; +} diff --git a/nix/packages/cleanup-ami.nix b/nix/packages/cleanup-ami.nix index f1f9cde27..9bd670804 100644 --- a/nix/packages/cleanup-ami.nix +++ b/nix/packages/cleanup-ami.nix @@ -1,35 +1,15 @@ -{ pkgs, runCommand }: -runCommand "cleanup-ami" - { - buildInputs = with pkgs; [ - awscli2 - aws-vault - ]; - } - '' - mkdir -p $out/bin - cat > $out/bin/cleanup-ami << 'EOL' - #!/usr/bin/env bash - set -euo pipefail - - export PATH="${ - pkgs.lib.makeBinPath ( - with pkgs; - [ - awscli2 - aws-vault - ] - ) - }:$PATH" - - # Check for required tools - for cmd in aws-vault; do - if ! command -v $cmd &> /dev/null; then - echo "Error: $cmd is required but not found" - exit 1 - fi - done - +{ + writeShellApplication, + awscli2, + aws-vault, +}: +writeShellApplication { + name = "cleanup-ami"; + runtimeInputs = [ + awscli2 + aws-vault + ]; + text = '' # Check AWS Vault profile if [ -z "''${AWS_VAULT:-}" ]; then echo "Error: AWS_VAULT environment variable must be set with the profile name" @@ -56,6 +36,5 @@ runCommand "cleanup-ami" aws ec2 deregister-image --region $REGION --image-id "$ami_id" || true done done - EOL - chmod +x $out/bin/cleanup-ami - '' + ''; +} diff --git a/nix/packages/dbmate-tool.nix b/nix/packages/dbmate-tool.nix index 7ce2c5031..a4c71f034 100644 --- a/nix/packages/dbmate-tool.nix +++ b/nix/packages/dbmate-tool.nix @@ -1,5 +1,10 @@ { - pkgs, + writeShellApplication, + overmind, + dbmate, + nix, + jq, + yq, system, defaults, }: @@ -9,37 +14,316 @@ let pgbouncerAuthSchemaSql = ../../ansible/files/pgbouncer_config/pgbouncer_auth_schema.sql; statExtensionSql = ../../ansible/files/stat_extension.sql; in -pkgs.runCommand "dbmate-tool" - { - buildInputs = with pkgs; [ - overmind - dbmate - nix - jq - yq - ]; - nativeBuildInputs = with pkgs; [ makeWrapper ]; - } - '' - mkdir -p $out/bin $out/migrations - cp -r ${migrationsDir}/* $out - substitute ${../tools/dbmate-tool.sh.in} $out/bin/dbmate-tool \ - --subst-var-by 'PGSQL_DEFAULT_PORT' '${defaults.port}' \ - --subst-var-by 'MIGRATIONS_DIR' $out \ - --subst-var-by 'PGSQL_SUPERUSER' '${defaults.superuser}' \ - --subst-var-by 'ANSIBLE_VARS' ${ansibleVars} \ - --subst-var-by 'CURRENT_SYSTEM' '${system}' \ - --subst-var-by 'PGBOUNCER_AUTH_SCHEMA_SQL' '${pgbouncerAuthSchemaSql}' \ - --subst-var-by 'STAT_EXTENSION_SQL' '${statExtensionSql}' - chmod +x $out/bin/dbmate-tool - wrapProgram $out/bin/dbmate-tool \ - --prefix PATH : ${ - pkgs.lib.makeBinPath [ - pkgs.overmind - pkgs.dbmate - pkgs.nix - pkgs.jq - pkgs.yq - ] - } - '' +writeShellApplication { + name = "dbmate-tool"; + runtimeInputs = [ + overmind + dbmate + nix + jq + yq + ]; + text = '' + # Default values + PSQL_VERSION="ALL" + PORTNO="${defaults.port}" + PGSQL_SUPERUSER="${defaults.superuser}" + PGPASSWORD="''${PGPASSWORD:-postgres}" + PGSQL_USER="postgres" + FLAKE_URL="github:supabase/postgres" + MIGRATIONS_DIR="${migrationsDir}" + CURRENT_SYSTEM="${system}" + ANSIBLE_VARS="${ansibleVars}" + PGBOUNCER_AUTH_SCHEMA_SQL="${pgbouncerAuthSchemaSql}" + STAT_EXTENSION_SQL="${statExtensionSql}" + + # Start PostgreSQL using nix + start_postgres() { + DATDIR=$(mktemp -d) + echo "Starting PostgreSQL in directory: $DATDIR" # Create the DATDIR if it doesn't exist + nix run "$FLAKE_URL#start-server" -- "$PSQL_VERSION" --skip-migrations --daemonize --datdir "$DATDIR" + echo "PostgreSQL started." + } + + # Cleanup function + cleanup() { + echo "Cleaning up..." + + # Check if PostgreSQL processes exist + if pgrep -f "postgres" >/dev/null; then + echo "Stopping PostgreSQL gracefully..." + + # Use pg_ctl to stop PostgreSQL + pg_ctl -D "$DATDIR" stop + + # Wait a bit for graceful shutdown + sleep 5 + + # Check if processes are still running + if pgrep -f "postgres" >/dev/null; then + echo "Warning: Some PostgreSQL processes could not be stopped gracefully." + fi + else + echo "PostgreSQL is not running, skipping stop." + fi + + # Always exit successfully, log any remaining processes + if pgrep -f "postgres" >/dev/null; then + echo "Warning: Some PostgreSQL processes could not be cleaned up:" + pgrep -f "postgres" + else + echo "Cleanup completed successfully" + fi + } + + + # Function to display help + print_help() { + echo "Usage: nix run .#dbmate-tool -- [options]" + echo + echo "Options:" + echo " -v, --version [15|17|orioledb-17|all] Specify the PostgreSQL version to use (required defaults to --version all)" + echo " -p, --port PORT Specify the port number to use (default: 5435)" + echo " -h, --help Show this help message" + echo " -f, --flake-url URL Specify the flake URL to use (default: github:supabase/postgres)" + echo "Description:" + echo " Runs 'dbmate up' against a locally running the version of database you specify. Or 'all' to run against all versions." + echo " NOTE: To create a migration, you must run 'nix develop' and then 'dbmate new ' to create a new migration file." + echo + echo "Examples:" + echo " nix run .#dbmate-tool" + echo " nix run .#dbmate-tool -- --version 15" + echo " nix run .#dbmate-tool -- --version 16 --port 5433" + echo " nix run .#dbmate-tool -- --version 16 --port 5433 --flake-url github:supabase/postgres/" + } + + # Parse arguments + while [[ "$#" -gt 0 ]]; do + case "$1" in + -v|--version) + if [[ -n "$2" && ! "$2" =~ ^- ]]; then + PSQL_VERSION="$2" + shift 2 + else + echo "Error: --version requires an argument (15, 16, or orioledb-17)" + exit 1 + fi + ;; + -u|--user) + if [[ -n "$2" && ! "$2" =~ ^- ]]; then + PGSQL_USER="$2" + shift 2 + else + echo "Error: --user requires an argument" + exit 1 + fi + ;; + -f|--flake-url) + if [[ -n "$2" && ! "$2" =~ ^- ]]; then + FLAKE_URL="$2" + shift 2 + else + echo "Error: --flake-url requires an argument" + exit 1 + fi + ;; + -p|--port) + if [[ -n "$2" && ! "$2" =~ ^- ]]; then + PORTNO="$2" + shift 2 + else + echo "Error: --port requires an argument" + exit 1 + fi + ;; + -h|--help) + print_help + exit 0 + ;; + *) + echo "Unknown option: $1" + print_help + exit 1 + ;; + esac + done + + # Function to wait for PostgreSQL to be ready + wait_for_postgres() { + local max_attempts=30 # Increased significantly + local attempt=1 + + # Give PostgreSQL a moment to actually start the process + sleep 2 + + while [ $attempt -le $max_attempts ]; do + "''${PSQLBIN}/pg_isready" -h localhost -p "$PORTNO" -U "$PGSQL_SUPERUSER" -d postgres + local status=$? + + if [ $status -eq 0 ]; then + echo "PostgreSQL is ready!" + return 0 + fi + echo "Waiting for PostgreSQL to start (attempt $attempt/$max_attempts)..." + sleep 2 + attempt=$((attempt + 1)) + done + + echo "PostgreSQL failed to start after $max_attempts attempts" + return 1 + } + + check_orioledb_ready() { + local max_attempts=30 + local attempt=1 + + while [ $attempt -le $max_attempts ]; do + if "''${PSQLBIN}/psql" -v ON_ERROR_STOP=1 -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres -c "SELECT * FROM pg_am WHERE amname = 'orioledb'" | grep -q orioledb; then + echo "Orioledb extension is ready!" + return 0 + fi + echo "Waiting for orioledb to be ready (attempt $attempt/$max_attempts)..." + sleep 2 + attempt=$((attempt + 1)) + done + + echo "Orioledb failed to initialize after $max_attempts attempts" + return 1 + } + + perform_dump() { + local max_attempts=3 + local attempt=1 + + while [ $attempt -le $max_attempts ]; do + echo "Attempting pg_dump (attempt $attempt/$max_attempts)" + + # Build the dump command + local dump_cmd="''${PSQLBIN}/pg_dump -h localhost -p $PORTNO -U $PGSQL_SUPERUSER -d postgres --schema-only --no-owner --no-privileges" + + # Only use --restrict-key for standard PostgreSQL 15 and 17 versions + # OrioleDB doesn't support this flag yet + if [ "$PSQL_VERSION" = "15" ] || [ "$PSQL_VERSION" = "17" ] || [ "$PSQL_VERSION" = "orioledb-17" ]; then + # Use a fixed restrict key for reproducible test dumps + # This is safe in testing contexts but should not be used in production + dump_cmd="$dump_cmd --restrict-key=SupabaseTestDumpKey123" + echo "Using --restrict-key for reproducible dumps (PostgreSQL $PSQL_VERSION)" + else + echo "Skipping --restrict-key (version: $PSQL_VERSION)" + fi + + if $dump_cmd > "./db/schema.sql"; then + return 0 + fi + + echo "Dump attempt $attempt failed, waiting before retry..." + sleep 5 + attempt=$((attempt + 1)) + done + + echo "All dump attempts failed" + return 1 + } + + migrate_version() { + echo "PSQL_VERSION: $PSQL_VERSION" + #pkill -f "postgres" || true # Ensure PostgreSQL is stopped before starting + PSQLBIN=$(nix build --no-link "$FLAKE_URL#psql_$PSQL_VERSION/bin" --json | jq -r '.[].outputs.out + "/bin"') + echo "Using PostgreSQL version $PSQL_VERSION from $PSQLBIN" + + # Start PostgreSQL + start_postgres + echo "Waiting for PostgreSQL to be ready..." + + # Wait for PostgreSQL to be ready to accept connections + if ! wait_for_postgres; then + echo "Failed to connect to PostgreSQL server" + cleanup + exit 1 + fi + + if [ "$PSQL_VERSION" = "orioledb-17" ]; then + if ! check_orioledb_ready; then + echo "Failed to initialize orioledb extension" + exit 1 + fi + fi + + echo "PostgreSQL server is ready" + + # Configure PostgreSQL roles and permissions + if ! "''${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres <<-EOSQL + create role postgres superuser login password '$PGPASSWORD'; + alter database postgres owner to postgres; + EOSQL + then + echo "Failed to configure PostgreSQL roles and permissions" + exit 1 + fi + "''${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -d postgres -f "$PGBOUNCER_AUTH_SCHEMA_SQL" + "''${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -d postgres -f "$STAT_EXTENSION_SQL" + + # Set db url to run dbmate + export DATABASE_URL="postgres://$PGSQL_USER:$PGPASSWORD@localhost:$PORTNO/postgres?sslmode=disable" + # Export path so dbmate can find correct psql and pg_dump + export PATH="$PSQLBIN:$PATH" + # Run init scripts + if ! dbmate --migrations-dir "$MIGRATIONS_DIR/init-scripts" up; then + echo "Error: Initial migration failed" + exit 1 + fi + + # Password update command + if ! "''${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -c "ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD'"; then + echo "Error: Failed to update supabase_admin password" + exit 1 + fi + + # Set up database URL + export DATABASE_URL="postgres://$PGSQL_SUPERUSER:$PGPASSWORD@localhost:$PORTNO/postgres?sslmode=disable" + # Run migrations + if ! dbmate --migrations-dir "$MIGRATIONS_DIR/migrations" up; then + echo "Error: Final migration failed" + exit 1 + fi + + echo "Running dbmate dump with $PSQLBIN" + perform_dump + + echo "CURRENT_SYSTEM: $CURRENT_SYSTEM" + if [ -f "./db/schema.sql" ]; then + cp "./db/schema.sql" "./migrations/schema-$PSQL_VERSION.sql" + echo "Schema file moved to ./migrations/schema-$PSQL_VERSION.sql" + echo "PSQLBIN is $PSQLBIN" + else + echo "Warning: schema.sql file not found in ./db directory" + exit 1 + fi + + # If we get here, all commands succeeded + echo "PostgreSQL migration completed successfully" + echo "Check migrations are idempotent" + for sql in ./migrations/db/migrations/*.sql; do + echo "$0: running $sql" + "''${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres -f "$sql" || { + echo "Failed to execute $sql" + exit 1 + } + done + } + + if [ "$PSQL_VERSION" == "all" ]; then + VERSIONS=$(yq '.postgres_major[]' "$ANSIBLE_VARS" | tr -d '"') + echo "$VERSIONS" | while read -r version; do + PSQL_VERSION="$version" + echo "Migrating to PostgreSQL version $PSQL_VERSION" + migrate_version + cleanup + done + else + echo "Migrating to PostgreSQL version $PSQL_VERSION" + migrate_version + cleanup + fi + ''; +} diff --git a/nix/packages/default.nix b/nix/packages/default.nix index ed6bbdca4..9ae7f1531 100644 --- a/nix/packages/default.nix +++ b/nix/packages/default.nix @@ -29,7 +29,7 @@ { packages = ( { - build-ami = pkgs.callPackage ./build-ami.nix { packer = self'.packages.packer; }; + build-ami = pkgs.callPackage ./build-ami.nix { }; build-test-ami = pkgs.callPackage ./build-test-ami.nix { }; cleanup-ami = pkgs.callPackage ./cleanup-ami.nix { }; dbmate-tool = pkgs.callPackage ./dbmate-tool.nix { inherit (self.supabase) defaults; }; @@ -37,19 +37,17 @@ github-matrix = pkgs.callPackage ./github-matrix { nix-eval-jobs = inputs'.nix-eval-jobs.packages.default; }; - supabase-groonga = pkgs.callPackage ./groonga { }; + http-mock-server = pkgs.callPackage ./http-mock-server.nix { }; local-infra-bootstrap = pkgs.callPackage ./local-infra-bootstrap.nix { }; mecab-naist-jdic = pkgs.callPackage ./mecab-naist-jdic.nix { }; migrate-tool = pkgs.callPackage ./migrate-tool.nix { psql_15 = self'.packages."psql_15/bin"; }; overlayfs-on-package = pkgs.callPackage ./overlayfs-on-package.nix { }; - packer = pkgs.callPackage ./packer.nix { inherit inputs; }; - pg-backrest = inputs.nixpkgs-pgbackrest.legacyPackages.${pkgs.system}.pgbackrest; + pg-backrest = inputs.nixpkgs.legacyPackages.${pkgs.system}.pgbackrest; pg-restore = pkgs.callPackage ./pg-restore.nix { psql_15 = self'.packages."psql_15/bin"; }; pg_prove = pkgs.perlPackages.TAPParserSourceHandlerpgTAP; pg_regress = makePgRegress activeVersion; run-testinfra = pkgs.callPackage ./run-testinfra.nix { }; - sfcgal = pkgs.callPackage ./sfcgal.nix { }; show-commands = pkgs.callPackage ./show-commands.nix { }; start-client = pkgs.callPackage ./start-client.nix { psql_15 = self'.packages."psql_15/bin"; diff --git a/nix/packages/groonga/do-not-use-vendored-libraries.patch b/nix/packages/groonga/do-not-use-vendored-libraries.patch deleted file mode 100644 index 6a005349d..000000000 --- a/nix/packages/groonga/do-not-use-vendored-libraries.patch +++ /dev/null @@ -1,15 +0,0 @@ -Do not use vendored libraries - ---- a/vendor/CMakeLists.txt -+++ b/vendor/CMakeLists.txt -@@ -14,10 +14,7 @@ - # License along with this library; if not, write to the Free Software - # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - add_subdirectory(onigmo) --add_subdirectory(mruby) --add_subdirectory(mecab) --add_subdirectory(message_pack) - if(GRN_WITH_MRUBY) - add_subdirectory(groonga-log) - endif() \ No newline at end of file diff --git a/nix/packages/groonga/fix-cmake-install-path.patch b/nix/packages/groonga/fix-cmake-install-path.patch deleted file mode 100644 index 1fe317b6c..000000000 --- a/nix/packages/groonga/fix-cmake-install-path.patch +++ /dev/null @@ -1,21 +0,0 @@ -Fix CMake install path - ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -1141,11 +1141,11 @@ - - set(prefix "${CMAKE_INSTALL_PREFIX}") - set(exec_prefix "\${prefix}") --set(bindir "\${exec_prefix}/${CMAKE_INSTALL_BINDIR}") --set(sbindir "\${exec_prefix}/${CMAKE_INSTALL_SBINDIR}") --set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") --set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") --set(datarootdir "\${prefix}/${CMAKE_INSTALL_DATAROOTDIR}") -+set(bindir "${CMAKE_INSTALL_FULL_BINDIR}") -+set(sbindir "${CMAKE_INSTALL_FULL_SBINDIR}") -+set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}") -+set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") -+set(datarootdir "${CMAKE_INSTALL_FULL_DATAROOTDIR}") - set(datadir "\${datarootdir}") - set(expanded_pluginsdir "${GRN_PLUGINS_DIR}") - set(GRN_EXPANDED_DEFAULT_DOCUMENT_ROOT "${GRN_DEFAULT_DOCUMENT_ROOT}") \ No newline at end of file diff --git a/nix/packages/lib.nix b/nix/packages/lib.nix index cf541913d..3297dfb0b 100644 --- a/nix/packages/lib.nix +++ b/nix/packages/lib.nix @@ -3,7 +3,6 @@ psql_15, psql_orioledb-17, defaults, - supabase-groonga, system, }: { @@ -15,6 +14,7 @@ extraSubstitutions ? { }, }: let + supabase-groonga = pgroonga.passthru.groonga or (pkgs.callPackage ../ext/pgroonga/groonga.nix { }); paths = { migrationsDir = builtins.path { name = "migrations"; @@ -100,7 +100,8 @@ PGBOUNCER_AUTH_SCHEMA_SQL = "${paths.pgbouncerAuthSchemaSql}"; STAT_EXTENSION_SQL = "${paths.statExtensionSql}"; CURRENT_SYSTEM = "${system}"; - } // extraSubstitutions; # Merge in any extra substitutions + } + // extraSubstitutions; # Merge in any extra substitutions in pkgs.runCommand name { @@ -129,13 +130,11 @@ chmod 644 $out/etc/postgresql/pg_hba.conf substitute ${../tools/run-server.sh.in} $out/bin/start-postgres-server \ - ${ - builtins.concatStringsSep " " ( - builtins.attrValues ( - builtins.mapAttrs (name: value: "--subst-var-by '${name}' '${value}'") substitutions - ) + ${builtins.concatStringsSep " " ( + builtins.attrValues ( + builtins.mapAttrs (name: value: "--subst-var-by '${name}' '${value}'") substitutions ) - } + )} chmod +x $out/bin/start-postgres-server ''; } diff --git a/nix/packages/migrate-tool.nix b/nix/packages/migrate-tool.nix index 57f218a63..c98992110 100644 --- a/nix/packages/migrate-tool.nix +++ b/nix/packages/migrate-tool.nix @@ -1,18 +1,128 @@ -{ runCommand, psql_15 }: +{ writeShellApplication, psql_15 }: let configFile = ../tests/postgresql.conf.in; getkeyScript = ../tests/util/pgsodium_getkey.sh; primingScript = ../tests/prime.sql; migrationData = ../tests/migrations/data.sql; in -runCommand "migrate-postgres" { } '' - mkdir -p $out/bin - substitute ${../tools/migrate-tool.sh.in} $out/bin/migrate-postgres \ - --subst-var-by 'PSQL15_BINDIR' '${psql_15}' \ - --subst-var-by 'PSQL_CONF_FILE' '${configFile}' \ - --subst-var-by 'PGSODIUM_GETKEY' '${getkeyScript}' \ - --subst-var-by 'PRIMING_SCRIPT' '${primingScript}' \ - --subst-var-by 'MIGRATION_DATA' '${migrationData}' - - chmod +x $out/bin/migrate-postgres -'' +writeShellApplication { + name = "migrate-postgres"; + runtimeInputs = [ ]; + text = '' + # first argument is the old version; a path 15 or 16 + if [[ $1 == /nix/store* ]]; then + if [ ! -L "$1/receipt.json" ] || [ ! -e "$1/receipt.json" ]; then + echo "ERROR: $1 does not look like a valid Postgres install" + exit 1 + fi + OLDVER="$1" + elif [ "$1" == "15" ]; then + OLDVER="${psql_15}" + elif [ "$1" == "16" ]; then + echo "ERROR: PSQL 16 is not configured in this package" + exit 1 + else + echo "Please provide a valid Postgres version (15 or 16), or a /nix/store path" + exit 1 + fi + + # second argument is the new version; 15 or 16 + if [[ $2 == /nix/store* ]]; then + if [ ! -L "$2/receipt.json" ] || [ ! -e "$2/receipt.json" ]; then + echo "ERROR: $1 does not look like a valid Postgres install" + exit 1 + fi + NEWVER="$2" + elif [ "$2" == "15" ]; then + NEWVER="${psql_15}" + elif [ "$2" == "16" ]; then + echo "ERROR: PSQL 16 is not configured in this package" + exit 1 + else + echo "Please provide a valid Postgres version (15 or 16), or a /nix/store path" + exit 1 + fi + + # thid argument is the upgrade method: either pg_dumpall or pg_ugprade + if [ "$3" != "pg_dumpall" ] && [ "$3" != "pg_upgrade" ]; then + echo "Please provide a valid upgrade method (pg_dumpall or pg_upgrade)" + exit 1 + fi + UPGRADE_METHOD="$3" + + echo "Old server build: PSQL $1" + echo "New server build: PSQL $2" + echo "Upgrade method: $UPGRADE_METHOD" + + DATDIR=$(mktemp -d) + NEWDAT=$(mktemp -d) + mkdir -p "$DATDIR" "$NEWDAT" + + echo "NOTE: using temporary directory $DATDIR for PSQL $1 data, which will not be removed" + echo "NOTE: you are free to re-use this data directory at will" + echo + + "$OLDVER/bin/initdb" -D "$DATDIR" --locale=C --username=supabase_admin + "$NEWVER/bin/initdb" -D "$NEWDAT" --locale=C --username=supabase_admin + + # NOTE (aseipp): we need to patch postgresql.conf to have the right pgsodium_getkey script + PSQL_CONF_FILE="${configFile}" + PGSODIUM_GETKEY_SCRIPT="${getkeyScript}" + echo "NOTE: patching postgresql.conf files" + for x in "$DATDIR" "$NEWDAT"; do + sed \ + "s#@PGSODIUM_GETKEY_SCRIPT@#$PGSODIUM_GETKEY_SCRIPT#g" \ + "$PSQL_CONF_FILE" > "$x/postgresql.conf" + done + + echo "NOTE: Starting first server (v''${1}) to load data into the system" + "$OLDVER/bin/pg_ctl" start -D "$DATDIR" + + PRIMING_SCRIPT="${primingScript}" + MIGRATION_DATA="${migrationData}" + + "$OLDVER/bin/psql" -h localhost -d postgres -Xf "$PRIMING_SCRIPT" + "$OLDVER/bin/psql" -h localhost -d postgres -Xf "$MIGRATION_DATA" + + if [ "$UPGRADE_METHOD" == "pg_upgrade" ]; then + echo "NOTE: Stopping old server (v''${1}) to prepare for migration" + "$OLDVER/bin/pg_ctl" stop -D "$DATDIR" + + echo "NOTE: Migrating old data $DATDIR to $NEWDAT using pg_upgrade" + + export PGDATAOLD="$DATDIR" + export PGDATANEW="$NEWDAT" + export PGBINOLD="$OLDVER/bin" + export PGBINNEW="$NEWVER/bin" + + if ! "$NEWVER/bin/pg_upgrade" --check; then + echo "ERROR: pg_upgrade check failed" + exit 1 + fi + + echo "NOTE: pg_upgrade check passed, proceeding with migration" + "$NEWVER/bin/pg_upgrade" + rm -f delete_old_cluster.sh # we don't need this + exit 0 + fi + + if [ "$UPGRADE_METHOD" == "pg_dumpall" ]; then + SQLDAT="$DATDIR/dump.sql" + echo "NOTE: Exporting data via pg_dumpall ($SQLDAT)" + "$NEWVER/bin/pg_dumpall" -h localhost > "$SQLDAT" + + echo "NOTE: Stopping old server (v''${1}) to prepare for migration" + "$OLDVER/bin/pg_ctl" stop -D "$DATDIR" + + echo "NOTE: Starting second server (v''${2}) to load data into the system" + "$NEWVER/bin/pg_ctl" start -D "$NEWDAT" + + echo "NOTE: Loading data into new server (v''${2}) via 'cat | psql'" + cat "$SQLDAT" | "$NEWVER/bin/psql" -h localhost -d postgres + + printf "\n\n\n\n" + echo "NOTE: Done, check logs. Stopping the server; new database is located at $NEWDAT" + "$NEWVER/bin/pg_ctl" stop -D "$NEWDAT" + fi + ''; +} diff --git a/nix/packages/packer.nix b/nix/packages/packer.nix deleted file mode 100644 index 7f0063c30..000000000 --- a/nix/packages/packer.nix +++ /dev/null @@ -1,50 +0,0 @@ -{ - pkgs, - inputs, - lib, - fetchFromGitHub, - installShellFiles, - ... -}: -let - go124 = inputs.nixpkgs-go124.legacyPackages.${pkgs.system}.go_1_24; - buildGoModule = pkgs.buildGoModule.override { go = go124; }; -in -buildGoModule rec { - pname = "packer"; - version = "1.14.1"; - - src = fetchFromGitHub { - owner = "hashicorp"; - repo = "packer"; - rev = "v${version}"; - hash = "sha256-3g9hsmrfLzGhjcGvUza/L9PMGUFw+KLbg2pIK0CxlQI="; - }; - - vendorHash = "sha256-F6hn+pXPyPe70UTK8EF24lk7ArYz7ygUyVVsatW6+hI="; - - subPackages = [ "." ]; - - ldflags = [ - "-s" - "-w" - ]; - - nativeBuildInputs = [ installShellFiles ]; - - buildInputs = lib.optionals pkgs.stdenv.isDarwin [ - pkgs.darwin.apple_sdk.frameworks.IOKit - pkgs.darwin.apple_sdk.frameworks.Security - ]; - - postInstall = '' - installShellCompletion --zsh contrib/zsh-completion/_packer - ''; - - meta = { - description = "Tool for creating identical machine images for multiple platforms from a single source configuration"; - homepage = "https://www.packer.io"; - license = lib.licenses.bsl11; - changelog = "https://github.com/hashicorp/packer/blob/v${version}/CHANGELOG.md"; - }; -} diff --git a/nix/packages/postgres.nix b/nix/packages/postgres.nix index aa6cc9e4c..611f60542 100644 --- a/nix/packages/postgres.nix +++ b/nix/packages/postgres.nix @@ -25,7 +25,7 @@ ../ext/pgjwt.nix ../ext/pgaudit.nix ../ext/postgis.nix - ../ext/pgrouting.nix + ../ext/pgrouting ../ext/pgtap.nix ../ext/pg_cron ../ext/pgsql-http.nix diff --git a/nix/packages/sfcgal.nix b/nix/packages/sfcgal.nix deleted file mode 100644 index da962cbf8..000000000 --- a/nix/packages/sfcgal.nix +++ /dev/null @@ -1,52 +0,0 @@ -{ - lib, - stdenv, - fetchFromGitLab, - cgal, - cmake, - pkg-config, - gmp, - mpfr, - boost, -}: - -stdenv.mkDerivation rec { - pname = "sfcgal"; - version = "61f3b08ade49493b56c6bafa98c7c1f84addbc10"; - - src = fetchFromGitLab { - owner = "sfcgal"; - repo = "SFCGAL"; - rev = "${version}"; - hash = "sha256-nKSqiFyMkZAYptIeShb1zFg9lYSny3kcGJfxdeTFqxw="; - }; - - nativeBuildInputs = [ - cmake - pkg-config - cgal - gmp - mpfr - boost - ]; - - cmakeFlags = [ - "-DCGAL_DIR=${cgal}" - "-DCMAKE_PREFIX_PATH=${cgal}" - ]; - - postPatch = '' - substituteInPlace sfcgal.pc.in \ - --replace '$'{prefix}/@CMAKE_INSTALL_LIBDIR@ @CMAKE_INSTALL_FULL_LIBDIR@ - ''; - - meta = with lib; { - description = "A wrapper around CGAL that intents to implement 2D and 3D operations on OGC standards models"; - homepage = "https://sfcgal.gitlab.io/SFCGAL/"; - license = with licenses; [ - gpl3Plus - lgpl3Plus - ]; - platforms = platforms.all; - }; -} diff --git a/nix/packages/start-client.nix b/nix/packages/start-client.nix index 84ab06209..a8f4200d9 100644 --- a/nix/packages/start-client.nix +++ b/nix/packages/start-client.nix @@ -1,27 +1,103 @@ { - runCommand, + writeShellApplication, psql_15, psql_17, psql_orioledb-17, defaults, }: -let - migrationsDir = ../../migrations/db; - postgresqlSchemaSql = ../tools/postgresql_schema.sql; - pgbouncerAuthSchemaSql = ../../ansible/files/pgbouncer_config/pgbouncer_auth_schema.sql; - statExtensionSql = ../../ansible/files/stat_extension.sql; -in -runCommand "start-postgres-client" { } '' - mkdir -p $out/bin - substitute ${../tools/run-client.sh.in} $out/bin/start-postgres-client \ - --subst-var-by 'PGSQL_DEFAULT_PORT' '${defaults.port}' \ - --subst-var-by 'PGSQL_SUPERUSER' '${defaults.superuser}' \ - --subst-var-by 'PSQL15_BINDIR' '${psql_15}' \ - --subst-var-by 'PSQL17_BINDIR' '${psql_17}' \ - --subst-var-by 'PSQLORIOLEDB17_BINDIR' '${psql_orioledb-17}' \ - --subst-var-by 'MIGRATIONS_DIR' '${migrationsDir}' \ - --subst-var-by 'POSTGRESQL_SCHEMA_SQL' '${postgresqlSchemaSql}' \ - --subst-var-by 'PGBOUNCER_AUTH_SCHEMA_SQL' '${pgbouncerAuthSchemaSql}' \ - --subst-var-by 'STAT_EXTENSION_SQL' '${statExtensionSql}' - chmod +x $out/bin/start-postgres-client -'' +writeShellApplication { + name = "start-postgres-client"; + runtimeInputs = [ ]; + text = '' + # Default values + PSQL_VERSION="15" + PORTNO="${defaults.port}" + PSQL_USER="postgres" + + # Function to display help + print_help() { + echo "Usage: nix run .#start-client -- [options]" + echo + echo "Options:" + echo " -v, --version [15|17|orioledb-17] Specify the PostgreSQL version to use (default: 15)" + echo " -u, --user USER Specify the user/role to use (default: postgres)" + echo " -p, --port PORT Specify the port (default: ${defaults.port})" + echo " -h, --help Show this help message" + echo + echo "Description:" + echo " Starts an interactive 'psql' session connecting to a Postgres database started with the" + echo " 'nix run .#start-server' command." + echo + echo "Examples:" + echo " nix run .#start-client" + echo " nix run .#start-client -- --version 15" + echo " nix run .#start-client -- --version 17 --port 5433" + echo " nix run .#start-client -- --version 17 --user supabase_admin" + } + + # Parse arguments + while [[ "$#" -gt 0 ]]; do + case "$1" in + -v|--version) + if [[ -n "$2" && ! "$2" =~ ^- ]]; then + PSQL_VERSION="$2" + shift 2 + else + echo "Error: --version requires an argument (15, 17, or orioledb-17)" + exit 1 + fi + ;; + -u|--user) + if [[ -n "$2" && ! "$2" =~ ^- ]]; then + PSQL_USER="$2" + shift 2 + else + echo "Error: --user requires an argument" + exit 1 + fi + ;; + -p|--port) + if [[ -n "$2" && ! "$2" =~ ^- ]]; then + PORTNO="$2" + shift 2 + else + echo "Error: --port requires an argument" + exit 1 + fi + ;; + -h|--help) + print_help + exit 0 + ;; + *) + echo "Unknown option: $1" + print_help + exit 1 + ;; + esac + done + + # Determine PostgreSQL version + if [ "$PSQL_VERSION" == "15" ]; then + echo "Starting client for PSQL 15" + BINDIR="${psql_15}" + elif [ "$PSQL_VERSION" == "17" ]; then + echo "Starting client for PSQL 17" + BINDIR="${psql_17}" + elif [ "$PSQL_VERSION" == "orioledb-17" ]; then + echo "Starting client for PSQL ORIOLEDB 17" + BINDIR="${psql_orioledb-17}" + else + echo "Please provide a valid Postgres version (15, 17, or orioledb-17)" + exit 1 + fi + + # Set up environment for psql + export PATH="$BINDIR/bin:$PATH" + export POSTGRES_DB=postgres + export POSTGRES_HOST=localhost + + # Start interactive psql session + exec psql -U "$PSQL_USER" -p "$PORTNO" -h localhost postgres + ''; +} diff --git a/nix/packages/start-replica.nix b/nix/packages/start-replica.nix index 129ccd9cc..bd63764fa 100644 --- a/nix/packages/start-replica.nix +++ b/nix/packages/start-replica.nix @@ -1,12 +1,48 @@ { - runCommand, + writeShellApplication, pgsqlSuperuser, psql_15, }: -runCommand "start-postgres-replica" { } '' - mkdir -p $out/bin - substitute ${./start-replica.sh.in} $out/bin/start-postgres-replica \ - --subst-var-by 'PGSQL_SUPERUSER' '${pgsqlSuperuser}' \ - --subst-var-by 'PSQL15_BINDIR' '${psql_15}' - chmod +x $out/bin/start-postgres-replica -'' +writeShellApplication { + name = "start-postgres-replica"; + runtimeInputs = [ ]; + text = '' + # first argument should be '15' or '16' for the version + if [ "$1" == "15" ]; then + echo "Starting server for PSQL 15" + BINDIR="${psql_15}" + elif [ "$1" == "16" ]; then + echo "Starting server for PSQL 16" + echo "Error: PSQL 16 is not configured in this package" + exit 1 + elif [ "$1" == "orioledb-16" ]; then + echo "Starting server for PSQL ORIOLEDB 16" + echo "Error: PSQL ORIOLEDB 16 is not configured in this package" + exit 1 + else + echo "Please provide a valid Postgres version (15, 16 or orioledb-16)" + exit 1 + fi + + export PATH="$BINDIR/bin:$PATH" + + PGSQL_SUPERUSER="${pgsqlSuperuser}" + MASTER_PORTNO="$2" + REPLICA_PORTNO="$3" + REPLICA_SLOT="replica_$RANDOM" + DATDIR=$(mktemp -d) + mkdir -p "$DATDIR" + + echo "NOTE: runing pg_basebackup for server on port $MASTER_PORTNO" + echo "NOTE: using replica slot $REPLICA_SLOT" + + pg_basebackup -p "$MASTER_PORTNO" -h localhost -U "''${PGSQL_SUPERUSER}" -X stream -C -S "$REPLICA_SLOT" -v -R -D "$DATDIR" + + echo "NOTE: using port $REPLICA_PORTNO for replica" + echo "NOTE: using temporary directory $DATDIR for data, which will not be removed" + echo "NOTE: you are free to re-use this data directory at will" + echo + + exec postgres -p "$REPLICA_PORTNO" -D "$DATDIR" -k /tmp + ''; +} diff --git a/nix/packages/start-replica.sh.in b/nix/packages/start-replica.sh.in deleted file mode 100644 index e2096b17a..000000000 --- a/nix/packages/start-replica.sh.in +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash -# shellcheck shell=bash - -[ ! -z "$DEBUG" ] && set -x - -# first argument should be '15' or '16' for the version -if [ "$1" == "15" ]; then - echo "Starting server for PSQL 15" - PSQL15=@PSQL15_BINDIR@ - BINDIR="$PSQL15" -elif [ "$1" == "16" ]; then - echo "Starting server for PSQL 16" - PSQL16=@PSQL16_BINDIR@ - BINDIR="$PSQL16" -elif [ "$1" == "orioledb-16" ]; then - echo "Starting server for PSQL ORIOLEDB 16" - PSQLORIOLEDB16=@PSQLORIOLEDB16_BINDIR@ - BINDIR="$PSQLORIOLEDB16" -else - echo "Please provide a valid Postgres version (15, 16 or orioledb-16)" - exit 1 -fi - -export PATH=$BINDIR/bin:$PATH - -PGSQL_SUPERUSER=@PGSQL_SUPERUSER@ -MASTER_PORTNO="$2" -REPLICA_PORTNO="$3" -REPLICA_SLOT="replica_$RANDOM" -DATDIR=$(mktemp -d) -mkdir -p "$DATDIR" - -echo "NOTE: runing pg_basebackup for server on port $MASTER_PORTNO" -echo "NOTE: using replica slot $REPLICA_SLOT" - -pg_basebackup -p "$MASTER_PORTNO" -h localhost -U "${PGSQL_SUPERUSER}" -X stream -C -S "$REPLICA_SLOT" -v -R -D "$DATDIR" - -echo "NOTE: using port $REPLICA_PORTNO for replica" -echo "NOTE: using temporary directory $DATDIR for data, which will not be removed" -echo "NOTE: you are free to re-use this data directory at will" -echo - -exec postgres -p "$REPLICA_PORTNO" -D "$DATDIR" -k /tmp diff --git a/nix/packages/sync-exts-versions.nix b/nix/packages/sync-exts-versions.nix index d76e66553..c660a66c6 100644 --- a/nix/packages/sync-exts-versions.nix +++ b/nix/packages/sync-exts-versions.nix @@ -1,17 +1,17 @@ { - runCommand, + writeShellApplication, jq, yq, nix-editor, - nixVersions, + nix, }: -runCommand "sync-exts-versions" { } '' - mkdir -p $out/bin - substitute ${../tools/sync-exts-versions.sh.in} $out/bin/sync-exts-versions \ - --subst-var-by 'YQ' '${yq}/bin/yq' \ - --subst-var-by 'JQ' '${jq}/bin/jq' \ - --subst-var-by 'NIX_EDITOR' '${nix-editor.packages.nix-editor}/bin/nix-editor' \ - --subst-var-by 'NIXPREFETCHURL' '${nixVersions.nix_2_20}/bin/nix-prefetch-url' \ - --subst-var-by 'NIX' '${nixVersions.nix_2_20}/bin/nix' - chmod +x $out/bin/sync-exts-versions -'' +writeShellApplication { + name = "sync-exts-versions"; + runtimeInputs = [ + jq + yq + nix-editor.packages.nix-editor + nix + ]; + text = builtins.readFile ../tools/sync-exts-versions.sh.in; +} diff --git a/nix/postgresql/generic.nix b/nix/postgresql/generic.nix index ea67cbc91..95034e060 100644 --- a/nix/postgresql/generic.nix +++ b/nix/postgresql/generic.nix @@ -12,7 +12,7 @@ let zlib, readline, openssl, - icu, + icu75, lz4, zstd, systemd, @@ -21,6 +21,7 @@ let libxml2, tzdata, libkrb5, + replaceVars, darwin, linux-pam, #orioledb specific @@ -65,7 +66,7 @@ let # for <13 (where it got removed: https://github.com/postgres/postgres/commit/c45643d618e35ec2fe91438df15abd4f3c0d85ca) libxcrypt, - isOrioleDB ? false, + isOrioleDB ? (builtins.match "[0-9][0-9]_.*" version) != null, }@args: let atLeast = lib.versionAtLeast version; @@ -105,7 +106,8 @@ let inherit hash; }; - hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ]; + # The 'pie' hardening flag has been removed in favor of enabling PIE by default in compilers and should no longer be used. + # hardeningEnable = lib.optionals (!stdenv'.cc.isClang) [ "pie" ]; outputs = [ "out" @@ -113,47 +115,48 @@ let ]; setOutputFlags = false; # $out retains configureFlags :-/ - buildInputs = - [ - zlib - readline - openssl - (libxml2.override { python = python3; }) - icu - ] - ++ lib.optionals (olderThan "13") [ libxcrypt ] - ++ lib.optionals jitSupport [ llvmPackages.llvm ] - ++ lib.optionals lz4Enabled [ lz4 ] - ++ lib.optionals zstdEnabled [ zstd ] - ++ lib.optionals systemdSupport' [ systemd ] - ++ lib.optionals pythonSupport [ python3 ] - ++ lib.optionals gssSupport [ libkrb5 ] - ++ lib.optionals stdenv'.isLinux [ linux-pam ] - ++ lib.optionals (!stdenv'.isDarwin) [ libossp_uuid ] - ++ lib.optionals (isOrioleDB || (lib.versionAtLeast version "17")) [ - perl - bison - flex - docbook_xsl - docbook_xml_dtd_45 - docbook_xsl_ns - libxslt - ]; + buildInputs = [ + zlib + readline + openssl + (libxml2.override { python3 = python3; }) + # Pin ICU to version 75 to maintain collation version 153.120 + # This prevents collation mismatch warnings when upgrading nixpkgs + icu75 + ] + ++ lib.optionals (olderThan "13") [ libxcrypt ] + ++ lib.optionals jitSupport [ llvmPackages.llvm ] + ++ lib.optionals lz4Enabled [ lz4 ] + ++ lib.optionals zstdEnabled [ zstd ] + ++ lib.optionals systemdSupport' [ systemd ] + ++ lib.optionals pythonSupport [ python3 ] + ++ lib.optionals gssSupport [ libkrb5 ] + ++ lib.optionals stdenv'.isLinux [ linux-pam ] + ++ lib.optionals (!stdenv'.isDarwin) [ libossp_uuid ] + ++ lib.optionals (isOrioleDB || (lib.versionAtLeast version "17")) [ + perl + bison + flex + docbook_xsl + docbook_xml_dtd_45 + docbook_xsl_ns + libxslt + ]; - nativeBuildInputs = - [ - makeWrapper - pkg-config - ] - ++ lib.optionals jitSupport [ - llvmPackages.llvm.dev - nukeReferences - patchelf - ]; + nativeBuildInputs = [ + makeWrapper + pkg-config + ] + ++ lib.optionals jitSupport [ + llvmPackages.llvm.dev + nukeReferences + patchelf + ]; enableParallelBuilding = true; separateDebugInfo = true; + __structuredAttrs = true; buildFlags = [ "world-bin" ]; @@ -161,113 +164,109 @@ let # Fixed upstream in https://github.com/postgres/postgres/commit/0bc8cebdb889368abdf224aeac8bc197fe4c9ae6 env.NIX_CFLAGS_COMPILE = lib.optionalString (olderThan "13") "-I${libxml2.dev}/include/libxml2"; - configureFlags = - [ - "--with-openssl" - "--with-libxml" - "--with-icu" - "--sysconfdir=/etc" - "--libdir=$(lib)/lib" - "--with-system-tzdata=${tzdata}/share/zoneinfo" - "--enable-debug" - (lib.optionalString systemdSupport' "--with-systemd") - (if stdenv'.isDarwin then "--with-uuid=e2fs" else "--with-ossp-uuid") - ] - ++ lib.optionals lz4Enabled [ "--with-lz4" ] - ++ lib.optionals zstdEnabled [ "--with-zstd" ] - ++ lib.optionals gssSupport [ "--with-gssapi" ] - ++ lib.optionals pythonSupport [ "--with-python" ] - ++ lib.optionals jitSupport [ "--with-llvm" ] - ++ lib.optionals stdenv'.isLinux [ "--with-pam" ]; - - patches = - [ - ( - if atLeast "16" then - ./patches/relative-to-symlinks-16+.patch - else - ./patches/relative-to-symlinks.patch - ) - ./patches/less-is-more.patch - ./patches/paths-for-split-outputs.patch - ./patches/specify_pkglibdir_at_runtime.patch - ./patches/paths-with-postgresql-suffix.patch - ./patches/locale-binary-path.patch - ] - ++ lib.optionals stdenv'.hostPlatform.isMusl ( - # Using fetchurl instead of fetchpatch on purpose: https://github.com/NixOS/nixpkgs/issues/240141 - map fetchurl (lib.attrValues muslPatches) + configureFlags = [ + "--with-openssl" + "--with-libxml" + "--with-icu" + "--sysconfdir=/etc" + "--libdir=$(lib)/lib" + "--with-system-tzdata=${tzdata}/share/zoneinfo" + "--enable-debug" + (lib.optionalString systemdSupport' "--with-systemd") + (if stdenv'.isDarwin then "--with-uuid=e2fs" else "--with-ossp-uuid") + ] + ++ lib.optionals lz4Enabled [ "--with-lz4" ] + ++ lib.optionals zstdEnabled [ "--with-zstd" ] + ++ lib.optionals gssSupport [ "--with-gssapi" ] + ++ lib.optionals pythonSupport [ "--with-python" ] + ++ lib.optionals jitSupport [ "--with-llvm" ] + ++ lib.optionals stdenv'.isLinux [ "--with-pam" ]; + + patches = [ + ( + if atLeast "16" then + ./patches/relative-to-symlinks-16+.patch + else + ./patches/relative-to-symlinks.patch ) - ++ lib.optionals stdenv'.isLinux [ - (if atLeast "13" then ./patches/socketdir-in-run-13+.patch else ./patches/socketdir-in-run.patch) - ]; + ./patches/less-is-more.patch + ./patches/paths-for-split-outputs.patch + ./patches/specify_pkglibdir_at_runtime.patch + ./patches/paths-with-postgresql-suffix.patch + + (replaceVars ./patches/locale-binary-path.patch { + locale = "${if stdenv.isDarwin then darwin.adv_cmds else lib.getBin stdenv.cc.libc}/bin/locale"; + }) + ] + ++ lib.optionals stdenv'.hostPlatform.isMusl ( + # Using fetchurl instead of fetchpatch on purpose: https://github.com/NixOS/nixpkgs/issues/240141 + map fetchurl (lib.attrValues muslPatches) + ) + ++ lib.optionals stdenv'.isLinux [ + (if atLeast "13" then ./patches/socketdir-in-run-13+.patch else ./patches/socketdir-in-run.patch) + ]; installTargets = [ "install-world-bin" ]; - postPatch = - '' - # Hardcode the path to pgxs so pg_config returns the path in $out - substituteInPlace "src/common/config_info.c" --subst-var out - substituteInPlace "src/backend/commands/collationcmds.c" --replace-fail '@locale@' '${ - if stdenv.isDarwin then darwin.adv_cmds else lib.getBin stdenv.cc.libc - }/bin/locale' - '' - + lib.optionalString jitSupport '' - # Force lookup of jit stuff in $out instead of $lib - substituteInPlace src/backend/jit/jit.c --replace pkglib_path \"$out/lib\" - substituteInPlace src/backend/jit/llvm/llvmjit.c --replace pkglib_path \"$out/lib\" - substituteInPlace src/backend/jit/llvm/llvmjit_inline.cpp --replace pkglib_path \"$out/lib\" - ''; - - postInstall = - '' - moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it - moveToOutput "lib/libpgcommon*.a" "$out" - moveToOutput "lib/libpgport*.a" "$out" - moveToOutput "lib/libecpg*" "$out" - - # Prevent a retained dependency on gcc-wrapper. - substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld - - if [ -z "''${dontDisableStatic:-}" ]; then - # Remove static libraries in case dynamic are available. - for i in $out/lib/*.a $lib/lib/*.a; do - name="$(basename "$i")" - ext="${stdenv'.hostPlatform.extensions.sharedLibrary}" - if [ -e "$lib/lib/''${name%.a}$ext" ] || [ -e "''${i%.a}$ext" ]; then - rm "$i" - fi - done - fi - '' - + lib.optionalString jitSupport '' - # Move the bitcode and libllvmjit.so library out of $lib; otherwise, every client that - # depends on libpq.so will also have libLLVM.so in its closure too, bloating it - moveToOutput "lib/bitcode" "$out" - moveToOutput "lib/llvmjit*" "$out" - - # In the case of JIT support, prevent a retained dependency on clang-wrapper - substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/clang clang - nuke-refs $out/lib/llvmjit_types.bc $(find $out/lib/bitcode -type f) - - # Stop out depending on the default output of llvm - substituteInPlace $out/lib/pgxs/src/Makefile.global \ - --replace ${llvmPackages.llvm.out}/bin "" \ - --replace '$(LLVM_BINPATH)/' "" - - # Stop out depending on the -dev output of llvm - substituteInPlace $out/lib/pgxs/src/Makefile.global \ - --replace ${llvmPackages.llvm.dev}/bin/llvm-config llvm-config \ - --replace -I${llvmPackages.llvm.dev}/include "" - - ${lib.optionalString (!stdenv'.isDarwin) '' - # Stop lib depending on the -dev output of llvm - rpath=$(patchelf --print-rpath $out/lib/llvmjit.so) - nuke-refs -e $out $out/lib/llvmjit.so - # Restore the correct rpath - patchelf $out/lib/llvmjit.so --set-rpath "$rpath" - ''} - ''; + postPatch = '' + # Hardcode the path to pgxs so pg_config returns the path in $out + substituteInPlace "src/common/config_info.c" --subst-var out + '' + + lib.optionalString jitSupport '' + # Force lookup of jit stuff in $out instead of $lib + substituteInPlace src/backend/jit/jit.c --replace pkglib_path \"$out/lib\" + substituteInPlace src/backend/jit/llvm/llvmjit.c --replace pkglib_path \"$out/lib\" + substituteInPlace src/backend/jit/llvm/llvmjit_inline.cpp --replace pkglib_path \"$out/lib\" + ''; + + postInstall = '' + moveToOutput "lib/pgxs" "$out" # looks strange, but not deleting it + moveToOutput "lib/libpgcommon*.a" "$out" + moveToOutput "lib/libpgport*.a" "$out" + moveToOutput "lib/libecpg*" "$out" + + # Prevent a retained dependency on gcc-wrapper. + substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/ld ld + + if [ -z "''${dontDisableStatic:-}" ]; then + # Remove static libraries in case dynamic are available. + for i in $out/lib/*.a $lib/lib/*.a; do + name="$(basename "$i")" + ext="${stdenv'.hostPlatform.extensions.sharedLibrary}" + if [ -e "$lib/lib/''${name%.a}$ext" ] || [ -e "''${i%.a}$ext" ]; then + rm "$i" + fi + done + fi + '' + + lib.optionalString jitSupport '' + # Move the bitcode and libllvmjit.so library out of $lib; otherwise, every client that + # depends on libpq.so will also have libLLVM.so in its closure too, bloating it + moveToOutput "lib/bitcode" "$out" + moveToOutput "lib/llvmjit*" "$out" + + # In the case of JIT support, prevent a retained dependency on clang-wrapper + substituteInPlace "$out/lib/pgxs/src/Makefile.global" --replace ${stdenv'.cc}/bin/clang clang + nuke-refs $out/lib/llvmjit_types.bc $(find $out/lib/bitcode -type f) + + # Stop out depending on the default output of llvm + substituteInPlace $out/lib/pgxs/src/Makefile.global \ + --replace ${llvmPackages.llvm.out}/bin "" \ + --replace '$(LLVM_BINPATH)/' "" + + # Stop out depending on the -dev output of llvm + substituteInPlace $out/lib/pgxs/src/Makefile.global \ + --replace ${llvmPackages.llvm.dev}/bin/llvm-config llvm-config \ + --replace -I${llvmPackages.llvm.dev}/include "" + + ${lib.optionalString (!stdenv'.isDarwin) '' + # Stop lib depending on the -dev output of llvm + rpath=$(patchelf --print-rpath $out/lib/llvmjit.so) + nuke-refs -e $out $out/lib/llvmjit.so + # Restore the correct rpath + patchelf $out/lib/llvmjit.so --set-rpath "$rpath" + ''} + ''; postFixup = lib.optionalString (!stdenv'.isDarwin && stdenv'.hostPlatform.libc == "glibc") '' # initdb needs access to "locale" command from glibc. @@ -321,22 +320,21 @@ let postgresql = this; } this.pkgs; - tests = - { - postgresql-wal-receiver = import ../../../../nixos/tests/postgresql-wal-receiver.nix { - inherit (stdenv) system; - pkgs = self; - package = this; - }; - pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; - } - // lib.optionalAttrs jitSupport { - postgresql-jit = import ../../../../nixos/tests/postgresql-jit.nix { - inherit (stdenv) system; - pkgs = self; - package = this; - }; + tests = { + postgresql-wal-receiver = import ../../../../nixos/tests/postgresql-wal-receiver.nix { + inherit (stdenv) system; + pkgs = self; + package = this; }; + pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; + } + // lib.optionalAttrs jitSupport { + postgresql-jit = import ../../../../nixos/tests/postgresql-jit.nix { + inherit (stdenv) system; + pkgs = self; + package = this; + }; + }; }; meta = with lib; { @@ -344,6 +342,7 @@ let description = "Powerful, open source object-relational database system"; license = licenses.postgresql; changelog = "https://www.postgresql.org/docs/release/${finalAttrs.version}/"; + teams = [ ]; maintainers = with maintainers; [ thoughtpolice danbst diff --git a/nix/tools/dbmate-tool.sh.in b/nix/tools/dbmate-tool.sh.in deleted file mode 100644 index ec38ecf1a..000000000 --- a/nix/tools/dbmate-tool.sh.in +++ /dev/null @@ -1,306 +0,0 @@ -#!/usr/bin/env bash -# shellcheck shell=bash - -[ ! -z "$DEBUG" ] && set -x - -# Default values -PSQL_VERSION="ALL" -PORTNO="@PGSQL_DEFAULT_PORT@" -PGSQL_SUPERUSER="@PGSQL_SUPERUSER@" -PGPASSWORD="${PGPASSWORD:-postgres}" -PGSQL_USER="postgres" -FLAKE_URL="github:supabase/postgres" -MIGRATIONS_DIR="@MIGRATIONS_DIR@" -CURRENT_SYSTEM="@CURRENT_SYSTEM@" -ANSIBLE_VARS="@ANSIBLE_VARS@" -PGBOUNCER_AUTH_SCHEMA_SQL=@PGBOUNCER_AUTH_SCHEMA_SQL@ -STAT_EXTENSION_SQL=@STAT_EXTENSION_SQL@ - -# Start PostgreSQL using nix -start_postgres() { - DATDIR=$(mktemp -d) - echo "Starting PostgreSQL in directory: $DATDIR" # Create the DATDIR if it doesn't exist - nix run "$FLAKE_URL#start-server" -- "$PSQL_VERSION" --skip-migrations --daemonize --datdir "$DATDIR" - echo "PostgreSQL started." -} - -# Cleanup function -cleanup() { - echo "Cleaning up..." - - # Check if PostgreSQL processes exist - if pgrep -f "postgres" >/dev/null; then - echo "Stopping PostgreSQL gracefully..." - - # Use pg_ctl to stop PostgreSQL - pg_ctl -D "$DATDIR" stop - - # Wait a bit for graceful shutdown - sleep 5 - - # Check if processes are still running - if pgrep -f "postgres" >/dev/null; then - echo "Warning: Some PostgreSQL processes could not be stopped gracefully." - fi - else - echo "PostgreSQL is not running, skipping stop." - fi - - # Always exit successfully, log any remaining processes - if pgrep -f "postgres" >/dev/null; then - echo "Warning: Some PostgreSQL processes could not be cleaned up:" - pgrep -f "postgres" - else - echo "Cleanup completed successfully" - fi -} - - -# Function to display help -print_help() { - echo "Usage: nix run .#dbmate-tool -- [options]" - echo - echo "Options:" - echo " -v, --version [15|17|orioledb-17|all] Specify the PostgreSQL version to use (required defaults to --version all)" - echo " -p, --port PORT Specify the port number to use (default: 5435)" - echo " -h, --help Show this help message" - echo " -f, --flake-url URL Specify the flake URL to use (default: github:supabase/postgres)" - echo "Description:" - echo " Runs 'dbmate up' against a locally running the version of database you specify. Or 'all' to run against all versions." - echo " NOTE: To create a migration, you must run 'nix develop' and then 'dbmate new ' to create a new migration file." - echo - echo "Examples:" - echo " nix run .#dbmate-tool" - echo " nix run .#dbmate-tool -- --version 15" - echo " nix run .#dbmate-tool -- --version 16 --port 5433" - echo " nix run .#dbmate-tool -- --version 16 --port 5433 --flake-url github:supabase/postgres/" -} - -# Parse arguments -while [[ "$#" -gt 0 ]]; do - case "$1" in - -v|--version) - if [[ -n "$2" && ! "$2" =~ ^- ]]; then - PSQL_VERSION="$2" - shift 2 - else - echo "Error: --version requires an argument (15, 16, or orioledb-17)" - exit 1 - fi - ;; - -u|--user) - if [[ -n "$2" && ! "$2" =~ ^- ]]; then - PGSQL_USER="$2" - shift 2 - else - echo "Error: --user requires an argument" - exit 1 - fi - ;; - -f|--flake-url) - if [[ -n "$2" && ! "$2" =~ ^- ]]; then - FLAKE_URL="$2" - shift 2 - else - echo "Error: --flake-url requires an argument" - exit 1 - fi - ;; - -p|--port) - if [[ -n "$2" && ! "$2" =~ ^- ]]; then - PORTNO="$2" - shift 2 - else - echo "Error: --port requires an argument" - exit 1 - fi - ;; - -h|--help) - print_help - exit 0 - ;; - *) - echo "Unknown option: $1" - print_help - exit 1 - ;; - esac -done - -# Function to wait for PostgreSQL to be ready -wait_for_postgres() { - local max_attempts=30 # Increased significantly - local attempt=1 - - # Give PostgreSQL a moment to actually start the process - sleep 2 - - while [ $attempt -le $max_attempts ]; do - "${PSQLBIN}/pg_isready" -h localhost -p "$PORTNO" -U "$PGSQL_SUPERUSER" -d postgres - local status=$? - - if [ $status -eq 0 ]; then - echo "PostgreSQL is ready!" - return 0 - fi - echo "Waiting for PostgreSQL to start (attempt $attempt/$max_attempts)..." - sleep 2 - attempt=$((attempt + 1)) - done - - echo "PostgreSQL failed to start after $max_attempts attempts" - return 1 -} - -check_orioledb_ready() { - local max_attempts=30 - local attempt=1 - - while [ $attempt -le $max_attempts ]; do - if "${PSQLBIN}/psql" -v ON_ERROR_STOP=1 -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres -c "SELECT * FROM pg_am WHERE amname = 'orioledb'" | grep -q orioledb; then - echo "Orioledb extension is ready!" - return 0 - fi - echo "Waiting for orioledb to be ready (attempt $attempt/$max_attempts)..." - sleep 2 - attempt=$((attempt + 1)) - done - - echo "Orioledb failed to initialize after $max_attempts attempts" - return 1 -} - -perform_dump() { - local max_attempts=3 - local attempt=1 - - while [ $attempt -le $max_attempts ]; do - echo "Attempting pg_dump (attempt $attempt/$max_attempts)" - - # Build the dump command - local dump_cmd="${PSQLBIN}/pg_dump -h localhost -p $PORTNO -U $PGSQL_SUPERUSER -d postgres --schema-only --no-owner --no-privileges" - - # Only use --restrict-key for standard PostgreSQL 15 and 17 versions - # OrioleDB doesn't support this flag yet - if [ "$PSQL_VERSION" = "15" ] || [ "$PSQL_VERSION" = "17" ] || [ "$PSQL_VERSION" = "orioledb-17" ]; then - # Use a fixed restrict key for reproducible test dumps - # This is safe in testing contexts but should not be used in production - dump_cmd="$dump_cmd --restrict-key=SupabaseTestDumpKey123" - echo "Using --restrict-key for reproducible dumps (PostgreSQL $PSQL_VERSION)" - else - echo "Skipping --restrict-key (version: $PSQL_VERSION)" - fi - - if $dump_cmd > "./db/schema.sql"; then - return 0 - fi - - echo "Dump attempt $attempt failed, waiting before retry..." - sleep 5 - attempt=$((attempt + 1)) - done - - echo "All dump attempts failed" - return 1 -} - -migrate_version() { - echo "PSQL_VERSION: $PSQL_VERSION" - #pkill -f "postgres" || true # Ensure PostgreSQL is stopped before starting - PSQLBIN=$(nix build --no-link "$FLAKE_URL#psql_$PSQL_VERSION/bin" --json | jq -r '.[].outputs.out + "/bin"') - echo "Using PostgreSQL version $PSQL_VERSION from $PSQLBIN" - - # Start PostgreSQL - start_postgres - echo "Waiting for PostgreSQL to be ready..." - - # Wait for PostgreSQL to be ready to accept connections - if ! wait_for_postgres; then - echo "Failed to connect to PostgreSQL server" - cleanup - exit 1 - fi - - if [ "$PSQL_VERSION" = "orioledb-17" ]; then - if ! check_orioledb_ready; then - echo "Failed to initialize orioledb extension" - exit 1 - fi - fi - - echo "PostgreSQL server is ready" - - # Configure PostgreSQL roles and permissions - if ! "${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres <<-EOSQL -create role postgres superuser login password '$PGPASSWORD'; -alter database postgres owner to postgres; -EOSQL - then - echo "Failed to configure PostgreSQL roles and permissions" - exit 1 - fi - "${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -d postgres -f "$PGBOUNCER_AUTH_SCHEMA_SQL" - "${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -d postgres -f "$STAT_EXTENSION_SQL" - - # Set db url to run dbmate - export DATABASE_URL="postgres://$PGSQL_USER:$PGPASSWORD@localhost:$PORTNO/postgres?sslmode=disable" - # Export path so dbmate can find correct psql and pg_dump - export PATH="$PSQLBIN:$PATH" - # Run init scripts - if ! dbmate --migrations-dir "$MIGRATIONS_DIR/init-scripts" up; then - echo "Error: Initial migration failed" - exit 1 - fi - - # Password update command - if ! "${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U postgres -p "$PORTNO" -h localhost -c "ALTER USER supabase_admin WITH PASSWORD '$PGPASSWORD'"; then - echo "Error: Failed to update supabase_admin password" - exit 1 - fi - - # Set up database URL - export DATABASE_URL="postgres://$PGSQL_SUPERUSER:$PGPASSWORD@localhost:$PORTNO/postgres?sslmode=disable" - # Run migrations - if ! dbmate --migrations-dir "$MIGRATIONS_DIR/migrations" up; then - echo "Error: Final migration failed" - exit 1 - fi - - echo "Running dbmate dump with $PSQLBIN" - perform_dump - - echo "CURRENT_SYSTEM: $CURRENT_SYSTEM" - if [ -f "./db/schema.sql" ]; then - cp "./db/schema.sql" "./migrations/schema-$PSQL_VERSION.sql" - echo "Schema file moved to ./migrations/schema-$PSQL_VERSION.sql" - echo "PSQLBIN is $PSQLBIN" - else - echo "Warning: schema.sql file not found in ./db directory" - exit 1 - fi - - # If we get here, all commands succeeded - echo "PostgreSQL migration completed successfully" - echo "Check migrations are idempotent" - for sql in ./migrations/db/migrations/*.sql; do - echo "$0: running $sql" - "${PSQLBIN}/psql" -v ON_ERROR_STOP=1 --no-password --no-psqlrc -U "$PGSQL_SUPERUSER" -p "$PORTNO" -h localhost -d postgres -f "$sql" || { - echo "Failed to execute $sql" - exit 1 - } - done -} - -if [ "$PSQL_VERSION" == "all" ]; then - VERSIONS=$(yq '.postgres_major[]' "$ANSIBLE_VARS" | tr -d '"') - echo "$VERSIONS" | while read -r version; do - PSQL_VERSION="$version" - echo "Migrating to PostgreSQL version $PSQL_VERSION" - migrate_version - cleanup - done -else - echo "Migrating to PostgreSQL version $PSQL_VERSION" - migrate_version - cleanup -fi diff --git a/nix/tools/migrate-tool.sh.in b/nix/tools/migrate-tool.sh.in deleted file mode 100644 index 10239ed80..000000000 --- a/nix/tools/migrate-tool.sh.in +++ /dev/null @@ -1,123 +0,0 @@ -#!/usr/bin/env bash - -[ ! -z "$DEBUG" ] && set -x - -# first argument is the old version; a path 15 or 16 -if [[ $1 == /nix/store* ]]; then - if [ ! -L "$1/receipt.json" ] || [ ! -e "$1/receipt.json" ]; then - echo "ERROR: $1 does not look like a valid Postgres install" - exit 1 - fi - OLDVER="$1" -elif [ "$1" == "15" ]; then - PSQL15=@PSQL15_BINDIR@ - OLDVER="$PSQL15" -elif [ "$1" == "16" ]; then - PSQL16=@PSQL16_BINDIR@ - OLDVER="$PSQL16" -else - echo "Please provide a valid Postgres version (15 or 16), or a /nix/store path" - exit 1 -fi - -# second argument is the new version; 15 or 16 -if [[ $2 == /nix/store* ]]; then - if [ ! -L "$2/receipt.json" ] || [ ! -e "$2/receipt.json" ]; then - echo "ERROR: $1 does not look like a valid Postgres install" - exit 1 - fi - NEWVER="$2" -elif [ "$2" == "15" ]; then - PSQL15=@PSQL15_BINDIR@ - NEWVER="$PSQL15" -elif [ "$2" == "16" ]; then - PSQL16=@PSQL16_BINDIR@ - NEWVER="$PSQL16" - echo "NEWVER IS $NEWVER" -else - echo "Please provide a valid Postgres version (15 or 16), or a /nix/store path" - exit 1 -fi - -# thid argument is the upgrade method: either pg_dumpall or pg_ugprade -if [ "$3" != "pg_dumpall" ] && [ "$3" != "pg_upgrade" ]; then - echo "Please provide a valid upgrade method (pg_dumpall or pg_upgrade)" - exit 1 -fi -UPGRADE_METHOD="$3" - -echo "Old server build: PSQL $1" -echo "New server build: PSQL $2" -echo "Upgrade method: $UPGRADE_METHOD" - -PORTNO="${2:-@PGSQL_DEFAULT_PORT@}" -DATDIR=$(mktemp -d) -NEWDAT=$(mktemp -d) -mkdir -p "$DATDIR" "$NEWDAT" - -echo "NOTE: using temporary directory $DATDIR for PSQL $1 data, which will not be removed" -echo "NOTE: you are free to re-use this data directory at will" -echo - -$OLDVER/bin/initdb -D "$DATDIR" --locale=C --username=supabase_admin -$NEWVER/bin/initdb -D "$NEWDAT" --locale=C --username=supabase_admin - -# NOTE (aseipp): we need to patch postgresql.conf to have the right pgsodium_getkey script -PSQL_CONF_FILE=@PSQL_CONF_FILE@ -PGSODIUM_GETKEY_SCRIPT=@PGSODIUM_GETKEY@ -echo "NOTE: patching postgresql.conf files" -for x in "$DATDIR" "$NEWDAT"; do - sed \ - "s#@PGSODIUM_GETKEY_SCRIPT@#$PGSODIUM_GETKEY_SCRIPT#g" \ - $PSQL_CONF_FILE > "$x/postgresql.conf" -done - -echo "NOTE: Starting first server (v${1}) to load data into the system" -$OLDVER/bin/pg_ctl start -D "$DATDIR" - -PRIMING_SCRIPT=@PRIMING_SCRIPT@ -MIGRATION_DATA=@MIGRATION_DATA@ - -$OLDVER/bin/psql -h localhost -d postgres -Xf "$PRIMING_SCRIPT" -$OLDVER/bin/psql -h localhost -d postgres -Xf "$MIGRATION_DATA" - -if [ "$UPGRADE_METHOD" == "pg_upgrade" ]; then - echo "NOTE: Stopping old server (v${1}) to prepare for migration" - $OLDVER/bin/pg_ctl stop -D "$DATDIR" - - echo "NOTE: Migrating old data $DATDIR to $NEWDAT using pg_upgrade" - - export PGDATAOLD="$DATDIR" - export PGDATANEW="$NEWDAT" - export PGBINOLD="$OLDVER/bin" - export PGBINNEW="$NEWVER/bin" - - if ! $NEWVER/bin/pg_upgrade --check; then - echo "ERROR: pg_upgrade check failed" - exit 1 - fi - - echo "NOTE: pg_upgrade check passed, proceeding with migration" - $NEWVER/bin/pg_upgrade - rm -f delete_old_cluster.sh # we don't need this - exit 0 -fi - -if [ "$UPGRADE_METHOD" == "pg_dumpall" ]; then - SQLDAT="$DATDIR/dump.sql" - echo "NOTE: Exporting data via pg_dumpall ($SQLDAT)" - $NEWVER/bin/pg_dumpall -h localhost > "$SQLDAT" - - echo "NOTE: Stopping old server (v${1}) to prepare for migration" - $OLDVER/bin/pg_ctl stop -D "$DATDIR" - - echo "NOTE: Starting second server (v${2}) to load data into the system" - $NEWVER/bin/pg_ctl start -D "$NEWDAT" - - echo "NOTE: Loading data into new server (v${2}) via 'cat | psql'" - cat "$SQLDAT" | $NEWVER/bin/psql -h localhost -d postgres - - printf "\n\n\n\n" - echo "NOTE: Done, check logs. Stopping the server; new database is located at $NEWDAT" - $NEWVER/bin/pg_ctl stop -D "$NEWDAT" -fi diff --git a/nix/tools/run-client.sh.in b/nix/tools/run-client.sh.in deleted file mode 100644 index 6acb4d6c0..000000000 --- a/nix/tools/run-client.sh.in +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env bash -# shellcheck shell=bash - -[ ! -z "$DEBUG" ] && set -x - -# Default values -PSQL_VERSION="15" -PORTNO="@PGSQL_DEFAULT_PORT@" -PSQL_USER="postgres" - -# Function to display help -print_help() { - echo "Usage: nix run .#start-client -- [options]" - echo - echo "Options:" - echo " -v, --version [15|16|orioledb-16] Specify the PostgreSQL version to use (required)" - echo " -u, --user USER Specify the user/role to use (default: postgres)" - echo " -h, --help Show this help message" - echo - echo "Description:" - echo " Starts an interactive 'psql' session connecting to a Postgres database started with the" - echo " 'nix run .#start-server' command. If a migration file is not provided, the client" - echo " initializes the database with the default migrations for a new Supabase project." - echo " If a migrations file is provided, default migrations are skipped" - echo " If no migration file is provided, it runs the default Supabase migrations." - echo - echo "Examples:" - echo " nix run .#start-client" - echo " nix run .#start-client -- --version 15" - echo " nix run .#start-client -- --version 16 --port 5433" - echo " nix run .#start-client -- --version 16 --user supabase_admin" -} - -# Parse arguments -while [[ "$#" -gt 0 ]]; do - case "$1" in - -v|--version) - if [[ -n "$2" && ! "$2" =~ ^- ]]; then - PSQL_VERSION="$2" - shift 2 - else - echo "Error: --version requires an argument (15, 16, or orioledb-16)" - exit 1 - fi - ;; - -u|--user) - if [[ -n "$2" && ! "$2" =~ ^- ]]; then - PSQL_USER="$2" - shift 2 - else - echo "Error: --user requires an argument" - exit 1 - fi - ;; - -p|--port) - if [[ -n "$2" && ! "$2" =~ ^- ]]; then - PORTNO="$2" - shift 2 - else - echo "Error: --port requires an argument" - exit 1 - fi - ;; - -h|--help) - print_help - exit 0 - ;; - *) - echo "Unknown option: $1" - print_help - exit 1 - ;; - esac -done - -# Check if version is provided -if [[ -z "$PSQL_VERSION" ]]; then - echo "Error: PostgreSQL version is required." - print_help - exit 1 -fi - -# Determine PostgreSQL version -if [ "$PSQL_VERSION" == "15" ]; then - echo "Starting client for PSQL 15" - PSQL15=@PSQL15_BINDIR@ - BINDIR="$PSQL15" -elif [ "$PSQL_VERSION" == "17" ]; then - echo "Starting client for PSQL 17" - PSQL17=@PSQL17_BINDIR@ - BINDIR="$PSQL17" -elif [ "$PSQL_VERSION" == "orioledb-17" ]; then - echo "Starting client for PSQL ORIOLEDB 17" - PSQLORIOLEDB17=@PSQLORIOLEDB17_BINDIR@ - BINDIR="$PSQLORIOLEDB17" -else - echo "Please provide a valid Postgres version (15, 17, or orioledb-17)" - exit 1 -fi - -#vars for migration.sh -export PATH=$BINDIR/bin:$PATH -export POSTGRES_DB=postgres -export POSTGRES_HOST=localhost - -# Start interactive psql session -exec psql -U "$PSQL_USER" -p "$PORTNO" -h localhost postgres diff --git a/nix/tools/sync-exts-versions.sh.in b/nix/tools/sync-exts-versions.sh.in index 1b120e988..8e588b002 100644 --- a/nix/tools/sync-exts-versions.sh.in +++ b/nix/tools/sync-exts-versions.sh.in @@ -1,15 +1,9 @@ #!/usr/bin/env bash # shellcheck shell=bash -[ ! -z "$DEBUG" ] && set -x +[ -n "$DEBUG" ] && set -x -#pass in env vars supplied by nix -yq=@YQ@ -jq=@JQ@ -editor=@NIX_EDITOR@ -ansible_vars=$($yq '.' $PWD/ansible/vars.yml) -prefetchurl=@NIXPREFETCHURL@ -_nix=@NIX@ +ansible_vars=$(yq '.' "$PWD/ansible/vars.yml") fetch_source_url() { local source_url=${1//\"/} # Remove double quotes source_url=${source_url//\'/} # Remove single quotes @@ -21,11 +15,13 @@ fetch_source_url() { fi echo "$source_url" - + # Run nix-prefetch-url command - local initial_hash=$($prefetchurl --type sha256 "$source_url" --unpack | cut -d ' ' -f 2) + local initial_hash + initial_hash=$(nix-prefetch-url --type sha256 "$source_url" --unpack | cut -d ' ' -f 2) #once we can bump up nix version, we can use nix hash convert --hash-algo sha256 - local final_hash=$($_nix hash to-sri --type sha256 $initial_hash) + local final_hash + final_hash=$(nix hash to-sri --type sha256 "$initial_hash") echo "$final_hash" } @@ -37,19 +33,19 @@ sync_version() { # Update the version and hash in the Nix expression - $editor $PWD/nix/ext/$package_name.nix version --inplace -v "$version" - $editor $PWD/nix/ext/$package_name.nix src.hash --inplace -v $hash + nix-editor "$PWD/nix/ext/$package_name.nix" version --inplace -v "$version" + nix-editor "$PWD/nix/ext/$package_name.nix" src.hash --inplace -v "$hash" } run_sync() { local varname=$1 local package_name=$2 - version=$(echo $ansible_vars | $jq -r '.'$varname'') + version=$(echo "$ansible_vars" | jq -r ".$varname") echo "$key: $version" - url=$($_nix eval .#psql_15/exts/$package_name.src.url) - hash=$(fetch_source_url $url | tail -n 1) - $(sync_version $package_name $version $hash) + url=$(nix eval ".#psql_15/exts/$package_name.src.url") + hash=$(fetch_source_url "$url" | tail -n 1) + sync_version "$package_name" "$version" "$hash" echo "synced $package_name to version $version with hash $hash" @@ -68,11 +64,13 @@ fetchurl_source_url() { fi echo "$source_url" - + # Run nix-prefetch-url command - local initial_hash=$($prefetchurl --type sha256 "$source_url" | cut -d ' ' -f 2) + local initial_hash + initial_hash=$(nix-prefetch-url --type sha256 "$source_url" | cut -d ' ' -f 2) #once we can bump up nix version, we can use nix hash convert --hash-algo sha256 - local final_hash=$($_nix hash to-sri --type sha256 $initial_hash) + local final_hash + final_hash=$(nix hash to-sri --type sha256 "$initial_hash") echo "$final_hash" } @@ -84,8 +82,8 @@ sync_version_fetchurl() { # Update the version and hash in the Nix expression - $editor $PWD/nix/ext/$package_name.nix version --inplace -v "$version" - $editor $PWD/nix/ext/$package_name.nix src.sha256 --inplace -v $hash + nix-editor "$PWD/nix/ext/$package_name.nix" version --inplace -v "$version" + nix-editor "$PWD/nix/ext/$package_name.nix" src.sha256 --inplace -v "$hash" } @@ -93,11 +91,11 @@ run_sync_fetchurl() { local varname=$1 local package_name=$2 - version=$(echo $ansible_vars | $jq -r '.'$varname'') + version=$(echo "$ansible_vars" | jq -r ".$varname") echo "$key: $version" - url=$($_nix eval .#psql_15/exts/$package_name.src.url) - hash=$(fetchurl_source_url $url | tail -n 1) - $(sync_version_fetchurl $package_name $version $hash) + url=$(nix eval ".#psql_15/exts/$package_name.src.url") + hash=$(fetchurl_source_url "$url" | tail -n 1) + sync_version_fetchurl "$package_name" "$version" "$hash" echo "synced $package_name to version $version with hash $hash" @@ -106,16 +104,13 @@ run_sync_fetchurl() { #for use on derivations that use cargoHash update_cargo_vendor_hash() { local package_name=$1 - $editor $PWD/nix/ext/$package_name.nix cargoHash --inplace -v "" - output=$($_nix build .#psql_15/exts/$package_name 2>&1) - - # Check if the command exited with an error - if [ $? -ne 0 ]; then + nix-editor "$PWD/nix/ext/$package_name.nix" cargoHash --inplace -v "" + if ! output=$(nix build .#psql_15/exts/"$package_name" 2>&1); then # Extract the hash value after "got: " hash_value_scraped=$(echo "$output" | grep "got:" | awk '{for (i=1; i<=NF; i++) if ($i ~ /^sha/) print $i}') hash_value="\"$hash_value_scraped\"" # Continue using the captured hash value - $editor $PWD/nix/ext/$package_name.nix cargoHash --inplace -v $hash_value + nix-editor "$PWD/nix/ext/$package_name.nix" cargoHash --inplace -v "$hash_value" echo "Updated cargoHash for $package_name to $hash_value" else echo "$package_name builds successfully, moving on..." @@ -124,146 +119,146 @@ update_cargo_vendor_hash() { #iterate values in ansible vars, case statement # to match ansible var to package name -keys=$(echo "$ansible_vars" | $jq -r 'keys[]') +keys=$(echo "$ansible_vars" | jq -r 'keys[]') for key in $keys; do case $key in "pg_hashids_release") varname="pg_hashids_release" package_name="pg_hashids" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "hypopg_release") varname="hypopg_release" package_name="hypopg" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pg_graphql_release") varname="pg_graphql_release" package_name="pg_graphql" - run_sync $varname $package_name - update_cargo_vendor_hash $package_name + run_sync "$varname" "$package_name" + update_cargo_vendor_hash "$package_name" ;; "pg_cron_release") varname="pg_cron_release" package_name="pg_cron" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pgsql_http_release") varname="pgsql_http_release" package_name="pgsql-http" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pg_jsonschema_release") varname="pg_jsonschema_release" package_name="pg_jsonschema" - run_sync $varname $package_name - update_cargo_vendor_hash $package_name + run_sync "$varname" "$package_name" + update_cargo_vendor_hash "$package_name" ;; "pg_net_release") varname="pg_net_release" package_name="pg_net" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pg_plan_filter_release") varname="pg_plan_filter_release" package_name="pg_plan_filter" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pg_safeupdate_release") varname="pg_safeupdate_release" package_name="pg-safeupdate" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pgsodium_release") varname="pgsodium_release" package_name="pgsodium" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pg_repack_release") varname="pg_repack_release" package_name="pg_repack" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pgrouting_release") varname="pgrouting_release" package_name="pgrouting" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "ptap_release") varname="pgtap_release" package_name="pgtap" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pg_stat_monitor_release") varname="pg_stat_monitor_release" package_name="pg_stat_monitor" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pg_tle_release") varname="pg_tle_release" package_name="pg_tle" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pgaudit_release") varname="pgaudit_release" package_name="pgaudit" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "plpgsql_check_release") varname="plpgsql_check_release" package_name="plpgsql-check" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pgvector_release") varname="pgvector_release" package_name="pgvector" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "pgjwt_release") varname="pgjwt_release" package_name="pgjwt" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "plv8_release") varname="plv8_release" package_name="plv8" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "postgis_release") varname="postgis_release" package_name="postgis" - run_sync_fetchurl $varname $package_name + run_sync_fetchurl "$varname" "$package_name" ;; "pgroonga_release") varname="pgroonga_release" package_name="pgroonga" - run_sync_fetchurl $varname $package_name + run_sync_fetchurl "$varname" "$package_name" ;; "rum_release") varname="rum_release" package_name="rum" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "timescaledb_release") varname="timescaledb_release" package_name="timescaledb" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "supautils_release") varname="supautils_release" package_name="supautils" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "vault_release") varname="vault_release" package_name="vault" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; "wal2json_release") varname="wal2json_release" package_name="wal2json" - run_sync $varname $package_name + run_sync "$varname" "$package_name" ;; *) ;; diff --git a/testinfra/test_ami_nix.py b/testinfra/test_ami_nix.py index 1b00f2c84..a5cadcad9 100644 --- a/testinfra/test_ami_nix.py +++ b/testinfra/test_ami_nix.py @@ -421,9 +421,9 @@ def is_healthy(ssh) -> bool: def test_postgrest_is_running(host): """Check if postgrest service is running using our SSH connection.""" result = run_ssh_command(host["ssh"], "systemctl is-active postgrest") - assert ( - result["succeeded"] and result["stdout"].strip() == "active" - ), "PostgREST service is not running" + assert result["succeeded"] and result["stdout"].strip() == "active", ( + "PostgREST service is not running" + ) def test_postgrest_responds_to_requests(host): @@ -546,9 +546,9 @@ def test_postgresql_version(host): if version_match: major_version = int(version_match.group(1)) print(f"PostgreSQL major version: {major_version}") - assert ( - major_version >= 14 - ), f"PostgreSQL version {major_version} is less than 14" + assert major_version >= 14, ( + f"PostgreSQL version {major_version} is less than 14" + ) else: assert False, "Could not parse PostgreSQL version number" else: @@ -578,9 +578,9 @@ def test_libpq5_version(host): if version_match: major_version = int(version_match.group(1)) print(f"libpq5 major version: {major_version}") - assert ( - major_version >= 14 - ), f"libpq5 version {major_version} is less than 14" + assert major_version >= 14, ( + f"libpq5 version {major_version} is less than 14" + ) else: print("Could not parse libpq5 version from dpkg output") else: @@ -613,9 +613,9 @@ def test_libpq5_version(host): if version_match: major_version = int(version_match.group(1)) print(f"psql/libpq major version: {major_version}") - assert ( - major_version >= 14 - ), f"psql/libpq version {major_version} is less than 14" + assert major_version >= 14, ( + f"psql/libpq version {major_version} is less than 14" + ) else: print("Could not parse psql version") @@ -776,7 +776,9 @@ def test_postgrest_read_only_session_attrs(host): print( f"\nFound 'session is not read-only' errors in PostgREST logs:\n{result['stdout']}" ) - assert False, "PostgREST logs contain 'session is not read-only' errors even though PostgreSQL is configured for read-only mode" + assert False, ( + "PostgREST logs contain 'session is not read-only' errors even though PostgreSQL is configured for read-only mode" + ) else: print("\nNo 'session is not read-only' errors found in PostgREST logs")