diff --git a/.github/workflows/testinfra-ami-build.yml b/.github/workflows/testinfra-ami-build.yml index 2b07e716f..8845e954a 100644 --- a/.github/workflows/testinfra-ami-build.yml +++ b/.github/workflows/testinfra-ami-build.yml @@ -108,13 +108,13 @@ jobs: df -h / # Display available space - name: Run tests - timeout-minutes: 10 + timeout-minutes: 30 env: AMI_NAME: "supabase-postgres-${{ steps.random.outputs.random_string }}" run: | # TODO: use poetry for pkg mgmt pip3 install boto3 boto3-stubs[essential] docker ec2instanceconnectcli pytest pytest-testinfra[paramiko,docker] requests - pytest -vv -s testinfra/test_ami_nix.py + pytest -vvvv -s testinfra/test_ami_nix.py - name: Cleanup resources on build cancellation if: ${{ cancelled() }} diff --git a/ansible/files/postgres_prestart.sh.j2 b/ansible/files/postgres_prestart.sh.j2 index 3ffe54c85..b8344f634 100644 --- a/ansible/files/postgres_prestart.sh.j2 +++ b/ansible/files/postgres_prestart.sh.j2 @@ -1,5 +1,11 @@ #!/bin/bash +set -x # Print commands + +log() { + echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" +} + check_orioledb_enabled() { local pg_conf="/etc/postgresql/postgresql.conf" if [ ! -f "$pg_conf" ]; then @@ -26,7 +32,78 @@ update_orioledb_buffers() { fi } +check_extensions_file() { + local extensions_file="/etc/adminapi/pg-extensions.json" + if [ ! -f "$extensions_file" ]; then + log "extensions: No extensions file found, skipping extensions versions check" + return 1 + fi + if [ ! -r "$extensions_file" ]; then + log "extensions: Cannot read extensions file" + return 1 + fi + return 0 +} + +get_pg_cron_version() { + if ! check_extensions_file; then + return + fi + + local version + version=$(jq -r '.pg_cron // empty' "/etc/adminapi/pg-extensions.json") + if [ -z "$version" ]; then + log "pg_cron: Not specified in extensions file" + return + fi + + if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + log "pg_cron: Invalid version format: $version" + return + fi + + # Log the version but don't include it in the output + log "pg_cron: Found version $version in extensions file" >&2 + printf "%s" "$version" +} + +switch_pg_cron_version() { + local version="$1" + local switch_script="/var/lib/postgresql/.nix-profile/bin/switch_pg_cron_version" + + if [ ! -x "$switch_script" ]; then + log "pg_cron: No version switch script available at $switch_script" + return 1 + fi + + log "pg_cron: Switching to version $version" + # Run directly as root since we're already running as root + "$switch_script" "$version" + local exit_code=$? + if [ $exit_code -eq 0 ]; then + log "pg_cron: Version switch completed successfully" + else + log "pg_cron: Version switch failed with exit code $exit_code" + fi + return $exit_code +} + +handle_pg_cron_version() { + local version + version=$(get_pg_cron_version) + if [ -n "$version" ]; then + # Don't fail if version switch fails + switch_pg_cron_version "$version" || log "pg_cron: Version switch failed but continuing" + fi +} + main() { + log "Starting prestart script" + + # 1. pg_cron version handling + handle_pg_cron_version + + # 2. orioledb handling local has_orioledb=$(check_orioledb_enabled) if [ "$has_orioledb" -lt 1 ]; then return 0 @@ -35,6 +112,8 @@ main() { if [ ! -z "$shared_buffers_value" ]; then update_orioledb_buffers "$shared_buffers_value" fi + + log "Prestart script completed" } # Initial locale setup diff --git a/ansible/files/postgresql_config/postgresql.service.j2 b/ansible/files/postgresql_config/postgresql.service.j2 index 4cc138ec7..844a2b400 100644 --- a/ansible/files/postgresql_config/postgresql.service.j2 +++ b/ansible/files/postgresql_config/postgresql.service.j2 @@ -18,6 +18,8 @@ TimeoutStopSec=90 TimeoutStartSec=86400 Restart=always RestartSec=5 +StandardOutput=journal +StandardError=journal OOMScoreAdjust=-1000 EnvironmentFile=-/etc/environment.d/postgresql.env LimitNOFILE=16384 diff --git a/ansible/tasks/stage2-setup-postgres.yml b/ansible/tasks/stage2-setup-postgres.yml index d3209fc04..e205a5dc8 100644 --- a/ansible/tasks/stage2-setup-postgres.yml +++ b/ansible/tasks/stage2-setup-postgres.yml @@ -94,6 +94,12 @@ shell: | sudo -u postgres bash -c ". /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install github:supabase/postgres/{{ git_commit_sha }}#{{postgresql_version}}_src" when: stage2_nix + +- name: Install jq from nix binary cache + become: yes + shell: | + . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh && nix profile install nixpkgs#jq --profile /nix/var/nix/profiles/default + when: stage2_nix - name: Set ownership and permissions for /etc/ssl/private become: yes diff --git a/ansible/vars.yml b/ansible/vars.yml index c33f69a76..b8df02733 100644 --- a/ansible/vars.yml +++ b/ansible/vars.yml @@ -9,9 +9,9 @@ postgres_major: # Full version strings for each major version postgres_release: - postgresorioledb-17: "17.0.1.086-orioledb" - postgres17: "17.4.1.036" - postgres15: "15.8.1.093" + postgresorioledb-17: "17.0.1.086-orioledb-cron-1" + postgres17: "17.4.1.036-cron-1" + postgres15: "15.8.1.093-cron-1" # Non Postgres Extensions pgbouncer_release: "1.19.0" diff --git a/flake.nix b/flake.nix index d49c9e3fa..3bf24afbd 100644 --- a/flake.nix +++ b/flake.nix @@ -637,157 +637,124 @@ --prefix PATH : ${pkgs.nushell}/bin ''; # Script to run the AMI build and tests locally - build-test-ami = pkgs.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 + build-test-ami = pkgs.writeScriptBin "build-test-ami" '' + #!/usr/bin/env bash + set -euo pipefail - show_help() { - cat << EOF - Usage: build-test-ami [--help] + show_help() { + cat << EOF + Usage: build-test-ami [--help] - Build AMI images for PostgreSQL testing. + Build AMI images for PostgreSQL testing. - This script will: - 1. Check for required tools and AWS authentication - 2. Build two AMI stages using Packer - 3. Clean up any temporary instances - 4. Output the final AMI name for use with run-testinfra + This script will: + 1. Check for required tools and AWS authentication + 2. Build two AMI stages using Packer + 3. Clean up any temporary instances + 4. Output the final AMI name for use with run-testinfra - Arguments: - postgres-version PostgreSQL major version to build (required) + Arguments: + postgres-version PostgreSQL major version to build (required) - Options: - --help Show this help message and exit - - Requirements: - - AWS Vault profile must be set in AWS_VAULT environment variable - - Packer, AWS CLI, yq, jq, and OpenSSL must be installed - - Must be run from a git repository + Options: + --help Show this help message and exit - Example: - aws-vault exec -- nix run .#build-test-ami 15 - EOF - } + Requirements: + - AWS Vault profile must be set in AWS_VAULT environment variable + - Packer, AWS CLI, yq, jq, and OpenSSL must be installed + - Must be run from a git repository - # Handle help flag - if [[ "$#" -gt 0 && "$1" == "--help" ]]; then - show_help - exit 0 - fi + Example: + aws-vault exec -- nix run .#build-test-ami 15 + EOF + } - export PATH="${pkgs.lib.makeBinPath (with pkgs; [ - packer - awscli2 - yq - jq - openssl - git - coreutils - aws-vault - ])}:$PATH" + # Handle help flag + if [[ "$#" -gt 0 && "$1" == "--help" ]]; then + show_help + exit 0 + fi - # 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 + export PATH="${pkgs.lib.makeBinPath (with pkgs; [ + packer + awscli2 + yq + jq + openssl + git + coreutils + aws-vault + ])}:$PATH" - # Check AWS Vault profile - if [ -z "''${AWS_VAULT:-}" ]; then - echo "Error: AWS_VAULT environment variable must be set with the profile name" - echo "Usage: aws-vault exec -- nix run .#build-test-ami " + # 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 - # Set values - REGION="ap-southeast-1" - POSTGRES_VERSION="$1" - RANDOM_STRING=$(openssl rand -hex 8) - GIT_SHA=$(git rev-parse HEAD) - RUN_ID=$(date +%s) - - # Generate common-nix.vars.pkr.hcl - PG_VERSION=$(yq -r ".postgres_release[\"postgres$POSTGRES_VERSION\"]" ansible/vars.yml) - echo "postgres-version = \"$PG_VERSION\"" > common-nix.vars.pkr.hcl - - # Build AMI Stage 1 - packer init amazon-arm64-nix.pkr.hcl - packer build \ - -var "git-head-version=$GIT_SHA" \ - -var "packer-execution-id=$RUN_ID" \ - -var-file="development-arm.vars.pkr.hcl" \ - -var-file="common-nix.vars.pkr.hcl" \ - -var "ansible_arguments=" \ - -var "postgres-version=$RANDOM_STRING" \ - -var "region=$REGION" \ - -var 'ami_regions=["'"$REGION"'"]' \ - -var "force-deregister=true" \ - -var "ansible_arguments=-e postgresql_major=$POSTGRES_VERSION" \ - amazon-arm64-nix.pkr.hcl - - # Build AMI Stage 2 - packer init stage2-nix-psql.pkr.hcl - packer build \ - -var "git-head-version=$GIT_SHA" \ - -var "packer-execution-id=$RUN_ID" \ - -var "postgres_major_version=$POSTGRES_VERSION" \ - -var-file="development-arm.vars.pkr.hcl" \ - -var-file="common-nix.vars.pkr.hcl" \ - -var "postgres-version=$RANDOM_STRING" \ - -var "region=$REGION" \ - -var 'ami_regions=["'"$REGION"'"]' \ - -var "force-deregister=true" \ - -var "git_sha=$GIT_SHA" \ - stage2-nix-psql.pkr.hcl - - # Cleanup instances from AMI builds - cleanup_instances() { - echo "Terminating EC2 instances with tag testinfra-run-id=$RUN_ID..." - aws ec2 --region $REGION describe-instances \ - --filters "Name=tag:testinfra-run-id,Values=$RUN_ID" \ - --query "Reservations[].Instances[].InstanceId" \ - --output text | xargs -r aws ec2 terminate-instances \ - --region $REGION --instance-ids || true - } - - # Set up traps for various signals to ensure cleanup - trap cleanup_instances EXIT HUP INT QUIT TERM - - # Create and activate virtual environment - VENV_DIR=$(mktemp -d) - trap 'rm -rf "$VENV_DIR"' EXIT HUP INT QUIT TERM - python3 -m venv "$VENV_DIR" - 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 - - # 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 + # Check AWS Vault profile + if [ -z "''${AWS_VAULT:-}" ]; then + echo "Error: AWS_VAULT environment variable must be set with the profile name" + echo "Usage: aws-vault exec -- nix run .#build-test-ami " + exit 1 + fi - # Deactivate virtual environment (cleanup is handled by trap) - deactivate - EOL - chmod +x $out/bin/build-test-ami - ''; + # Set values + REGION="ap-southeast-1" + POSTGRES_VERSION="$1" + RANDOM_STRING=$(openssl rand -hex 8) + GIT_SHA=$(git rev-parse HEAD) + RUN_ID=$(date +%s) + + # Generate common-nix.vars.pkr.hcl + PG_VERSION=$(yq -r ".postgres_release[\"postgres$POSTGRES_VERSION\"]" ansible/vars.yml) + echo "postgres-version = \"$PG_VERSION\"" > common-nix.vars.pkr.hcl + + # Build AMI Stage 1 + packer init amazon-arm64-nix.pkr.hcl + packer build \ + -var "git-head-version=$GIT_SHA" \ + -var "packer-execution-id=$RUN_ID" \ + -var-file="development-arm.vars.pkr.hcl" \ + -var-file="common-nix.vars.pkr.hcl" \ + -var "ansible_arguments=" \ + -var "postgres-version=$RANDOM_STRING" \ + -var "region=$REGION" \ + -var 'ami_regions=["'"$REGION"'"]' \ + -var "force-deregister=true" \ + -var "ansible_arguments=-e postgresql_major=$POSTGRES_VERSION" \ + amazon-arm64-nix.pkr.hcl + + # Build AMI Stage 2 + packer init stage2-nix-psql.pkr.hcl + packer build \ + -var "git-head-version=$GIT_SHA" \ + -var "packer-execution-id=$RUN_ID" \ + -var "postgres_major_version=$POSTGRES_VERSION" \ + -var-file="development-arm.vars.pkr.hcl" \ + -var-file="common-nix.vars.pkr.hcl" \ + -var "postgres-version=$RANDOM_STRING" \ + -var "region=$REGION" \ + -var 'ami_regions=["'"$REGION"'"]' \ + -var "force-deregister=true" \ + -var "git_sha=$GIT_SHA" \ + stage2-nix-psql.pkr.hcl + + # Cleanup instances from AMI builds + cleanup_instances() { + echo "Terminating EC2 instances with tag testinfra-run-id=$RUN_ID..." + aws ec2 --region $REGION describe-instances \ + --filters "Name=tag:testinfra-run-id,Values=$RUN_ID" \ + --query "Reservations[].Instances[].InstanceId" \ + --output text | xargs -r aws ec2 terminate-instances \ + --region $REGION --instance-ids || true + } + + # Set up traps for various signals to ensure cleanup + trap cleanup_instances EXIT HUP INT QUIT TERM + ''; run-testinfra = pkgs.runCommand "run-testinfra" { @@ -805,7 +772,7 @@ show_help() { cat << EOF - Usage: run-testinfra --ami-name NAME [--aws-vault-profile PROFILE] + Usage: run-testinfra --ami-name NAME [--aws-vault-profile PROFILE] [--postgres-version VERSION] Run the testinfra tests locally against a specific AMI. @@ -822,6 +789,7 @@ Optional flags: --aws-vault-profile PROFILE AWS Vault profile to use (default: staging) + --postgres-version VERSION PostgreSQL major version to test (default: 15) --help Show this help message and exit Requirements: @@ -832,12 +800,14 @@ Examples: run-testinfra --ami-name supabase-postgres-abc123 run-testinfra --ami-name supabase-postgres-abc123 --aws-vault-profile production + run-testinfra --ami-name supabase-postgres-abc123 --postgres-version 15 EOF } # Default values AWS_VAULT_PROFILE="staging" AMI_NAME="" + POSTGRES_MAJOR_VERSION="15" # Parse arguments while [[ $# -gt 0 ]]; do @@ -850,6 +820,10 @@ AMI_NAME="$2" shift 2 ;; + --postgres-version) + POSTGRES_MAJOR_VERSION="$2" + shift 2 + ;; --help) show_help exit 0 @@ -880,6 +854,7 @@ export AWS_DEFAULT_REGION="ap-southeast-1" export AMI_NAME="$AMI_NAME" # Export AMI_NAME for pytest export RUN_ID="local-$(date +%s)" # Generate a unique RUN_ID + export POSTGRES_MAJOR_VERSION="$POSTGRES_MAJOR_VERSION" # Export PostgreSQL version for pytest # Function to terminate EC2 instances terminate_instances() { diff --git a/nix/ext/pg_cron-1.3.1-pg15.patch b/nix/ext/pg_cron-1.3.1-pg15.patch new file mode 100644 index 000000000..d3b6cd702 --- /dev/null +++ b/nix/ext/pg_cron-1.3.1-pg15.patch @@ -0,0 +1,31 @@ +diff --git a/src/pg_cron.c b/src/pg_cron.c +index e0ca973..4d51b2c 100644 +--- a/src/pg_cron.c ++++ b/src/pg_cron.c +@@ -14,6 +14,8 @@ + #include + + #include "postgres.h" ++#include "commands/async.h" ++#include "miscadmin.h" + #include "fmgr.h" + + /* these are always necessary for a bgworker */ +@@ -1908,7 +1910,7 @@ CronBackgroundWorker(Datum main_arg) + /* Post-execution cleanup. */ + disable_timeout(STATEMENT_TIMEOUT, false); + CommitTransactionCommand(); +- ProcessCompletedNotifies(); ++ /* ProcessCompletedNotifies removed */ + pgstat_report_activity(STATE_IDLE, command); + pgstat_report_stat(true); + +@@ -2025,7 +2027,7 @@ ExecuteSqlString(const char *sql) + */ + oldcontext = MemoryContextSwitchTo(parsecontext); + #if PG_VERSION_NUM >= 100000 +- querytree_list = pg_analyze_and_rewrite(parsetree, sql, NULL, 0,NULL); ++ querytree_list = pg_analyze_and_rewrite_fixedparams(parsetree, sql, NULL, 0, NULL); + #else + querytree_list = pg_analyze_and_rewrite(parsetree, sql, NULL, 0); + #endif diff --git a/nix/ext/pg_cron.nix b/nix/ext/pg_cron.nix index 792db7676..cee4f1069 100644 --- a/nix/ext/pg_cron.nix +++ b/nix/ext/pg_cron.nix @@ -1,31 +1,171 @@ { lib, stdenv, fetchFromGitHub, postgresql }: -stdenv.mkDerivation rec { - pname = "pg_cron"; - version = "1.6.4"; +let + allVersions = { + "1.3.1" = { + rev = "v1.3.1"; + hash = "sha256-rXotNOtQNmA55ErNxGoNSKZ0pP1uxEVlDGITFHuqGG4="; + patches = [ ./pg_cron-1.3.1-pg15.patch ]; + }; + "1.4.2" = { + rev = "v1.4.2"; + hash = "sha256-P0Fd10Q1p+KrExb35G6otHpc6pD61WnMll45H2jkevM="; + }; + "1.6.4" = { + rev = "v1.6.4"; + hash = "sha256-t1DpFkPiSfdoGG2NgNT7g1lkvSooZoRoUrix6cBID40="; + }; + "1.5.2" = { + rev = "v1.5.2"; + hash = "sha256-+quVWbKJy6wXpL/zwTk5FF7sYwHA7I97WhWmPO/HSZ4="; + }; + }; + + # Simple version string that concatenates all versions with dashes + versionString = "multi-" + lib.concatStringsSep "-" (map (v: lib.replaceStrings ["."] ["-"] v) (lib.attrNames allVersions)); + + mkPgCron = pgCronVersion: { rev, hash, patches ? [] }: stdenv.mkDerivation { + pname = "pg_cron"; + version = "${pgCronVersion}-pg${lib.versions.major postgresql.version}"; + + buildInputs = [ postgresql ]; + inherit patches; + + src = fetchFromGitHub { + owner = "citusdata"; + repo = "pg_cron"; + inherit rev hash; + }; - buildInputs = [ postgresql ]; + buildPhase = '' + make PG_CONFIG=${postgresql}/bin/pg_config + + # Create version-specific SQL file + cp pg_cron.sql pg_cron--${pgCronVersion}.sql - src = fetchFromGitHub { - owner = "citusdata"; - repo = pname; - rev = "v${version}"; - hash = "sha256-t1DpFkPiSfdoGG2NgNT7g1lkvSooZoRoUrix6cBID40="; + # Create versioned control file with modified module path + sed -e "/^default_version =/d" \ + -e "s|^module_pathname = .*|module_pathname = '\$libdir/pg_cron'|" \ + pg_cron.control > pg_cron--${pgCronVersion}.control + ''; + + installPhase = '' + mkdir -p $out/{lib,share/postgresql/extension,bin} + + # Install versioned library + install -Dm755 pg_cron${postgresql.dlSuffix} $out/lib/pg_cron-${pgCronVersion}${postgresql.dlSuffix} + + # Install version-specific files + install -Dm644 pg_cron--${pgCronVersion}.sql $out/share/postgresql/extension/ + install -Dm644 pg_cron--${pgCronVersion}.control $out/share/postgresql/extension/ + + # Install upgrade scripts + find . -name 'pg_cron--*--*.sql' -exec install -Dm644 {} $out/share/postgresql/extension/ \; + ''; }; + getVersions = pg: + if lib.versionAtLeast pg.version "17" + then { "1.6.4" = allVersions."1.6.4"; } + else allVersions; + + allVersionsForPg = lib.mapAttrs mkPgCron (getVersions postgresql); + +in +stdenv.mkDerivation { + pname = "pg_cron-all"; + version = versionString; + + buildInputs = lib.attrValues allVersionsForPg; + + dontUnpack = true; + dontConfigure = true; + dontBuild = true; + installPhase = '' - mkdir -p $out/{lib,share/postgresql/extension} + mkdir -p $out/{lib,share/postgresql/extension,bin} + + # Install all versions + for drv in ${lib.concatStringsSep " " (lib.attrValues allVersionsForPg)}; do + ln -sv $drv/lib/* $out/lib/ + cp -v --no-clobber $drv/share/postgresql/extension/* $out/share/postgresql/extension/ || true + done + + # Create default symlinks + latest_control=$(ls -v $out/share/postgresql/extension/pg_cron--*.control | tail -n1) + latest_version=$(basename "$latest_control" | sed -E 's/pg_cron--([0-9.]+).control/\1/') + + # Create main control file with default_version + echo "default_version = '$latest_version'" > $out/share/postgresql/extension/pg_cron.control + cat "$latest_control" >> $out/share/postgresql/extension/pg_cron.control + + # Library symlink + ln -sfnv pg_cron-$latest_version${postgresql.dlSuffix} $out/lib/pg_cron${postgresql.dlSuffix} + + # Create version switcher script + cat > $out/bin/switch_pg_cron_version <<'EOF' + #!/bin/sh + set -e + + if [ $# -ne 1 ]; then + echo "Usage: $0 " + echo "Example: $0 1.4.2" + exit 1 + fi + + VERSION=$1 + NIX_PROFILE="/var/lib/postgresql/.nix-profile" + + # Follow the complete chain of symlinks to find the multi-version directory + CURRENT_LINK="$NIX_PROFILE/lib/pg_cron-$VERSION${postgresql.dlSuffix}" + echo "Starting with link: $CURRENT_LINK" + + # Follow first two symlinks to get to the multi-version directory + for i in 1 2; do + if [ -L "$CURRENT_LINK" ]; then + NEXT_LINK=$(readlink "$CURRENT_LINK") + echo "Following link: $NEXT_LINK" + if echo "$NEXT_LINK" | grep -q '^/'; then + CURRENT_LINK="$NEXT_LINK" + else + CURRENT_LINK="$(dirname "$CURRENT_LINK")/$NEXT_LINK" + fi + echo "Current link is now: $CURRENT_LINK" + fi + done + + # The multi-version directory should be the parent of the current link + MULTI_VERSION_DIR=$(dirname "$CURRENT_LINK") + echo "Found multi-version directory: $MULTI_VERSION_DIR" + LIB_DIR="$MULTI_VERSION_DIR" + EXTENSION_DIR="$NIX_PROFILE/share/postgresql/extension" + + echo "Looking for file: $LIB_DIR/pg_cron-$VERSION${postgresql.dlSuffix}" + ls -la "$LIB_DIR" || true + + # Check if version exists + if [ ! -f "$LIB_DIR/pg_cron-$VERSION${postgresql.dlSuffix}" ]; then + echo "Error: Version $VERSION not found" + exit 1 + fi + + # Update library symlink + ln -sfnv "pg_cron-$VERSION${postgresql.dlSuffix}" "$LIB_DIR/pg_cron${postgresql.dlSuffix}" + + # Update control file + echo "default_version = '$VERSION'" > "$EXTENSION_DIR/pg_cron.control" + cat "$EXTENSION_DIR/pg_cron--$VERSION.control" >> "$EXTENSION_DIR/pg_cron.control" + + echo "Successfully switched pg_cron to version $VERSION" + EOF - cp *${postgresql.dlSuffix} $out/lib - cp *.sql $out/share/postgresql/extension - cp *.control $out/share/postgresql/extension + chmod +x $out/bin/switch_pg_cron_version ''; meta = with lib; { - description = "Run Cron jobs through PostgreSQL"; - homepage = "https://github.com/citusdata/pg_cron"; - changelog = "https://github.com/citusdata/pg_cron/raw/v${version}/CHANGELOG.md"; - platforms = postgresql.meta.platforms; - license = licenses.postgresql; + description = "Run Cron jobs through PostgreSQL (multi-version compatible)"; + homepage = "https://github.com/citusdata/pg_cron"; + platforms = postgresql.meta.platforms; + license = licenses.postgresql; }; }