Compare commits
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
freebsd_instance:
|
freebsd_instance:
|
||||||
image_family: freebsd-14-0
|
image_family: freebsd-14-1
|
||||||
|
|
||||||
build_task:
|
build_task:
|
||||||
# Don't change this name without adjusting .github/workflows/build.yaml
|
# Don't change this name without adjusting .github/workflows/build.yaml
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# TODO: Remove this once a new actionlint release has been cut
|
||||||
|
# and made its way to us through nixpkgs.
|
||||||
|
self-hosted-runner:
|
||||||
|
labels:
|
||||||
|
- ubuntu-24.04-arm
|
||||||
@@ -112,7 +112,7 @@ runs:
|
|||||||
echo "artifacts=${artifacts}" >> "$GITHUB_OUTPUT"
|
echo "artifacts=${artifacts}" >> "$GITHUB_OUTPUT"
|
||||||
- name: Save artifact to GitHub Actions
|
- name: Save artifact to GitHub Actions
|
||||||
if: steps.find-task.outputs.task_found
|
if: steps.find-task.outputs.task_found
|
||||||
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
|
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||||
with:
|
with:
|
||||||
name: ${{ inputs.upload }}
|
name: ${{ inputs.upload }}
|
||||||
path: ${{ steps.download.outputs.artifacts }}
|
path: ${{ steps.download.outputs.artifacts }}
|
||||||
|
|||||||
@@ -19,14 +19,14 @@ inputs:
|
|||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
|
- uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
|
||||||
if: ${{ startsWith(github.ref, 'refs/heads/') || (inputs.save-prs && startsWith(github.ref, 'refs/pull/')) }}
|
if: ${{ startsWith(github.ref, 'refs/heads/') || (inputs.save-prs && startsWith(github.ref, 'refs/pull/')) }}
|
||||||
with:
|
with:
|
||||||
path: ${{ inputs.path }}
|
path: ${{ inputs.path }}
|
||||||
key: ${{ runner.os }}-${{ inputs.prefix }}-${{ inputs.suffix }}
|
key: ${{ runner.os }}-${{ inputs.prefix }}-${{ inputs.suffix }}
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-${{ inputs.prefix }}-
|
${{ runner.os }}-${{ inputs.prefix }}-
|
||||||
- uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
|
- uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
|
||||||
if: ${{ !startsWith(github.ref, 'refs/heads/') && !(inputs.save-prs && startsWith(github.ref, 'refs/pull/')) }}
|
if: ${{ !startsWith(github.ref, 'refs/heads/') && !(inputs.save-prs && startsWith(github.ref, 'refs/pull/')) }}
|
||||||
with:
|
with:
|
||||||
path: ${{ inputs.path }}
|
path: ${{ inputs.path }}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ inputs:
|
|||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
- uses: nixbuild/nix-quick-install-action@60e9c39264d4714139af3cdf15f691b19eec3530 # v28
|
- uses: nixbuild/nix-quick-install-action@25aff27c252e0c8cdda3264805f7b6bcd92c8718 # v29
|
||||||
with:
|
with:
|
||||||
nix_conf: |-
|
nix_conf: |-
|
||||||
always-allow-substitutes = true
|
always-allow-substitutes = true
|
||||||
@@ -20,6 +20,7 @@ runs:
|
|||||||
with:
|
with:
|
||||||
name: postgrest
|
name: postgrest
|
||||||
authToken: ${{ inputs.authToken }}
|
authToken: ${{ inputs.authToken }}
|
||||||
|
skipPush: ${{ inputs.authToken == '' }}
|
||||||
- if: ${{ inputs.tools }}
|
- if: ${{ inputs.tools }}
|
||||||
run: nix-env -f default.nix -iA ${{ inputs.tools }}
|
run: nix-env -f default.nix -iA ${{ inputs.tools }}
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -Eeuo pipefail
|
|
||||||
|
|
||||||
# This script builds PostgREST in a remote ARM server
|
|
||||||
|
|
||||||
[ -z "$1" ] && { echo "Missing 1st argument: PostgREST github commit SHA"; exit 1; }
|
|
||||||
[ -z "$2" ] && { echo "Missing 2nd argument: Build environment directory name"; exit 1; }
|
|
||||||
[ -z "$3" ] && { echo "Missing 3rd argument: GHC version"; exit 1; }
|
|
||||||
|
|
||||||
PGRST_GITHUB_COMMIT="$1"
|
|
||||||
SCRIPT_DIR="$2"
|
|
||||||
|
|
||||||
DOCKER_BUILD_DIR="$SCRIPT_DIR/docker-env"
|
|
||||||
# latest is a shortcut documented on https://www.haskell.org/ghcup/guide/#tags-and-shortcuts
|
|
||||||
CABAL_VERSION="latest"
|
|
||||||
GHC_VERSION="$3"
|
|
||||||
|
|
||||||
install_packages() {
|
|
||||||
sudo apt-get update -y
|
|
||||||
sudo apt-get upgrade -y
|
|
||||||
sudo apt-get install -y git build-essential curl libffi-dev libffi7 libgmp-dev libgmp10 libncurses-dev libncurses5 libtinfo5 llvm libnuma-dev zlib1g-dev libpq-dev jq gcc
|
|
||||||
sudo apt-get clean
|
|
||||||
}
|
|
||||||
|
|
||||||
install_ghcup() {
|
|
||||||
export BOOTSTRAP_HASKELL_NONINTERACTIVE=1
|
|
||||||
export BOOTSTRAP_HASKELL_MINIMAL=1
|
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
|
|
||||||
source ~/.ghcup/env
|
|
||||||
}
|
|
||||||
|
|
||||||
install_cabal() {
|
|
||||||
ghcup upgrade
|
|
||||||
ghcup install cabal $CABAL_VERSION
|
|
||||||
ghcup set cabal $CABAL_VERSION
|
|
||||||
}
|
|
||||||
|
|
||||||
install_ghc() {
|
|
||||||
ghcup upgrade
|
|
||||||
ghcup install ghc $GHC_VERSION
|
|
||||||
ghcup set ghc $GHC_VERSION
|
|
||||||
}
|
|
||||||
|
|
||||||
install_packages
|
|
||||||
|
|
||||||
# Add ghcup to the PATH for this session
|
|
||||||
[ -f ~/.ghcup/env ] && source ~/.ghcup/env
|
|
||||||
|
|
||||||
ghcup --version || install_ghcup
|
|
||||||
ghcup set cabal $CABAL_VERSION || install_cabal
|
|
||||||
ghcup set ghc $GHC_VERSION || install_ghc
|
|
||||||
|
|
||||||
cd ~/$SCRIPT_DIR
|
|
||||||
|
|
||||||
# Clone the repository and build the project
|
|
||||||
git clone https://github.com/PostgREST/postgrest.git
|
|
||||||
cd postgrest
|
|
||||||
git checkout $PGRST_GITHUB_COMMIT
|
|
||||||
cabal v2-update && cabal v2-build
|
|
||||||
|
|
||||||
# Strip unused symbols from executable
|
|
||||||
PGRST_BIN=$(cabal exec which postgrest | tail -1)
|
|
||||||
strip $PGRST_BIN
|
|
||||||
|
|
||||||
# Copy the built binary to the Dockerfile directory
|
|
||||||
cp $PGRST_BIN ~/$DOCKER_BUILD_DIR
|
|
||||||
|
|
||||||
# Move and compress the built binary
|
|
||||||
mkdir -p ~/$SCRIPT_DIR/result
|
|
||||||
mv $PGRST_BIN ~/$SCRIPT_DIR/result
|
|
||||||
cd ~/$SCRIPT_DIR
|
|
||||||
tar -cJf result.tar.xz result
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -Eeuo pipefail
|
|
||||||
|
|
||||||
# This script publishes the Docker ARM images to Docker Hub.
|
|
||||||
|
|
||||||
[ -z "$1" ] && { echo "Missing 1st argument: PostgREST github commit SHA"; exit 1; }
|
|
||||||
[ -z "$2" ] && { echo "Missing 2nd argument: Docker repo"; exit 1; }
|
|
||||||
[ -z "$3" ] && { echo "Missing 3rd argument: Docker username"; exit 1; }
|
|
||||||
[ -z "$4" ] && { echo "Missing 4th argument: Docker password"; exit 1; }
|
|
||||||
[ -z "$5" ] && { echo "Missing 5th argument: Build environment directory name"; exit 1; }
|
|
||||||
[ -z "$6" ] && { echo "Missing 6th argument: PostgREST version"; exit 1; }
|
|
||||||
|
|
||||||
PGRST_GITHUB_COMMIT="$1"
|
|
||||||
DOCKER_REPO="$2"
|
|
||||||
DOCKER_USER="$3"
|
|
||||||
DOCKER_PASS="$4"
|
|
||||||
SCRIPT_DIR="$5"
|
|
||||||
PGRST_VERSION="$6"
|
|
||||||
|
|
||||||
DOCKER_BUILD_DIR="$SCRIPT_DIR/docker-env"
|
|
||||||
|
|
||||||
clean_env()
|
|
||||||
{
|
|
||||||
sudo docker logout
|
|
||||||
}
|
|
||||||
|
|
||||||
# Login to Docker
|
|
||||||
sudo docker logout
|
|
||||||
{ echo $DOCKER_PASS | sudo docker login -u $DOCKER_USER --password-stdin; } || { echo "Couldn't login to docker"; exit 1; }
|
|
||||||
|
|
||||||
trap clean_env sigint sigterm exit
|
|
||||||
|
|
||||||
# Move to the docker build environment
|
|
||||||
cd ~/$DOCKER_BUILD_DIR
|
|
||||||
|
|
||||||
# Push final images to Docker hub
|
|
||||||
# NOTE: This command publishes a separate ARM image because the builds cannot
|
|
||||||
# be added to the manifest if they are not in the registry beforehand.
|
|
||||||
# This image must be manually deleted from Docker Hub at the end of the process.
|
|
||||||
sudo docker buildx build --build-arg PGRST_GITHUB_COMMIT=$PGRST_GITHUB_COMMIT \
|
|
||||||
-t $DOCKER_REPO/postgrest:$PGRST_VERSION-arm \
|
|
||||||
--push .
|
|
||||||
|
|
||||||
# Add the arm images to the manifest
|
|
||||||
# NOTE: This assumes that there already is a `postgrest:<version>` image
|
|
||||||
# for the amd64 architecture pushed to Docker Hub
|
|
||||||
sudo docker buildx imagetools create --append -t $DOCKER_REPO/postgrest:$PGRST_VERSION $DOCKER_REPO/postgrest:$PGRST_VERSION-arm
|
|
||||||
[ "$PGRST_VERSION" != "devel" ] && sudo docker buildx imagetools create --append -t $DOCKER_REPO/postgrest:latest $DOCKER_REPO/postgrest:$PGRST_VERSION-arm
|
|
||||||
|
|
||||||
sudo docker logout
|
|
||||||
@@ -30,10 +30,10 @@ concurrency:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
static:
|
static:
|
||||||
name: Nix - Linux static
|
name: Nix - Linux x86-64 static
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- name: Setup Nix Environment
|
- name: Setup Nix Environment
|
||||||
uses: ./.github/actions/setup-nix
|
uses: ./.github/actions/setup-nix
|
||||||
with:
|
with:
|
||||||
@@ -42,27 +42,27 @@ jobs:
|
|||||||
- name: Build static executable
|
- name: Build static executable
|
||||||
run: nix-build -A postgrestStatic
|
run: nix-build -A postgrestStatic
|
||||||
- name: Save built executable as artifact
|
- name: Save built executable as artifact
|
||||||
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
|
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||||
with:
|
with:
|
||||||
name: postgrest-linux-static-x64
|
name: postgrest-linux-static-x86-64
|
||||||
path: result/bin/postgrest
|
path: result/bin/postgrest
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
- name: Build Docker image
|
- name: Build Docker image
|
||||||
run: nix-build -A docker.image --out-link postgrest-docker.tar.gz
|
run: nix-build -A docker.image --out-link postgrest-docker.tar.gz
|
||||||
- name: Save built Docker image as artifact
|
- name: Save built Docker image as artifact
|
||||||
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
|
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||||
with:
|
with:
|
||||||
name: postgrest-docker-x64
|
name: postgrest-docker-x86-64
|
||||||
path: postgrest-docker.tar.gz
|
path: postgrest-docker.tar.gz
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
|
|
||||||
macos:
|
macos:
|
||||||
name: Nix - MacOS
|
name: Nix - MacOS
|
||||||
runs-on: macos-12
|
runs-on: macos-14
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- name: Setup Nix Environment
|
- name: Setup Nix Environment
|
||||||
uses: ./.github/actions/setup-nix
|
uses: ./.github/actions/setup-nix
|
||||||
with:
|
with:
|
||||||
@@ -87,39 +87,38 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- name: Linux
|
- name: Linux aarch64
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04-arm
|
||||||
cache: |
|
cache: |
|
||||||
~/.stack/pantry
|
~/.stack/pantry
|
||||||
~/.stack/snapshots
|
~/.stack/snapshots
|
||||||
~/.stack/stack.sqlite3
|
~/.stack/stack.sqlite3
|
||||||
# no artifact for Linux, because we use the static build
|
artifact: postgrest-ubuntu-aarch64
|
||||||
|
deps: sudo apt-get update && sudo apt-get install libpq-dev
|
||||||
|
|
||||||
- name: MacOS
|
- name: MacOS
|
||||||
runs-on: macos-12
|
runs-on: macos-14
|
||||||
cache: |
|
cache: |
|
||||||
~/.stack/pantry
|
~/.stack/pantry
|
||||||
~/.stack/snapshots
|
~/.stack/snapshots
|
||||||
~/.stack/stack.sqlite3
|
~/.stack/stack.sqlite3
|
||||||
artifact: postgrest-macos-x64
|
artifact: postgrest-macos-aarch64
|
||||||
|
deps: brew link --force libpq
|
||||||
|
|
||||||
- name: Windows
|
- name: Windows
|
||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
cache: |
|
cache: |
|
||||||
~\AppData\Roaming\stack\pantry
|
C:\sr\pantry
|
||||||
~\AppData\Local\Programs\stack\pantry
|
C:\sr\snapshots
|
||||||
~\AppData\Roaming\stack\snapshots
|
C:\sr\stack.sqlite3
|
||||||
~\AppData\Local\Programs\stack\snapshots
|
|
||||||
~\AppData\Roaming\stack\stack.sqlite3
|
|
||||||
~\AppData\Local\Programs\stack\stack.sqlite3
|
|
||||||
deps: Add-Content $env:GITHUB_PATH $env:PGBIN
|
deps: Add-Content $env:GITHUB_PATH $env:PGBIN
|
||||||
artifact: postgrest-windows-x64
|
artifact: postgrest-windows-x86-64
|
||||||
|
|
||||||
name: Stack - ${{ matrix.name }}
|
name: Stack - ${{ matrix.name }}
|
||||||
runs-on: ${{ matrix.runs-on }}
|
runs-on: ${{ matrix.runs-on }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- uses: haskell-actions/setup@ec49483bfc012387b227434aba94f59a6ecd0900 # v2.7.5
|
- uses: haskell-actions/setup@bbd90a29996ac33b1c644a42206e312fc0379748 # v2.7.9
|
||||||
with:
|
with:
|
||||||
# This must match the version in stack.yaml's resolver
|
# This must match the version in stack.yaml's resolver
|
||||||
ghc-version: 9.6.5
|
ghc-version: 9.6.5
|
||||||
@@ -147,8 +146,7 @@ jobs:
|
|||||||
- name: Strip Executable
|
- name: Strip Executable
|
||||||
run: strip result/postgrest*
|
run: strip result/postgrest*
|
||||||
- name: Save built executable as artifact
|
- name: Save built executable as artifact
|
||||||
if: matrix.artifact
|
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||||
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
|
|
||||||
with:
|
with:
|
||||||
name: ${{ matrix.artifact }}
|
name: ${{ matrix.artifact }}
|
||||||
path: |
|
path: |
|
||||||
@@ -159,15 +157,15 @@ jobs:
|
|||||||
|
|
||||||
freebsd:
|
freebsd:
|
||||||
name: Stack - FreeBSD from CirrusCI
|
name: Stack - FreeBSD from CirrusCI
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- uses: ./.github/actions/artifact-from-cirrus
|
- uses: ./.github/actions/artifact-from-cirrus
|
||||||
with:
|
with:
|
||||||
token: ${{ github.token }}
|
token: ${{ github.token }}
|
||||||
task: Build FreeBSD (Stack)
|
task: Build FreeBSD (Stack)
|
||||||
download: bin
|
download: bin
|
||||||
upload: postgrest-freebsd-x64
|
upload: postgrest-freebsd-x86-64
|
||||||
|
|
||||||
|
|
||||||
cabal:
|
cabal:
|
||||||
@@ -175,11 +173,11 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
ghc: ['9.6.4', '9.8.2']
|
ghc: ['9.6.4', '9.8.2']
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
name: Cabal - Linux GHC ${{ matrix.ghc }}
|
name: Cabal - Linux x86-64 - GHC ${{ matrix.ghc }}
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- uses: haskell-actions/setup@ec49483bfc012387b227434aba94f59a6ecd0900 # v2.7.5
|
- uses: haskell-actions/setup@bbd90a29996ac33b1c644a42206e312fc0379748 # v2.7.9
|
||||||
with:
|
with:
|
||||||
ghc-version: ${{ matrix.ghc }}
|
ghc-version: ${{ matrix.ghc }}
|
||||||
- name: Cache .cabal
|
- name: Cache .cabal
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
lint-style:
|
lint-style:
|
||||||
name: Lint & Style
|
name: Lint & Style
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- name: Setup Nix Environment
|
- name: Setup Nix Environment
|
||||||
uses: ./.github/actions/setup-nix
|
uses: ./.github/actions/setup-nix
|
||||||
with:
|
with:
|
||||||
|
|||||||
+4
-296
@@ -5,21 +5,10 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- v[0-9]+
|
- v[0-9]+
|
||||||
tags:
|
|
||||||
- devel
|
|
||||||
- v*
|
|
||||||
|
|
||||||
concurrency:
|
|
||||||
# Terminate all previous runs of the same workflow for the same tag, but never
|
|
||||||
# cancel for the main / release branch pipelines.
|
|
||||||
group: ci-${{ (github.ref_type == 'tag' && github.ref) || github.run_id }}
|
|
||||||
# TODO: Enable this once https://github.com/orgs/community/discussions/13015 is solved
|
|
||||||
cancel-in-progress: false
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
name: Check
|
name: Check
|
||||||
if: startsWith(github.ref, 'refs/heads/')
|
|
||||||
uses: ./.github/workflows/check.yaml
|
uses: ./.github/workflows/check.yaml
|
||||||
secrets:
|
secrets:
|
||||||
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
||||||
@@ -27,7 +16,6 @@ jobs:
|
|||||||
|
|
||||||
docs:
|
docs:
|
||||||
name: Docs
|
name: Docs
|
||||||
if: startsWith(github.ref, 'refs/heads/')
|
|
||||||
uses: ./.github/workflows/docs.yaml
|
uses: ./.github/workflows/docs.yaml
|
||||||
secrets:
|
secrets:
|
||||||
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
||||||
@@ -35,7 +23,6 @@ jobs:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
name: Test
|
name: Test
|
||||||
if: startsWith(github.ref, 'refs/heads/')
|
|
||||||
uses: ./.github/workflows/test.yaml
|
uses: ./.github/workflows/test.yaml
|
||||||
secrets:
|
secrets:
|
||||||
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
||||||
@@ -49,87 +36,21 @@ jobs:
|
|||||||
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
||||||
|
|
||||||
|
|
||||||
arm:
|
|
||||||
name: Build / Cabal - aarch64 GHC 9.4.8
|
|
||||||
if: vars.SSH_ARM_ENABLED
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
outputs:
|
|
||||||
remotepath: ${{ steps.Remote-Dir.outputs.remotepath }}
|
|
||||||
env:
|
|
||||||
GITHUB_COMMIT: ${{ github.sha }}
|
|
||||||
GHC_VERSION: '9.4.8'
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
|
||||||
- id: Remote-Dir
|
|
||||||
name: Unique directory name for the remote build
|
|
||||||
run: echo "remotepath=postgrest-build-$(uuidgen)" >> "$GITHUB_OUTPUT"
|
|
||||||
- name: Copy script files to the remote server
|
|
||||||
uses: appleboy/scp-action@master
|
|
||||||
with:
|
|
||||||
host: ${{ secrets.SSH_ARM_HOST }}
|
|
||||||
username: ubuntu
|
|
||||||
key: ${{ secrets.SSH_ARM_PRIVATE_KEY }}
|
|
||||||
fingerprint: ${{ secrets.SSH_ARM_FINGERPRINT }}
|
|
||||||
source: ".github/scripts/arm/*"
|
|
||||||
target: ${{ steps.Remote-Dir.outputs.remotepath }}
|
|
||||||
strip_components: 3
|
|
||||||
- name: Build ARM
|
|
||||||
uses: appleboy/ssh-action@master
|
|
||||||
env:
|
|
||||||
REMOTE_DIR: ${{ steps.Remote-Dir.outputs.remotepath }}
|
|
||||||
with:
|
|
||||||
host: ${{ secrets.SSH_ARM_HOST }}
|
|
||||||
username: ubuntu
|
|
||||||
key: ${{ secrets.SSH_ARM_PRIVATE_KEY }}
|
|
||||||
fingerprint: ${{ secrets.SSH_ARM_FINGERPRINT }}
|
|
||||||
command_timeout: 120m
|
|
||||||
script_stop: true
|
|
||||||
envs: GITHUB_COMMIT,REMOTE_DIR,GHC_VERSION
|
|
||||||
script: bash ~/$REMOTE_DIR/build.sh "$GITHUB_COMMIT" "$REMOTE_DIR" "$GHC_VERSION"
|
|
||||||
- name: Download binaries from remote server
|
|
||||||
uses: nicklasfrahm/scp-action@main
|
|
||||||
with:
|
|
||||||
direction: download
|
|
||||||
host: ${{ secrets.SSH_ARM_HOST }}
|
|
||||||
username: ubuntu
|
|
||||||
key: ${{ secrets.SSH_ARM_PRIVATE_KEY }}
|
|
||||||
fingerprint: ${{ secrets.SSH_ARM_FINGERPRINT }}
|
|
||||||
source: "${{ steps.Remote-Dir.outputs.remotepath }}/result.tar.xz"
|
|
||||||
target: "result.tar.xz"
|
|
||||||
- name: Extract downloaded binaries
|
|
||||||
run: tar -xvf result.tar.xz && rm result.tar.xz
|
|
||||||
- name: Save aarch64 executable as artifact
|
|
||||||
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
|
|
||||||
with:
|
|
||||||
name: postgrest-ubuntu-aarch64
|
|
||||||
path: result/postgrest
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
|
|
||||||
tag:
|
tag:
|
||||||
name: Release / Tag
|
name: Tag
|
||||||
concurrency:
|
concurrency:
|
||||||
# Never tag outdated commits on the main branch by skipping superseded commits
|
# Never tag outdated commits on the main branch by skipping superseded commits
|
||||||
group: ci-tag-${{ (github.ref == 'refs/heads/main' && github.ref) || github.run_id }}
|
group: ci-tag-${{ (github.ref == 'refs/heads/main' && github.ref) || github.run_id }}
|
||||||
# TODO: Enable this once https://github.com/orgs/community/discussions/13015 is solved
|
# TODO: Enable this once https://github.com/orgs/community/discussions/13015 is solved
|
||||||
cancel-in-progress: false
|
cancel-in-progress: false
|
||||||
if: |
|
if: vars.RELEASE_ENABLED
|
||||||
vars.RELEASE_ENABLED &&
|
runs-on: ubuntu-24.04
|
||||||
startsWith(github.ref, 'refs/heads/') &&
|
|
||||||
needs.docs.result == 'success' &&
|
|
||||||
needs.test.result == 'success' &&
|
|
||||||
needs.build.result == 'success' &&
|
|
||||||
(needs.arm.result == 'skipped' || success())
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
needs:
|
needs:
|
||||||
- docs
|
- docs
|
||||||
- test
|
- test
|
||||||
- build
|
- build
|
||||||
- arm
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
with:
|
with:
|
||||||
ssh-key: ${{ secrets.POSTGREST_SSH_KEY }}
|
ssh-key: ${{ secrets.POSTGREST_SSH_KEY }}
|
||||||
- name: Tag latest commit
|
- name: Tag latest commit
|
||||||
@@ -147,216 +68,3 @@ jobs:
|
|||||||
git tag -f "devel"
|
git tag -f "devel"
|
||||||
git push -f origin "devel"
|
git push -f origin "devel"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
prepare:
|
|
||||||
name: Release / Prepare
|
|
||||||
if: |
|
|
||||||
startsWith(github.ref, 'refs/tags/') &&
|
|
||||||
needs.build.result == 'success' &&
|
|
||||||
(needs.arm.result == 'skipped' || success())
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
needs:
|
|
||||||
- build
|
|
||||||
- arm
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
|
||||||
- name: Check the version to be released
|
|
||||||
run: |
|
|
||||||
cabal_version="$(grep -oP '^version:\s*\K.*' postgrest.cabal)"
|
|
||||||
|
|
||||||
if [ "${GITHUB_REF_NAME}" != "devel" ] && [ "${GITHUB_REF_NAME}" != "v$cabal_version" ]; then
|
|
||||||
echo "Tagged version ($GITHUB_REF_NAME) does not match the one in postgrest.cabal (v$cabal_version). Aborting release..."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
- name: Identify changes from CHANGELOG.md
|
|
||||||
run: |
|
|
||||||
if [ "${GITHUB_REF_NAME}" == "devel" ]; then
|
|
||||||
echo "Getting unreleased changes..."
|
|
||||||
sed -n "1,/## Unreleased/d;/## \[/q;p" CHANGELOG.md > CHANGES.md
|
|
||||||
else
|
|
||||||
version="$(grep -oP '^version:\s*\K.*' postgrest.cabal)"
|
|
||||||
echo "Propper release, getting changes for version $version ..."
|
|
||||||
sed -n "1,/## \[$version\]/d;/## \[/q;p" CHANGELOG.md > CHANGES.md
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Relevant extract from CHANGELOG.md:"
|
|
||||||
cat CHANGES.md
|
|
||||||
- name: Save CHANGES.md as artifact
|
|
||||||
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
|
|
||||||
with:
|
|
||||||
name: release-changes
|
|
||||||
path: CHANGES.md
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
|
|
||||||
github:
|
|
||||||
name: Release / GitHub
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
needs:
|
|
||||||
- prepare
|
|
||||||
if: success() || needs.prepare.result == 'success'
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
|
||||||
- name: Download all artifacts
|
|
||||||
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
|
|
||||||
with:
|
|
||||||
path: artifacts
|
|
||||||
- name: Create release bundle with archives for all builds
|
|
||||||
run: |
|
|
||||||
find artifacts -type f -iname postgrest -exec chmod +x {} \;
|
|
||||||
|
|
||||||
mkdir -p release-bundle
|
|
||||||
|
|
||||||
tar cJvf "release-bundle/postgrest-${GITHUB_REF_NAME}-linux-static-x64.tar.xz" \
|
|
||||||
-C artifacts/postgrest-linux-static-x64 postgrest
|
|
||||||
|
|
||||||
tar cJvf "release-bundle/postgrest-${GITHUB_REF_NAME}-macos-x64.tar.xz" \
|
|
||||||
-C artifacts/postgrest-macos-x64 postgrest
|
|
||||||
|
|
||||||
tar cJvf "release-bundle/postgrest-${GITHUB_REF_NAME}-freebsd-x64.tar.xz" \
|
|
||||||
-C artifacts/postgrest-freebsd-x64 postgrest
|
|
||||||
|
|
||||||
tar cJvf "release-bundle/postgrest-${GITHUB_REF_NAME}-ubuntu-aarch64.tar.xz" \
|
|
||||||
-C artifacts/postgrest-ubuntu-aarch64 postgrest
|
|
||||||
|
|
||||||
zip "release-bundle/postgrest-${GITHUB_REF_NAME}-windows-x64.zip" \
|
|
||||||
artifacts/postgrest-windows-x64/postgrest.exe
|
|
||||||
|
|
||||||
- name: Save release bundle
|
|
||||||
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
|
|
||||||
with:
|
|
||||||
name: release-bundle
|
|
||||||
path: release-bundle
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
- name: Publish release on GitHub
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
run: |
|
|
||||||
echo "Releasing version ${GITHUB_REF_NAME} on GitHub..."
|
|
||||||
|
|
||||||
if [ "${GITHUB_REF_NAME}" == "devel" ]; then
|
|
||||||
# To replace the existing release, we must first delete the old assets,
|
|
||||||
# then modify the release, then add the new assets.
|
|
||||||
gh release view devel --json assets \
|
|
||||||
| jq -r '.assets[] | .name' \
|
|
||||||
| xargs -rn1 \
|
|
||||||
gh release delete-asset -y devel
|
|
||||||
gh release edit devel \
|
|
||||||
-t devel \
|
|
||||||
--verify-tag \
|
|
||||||
-F artifacts/release-changes/CHANGES.md \
|
|
||||||
--prerelease
|
|
||||||
gh release upload --clobber devel release-bundle/*
|
|
||||||
else
|
|
||||||
gh release create "${GITHUB_REF_NAME}" \
|
|
||||||
-t "${GITHUB_REF_NAME}" \
|
|
||||||
--verify-tag \
|
|
||||||
-F artifacts/release-changes/CHANGES.md \
|
|
||||||
release-bundle/*
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
docker:
|
|
||||||
name: Release / Docker Hub
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
needs:
|
|
||||||
- prepare
|
|
||||||
if: |
|
|
||||||
vars.DOCKER_REPO && vars.DOCKER_USER &&
|
|
||||||
(success() || needs.prepare.result == 'success')
|
|
||||||
env:
|
|
||||||
DOCKER_REPO: ${{ vars.DOCKER_REPO }}
|
|
||||||
DOCKER_USER: ${{ vars.DOCKER_USER }}
|
|
||||||
DOCKER_PASS: ${{ secrets.DOCKER_PASS }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
|
||||||
- name: Download Docker image
|
|
||||||
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
|
|
||||||
with:
|
|
||||||
name: postgrest-docker-x64
|
|
||||||
- name: Publish images on Docker Hub
|
|
||||||
run: |
|
|
||||||
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
|
|
||||||
docker load -i postgrest-docker.tar.gz
|
|
||||||
|
|
||||||
docker tag postgrest:latest "$DOCKER_REPO/postgrest:${GITHUB_REF_NAME}"
|
|
||||||
docker push "$DOCKER_REPO/postgrest:${GITHUB_REF_NAME}"
|
|
||||||
|
|
||||||
# Only tag 'latest' for full releases
|
|
||||||
if [ "${GITHUB_REF_NAME}" != "devel" ]; then
|
|
||||||
echo "Pushing to 'latest' tag for full release of ${GITHUB_REF_NAME} ..."
|
|
||||||
docker tag postgrest:latest "$DOCKER_REPO"/postgrest:latest
|
|
||||||
docker push "$DOCKER_REPO"/postgrest:latest
|
|
||||||
else
|
|
||||||
echo "Skipping push to 'latest' tag for pre-release..."
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
docker-description:
|
|
||||||
name: Release / Docker Hub Description
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
if: |
|
|
||||||
vars.DOCKER_REPO && vars.DOCKER_USER &&
|
|
||||||
github.ref == 'refs/tags/devel'
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
|
||||||
- uses: peter-evans/dockerhub-description@e98e4d1628a5f3be2be7c231e50981aee98723ae # v4.0.0
|
|
||||||
with:
|
|
||||||
username: ${{ vars.DOCKER_USER }}
|
|
||||||
password: ${{ secrets.DOCKER_PASS }}
|
|
||||||
repository: ${{ vars.DOCKER_REPO }}/postgrest
|
|
||||||
short-description: ${{ github.event.repository.description }}
|
|
||||||
readme-filepath: ./docker-hub-readme.md
|
|
||||||
|
|
||||||
|
|
||||||
docker-arm:
|
|
||||||
name: Release / Docker Hub Arm
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
needs:
|
|
||||||
- arm
|
|
||||||
- docker
|
|
||||||
env:
|
|
||||||
GITHUB_COMMIT: ${{ github.sha }}
|
|
||||||
DOCKER_REPO: ${{ vars.DOCKER_REPO }}
|
|
||||||
DOCKER_USER: ${{ vars.DOCKER_USER }}
|
|
||||||
DOCKER_PASS: ${{ secrets.DOCKER_PASS }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
|
||||||
- name: Publish images for ARM builds on Docker Hub
|
|
||||||
uses: appleboy/ssh-action@master
|
|
||||||
env:
|
|
||||||
REMOTE_DIR: ${{ needs.arm.outputs.remotepath }}
|
|
||||||
with:
|
|
||||||
host: ${{ secrets.SSH_ARM_HOST }}
|
|
||||||
username: ubuntu
|
|
||||||
key: ${{ secrets.SSH_ARM_PRIVATE_KEY }}
|
|
||||||
fingerprint: ${{ secrets.SSH_ARM_FINGERPRINT }}
|
|
||||||
script_stop: true
|
|
||||||
envs: GITHUB_COMMIT,DOCKER_REPO,DOCKER_USER,DOCKER_PASS,REMOTE_DIR,GITHUB_REF_NAME
|
|
||||||
script: bash ~/$REMOTE_DIR/docker-publish.sh "$GITHUB_COMMIT" "$DOCKER_REPO" "$DOCKER_USER" "$DOCKER_PASS" "$REMOTE_DIR" "$GITHUB_REF_NAME"
|
|
||||||
|
|
||||||
|
|
||||||
clean-arm:
|
|
||||||
name: Build / Cleanup
|
|
||||||
needs:
|
|
||||||
- arm
|
|
||||||
- docker-arm
|
|
||||||
if: ${{ always() && vars.SSH_ARM_ENABLED }}
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
env:
|
|
||||||
REMOTE_DIR: ${{ needs.arm.outputs.remotepath }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
|
||||||
- name: Remove uploaded files from server
|
|
||||||
uses: appleboy/ssh-action@master
|
|
||||||
with:
|
|
||||||
host: ${{ secrets.SSH_ARM_HOST }}
|
|
||||||
username: ubuntu
|
|
||||||
key: ${{ secrets.SSH_ARM_PRIVATE_KEY }}
|
|
||||||
fingerprint: ${{ secrets.SSH_ARM_FINGERPRINT }}
|
|
||||||
envs: REMOTE_DIR
|
|
||||||
script: rm -rf $REMOTE_DIR
|
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- name: Setup Nix Environment
|
- name: Setup Nix Environment
|
||||||
uses: ./.github/actions/setup-nix
|
uses: ./.github/actions/setup-nix
|
||||||
with:
|
with:
|
||||||
@@ -39,9 +39,9 @@ jobs:
|
|||||||
|
|
||||||
spellcheck:
|
spellcheck:
|
||||||
name: Spellcheck
|
name: Spellcheck
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- name: Setup Nix Environment
|
- name: Setup Nix Environment
|
||||||
uses: ./.github/actions/setup-nix
|
uses: ./.github/actions/setup-nix
|
||||||
with:
|
with:
|
||||||
@@ -56,9 +56,9 @@ jobs:
|
|||||||
linkcheck:
|
linkcheck:
|
||||||
name: Linkcheck
|
name: Linkcheck
|
||||||
if: github.base_ref == 'main'
|
if: github.base_ref == 'main'
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- name: Setup Nix Environment
|
- name: Setup Nix Environment
|
||||||
uses: ./.github/actions/setup-nix
|
uses: ./.github/actions/setup-nix
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- devel
|
||||||
|
- v*
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
# Terminate all previous runs of the same workflow for the same tag.
|
||||||
|
group: release-${{ github.ref }}
|
||||||
|
# TODO: Enable this once https://github.com/orgs/community/discussions/13015 is solved
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
uses: ./.github/workflows/build.yaml
|
||||||
|
secrets:
|
||||||
|
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
|
||||||
|
|
||||||
|
|
||||||
|
prepare:
|
||||||
|
name: Prepare
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
needs:
|
||||||
|
- build
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
|
- name: Check the version to be released
|
||||||
|
run: |
|
||||||
|
cabal_version="$(grep -oP '^version:\s*\K.*' postgrest.cabal)"
|
||||||
|
|
||||||
|
if [ "${GITHUB_REF_NAME}" != "devel" ] && [ "${GITHUB_REF_NAME}" != "v$cabal_version" ]; then
|
||||||
|
echo "Tagged version ($GITHUB_REF_NAME) does not match the one in postgrest.cabal (v$cabal_version). Aborting release..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
- name: Identify changes from CHANGELOG.md
|
||||||
|
run: |
|
||||||
|
if [ "${GITHUB_REF_NAME}" == "devel" ]; then
|
||||||
|
echo "Getting unreleased changes..."
|
||||||
|
sed -n "1,/## Unreleased/d;/## \[/q;p" CHANGELOG.md > CHANGES.md
|
||||||
|
else
|
||||||
|
version="$(grep -oP '^version:\s*\K.*' postgrest.cabal)"
|
||||||
|
echo "Propper release, getting changes for version $version ..."
|
||||||
|
sed -n "1,/## \[$version\]/d;/## \[/q;p" CHANGELOG.md > CHANGES.md
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Relevant extract from CHANGELOG.md:"
|
||||||
|
cat CHANGES.md
|
||||||
|
- name: Save CHANGES.md as artifact
|
||||||
|
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||||
|
with:
|
||||||
|
name: release-changes
|
||||||
|
path: CHANGES.md
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
|
||||||
|
github:
|
||||||
|
name: GitHub
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
needs:
|
||||||
|
- prepare
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
|
- name: Download all artifacts
|
||||||
|
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
|
||||||
|
with:
|
||||||
|
path: artifacts
|
||||||
|
- name: Create release bundle with archives for all builds
|
||||||
|
run: |
|
||||||
|
find artifacts -type f -iname postgrest -exec chmod +x {} \;
|
||||||
|
|
||||||
|
mkdir -p release-bundle
|
||||||
|
|
||||||
|
tar cJvf "release-bundle/postgrest-${GITHUB_REF_NAME}-linux-static-x86-64.tar.xz" \
|
||||||
|
-C artifacts/postgrest-linux-static-x86-64 postgrest
|
||||||
|
|
||||||
|
tar cJvf "release-bundle/postgrest-${GITHUB_REF_NAME}-macos-aarch64.tar.xz" \
|
||||||
|
-C artifacts/postgrest-macos-aarch64 postgrest
|
||||||
|
|
||||||
|
tar cJvf "release-bundle/postgrest-${GITHUB_REF_NAME}-freebsd-x86-64.tar.xz" \
|
||||||
|
-C artifacts/postgrest-freebsd-x86-64 postgrest
|
||||||
|
|
||||||
|
tar cJvf "release-bundle/postgrest-${GITHUB_REF_NAME}-ubuntu-aarch64.tar.xz" \
|
||||||
|
-C artifacts/postgrest-ubuntu-aarch64 postgrest
|
||||||
|
|
||||||
|
zip --junk-paths "release-bundle/postgrest-${GITHUB_REF_NAME}-windows-x86-64.zip" \
|
||||||
|
artifacts/postgrest-windows-x86-64/postgrest.exe
|
||||||
|
|
||||||
|
- name: Save release bundle
|
||||||
|
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
|
||||||
|
with:
|
||||||
|
name: release-bundle
|
||||||
|
path: release-bundle
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
- name: Publish release on GitHub
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
echo "Releasing version ${GITHUB_REF_NAME} on GitHub..."
|
||||||
|
|
||||||
|
if [ "${GITHUB_REF_NAME}" == "devel" ]; then
|
||||||
|
# To replace the existing release, we must first delete the old assets,
|
||||||
|
# then modify the release, then add the new assets.
|
||||||
|
gh release view devel --json assets \
|
||||||
|
| jq -r '.assets[] | .name' \
|
||||||
|
| xargs -rn1 \
|
||||||
|
gh release delete-asset -y devel
|
||||||
|
gh release edit devel \
|
||||||
|
-t devel \
|
||||||
|
--verify-tag \
|
||||||
|
-F artifacts/release-changes/CHANGES.md \
|
||||||
|
--prerelease
|
||||||
|
gh release upload --clobber devel release-bundle/*
|
||||||
|
else
|
||||||
|
gh release create "${GITHUB_REF_NAME}" \
|
||||||
|
-t "${GITHUB_REF_NAME}" \
|
||||||
|
--verify-tag \
|
||||||
|
-F artifacts/release-changes/CHANGES.md \
|
||||||
|
release-bundle/*
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
docker:
|
||||||
|
name: Docker Hub
|
||||||
|
runs-on: ubuntu-24.04-arm
|
||||||
|
needs:
|
||||||
|
- prepare
|
||||||
|
if: |
|
||||||
|
vars.DOCKER_REPO && vars.DOCKER_USER
|
||||||
|
env:
|
||||||
|
DOCKER_REPO: ${{ vars.DOCKER_REPO }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
|
- name: Download x86-64 Docker image
|
||||||
|
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
|
||||||
|
with:
|
||||||
|
name: postgrest-docker-x86-64
|
||||||
|
- name: Download aarch64 binary
|
||||||
|
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
|
||||||
|
with:
|
||||||
|
name: postgrest-ubuntu-aarch64
|
||||||
|
- uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3.8.0
|
||||||
|
- uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
|
||||||
|
with:
|
||||||
|
username: ${{ vars.DOCKER_USER }}
|
||||||
|
password: ${{ secrets.DOCKER_PASS }}
|
||||||
|
- name: Build aarch64 Docker image
|
||||||
|
run: |
|
||||||
|
# This only pushes the image via digest, not a tag. This will not appear
|
||||||
|
# in the image list on Docker Hub, yet. It will be later added to the main
|
||||||
|
# tag's manifest.
|
||||||
|
docker buildx build \
|
||||||
|
-t "$DOCKER_REPO/postgrest" \
|
||||||
|
--platform linux/arm64 \
|
||||||
|
--output push-by-digest=true,type=image,push=true \
|
||||||
|
--metadata-file metadata.json \
|
||||||
|
.
|
||||||
|
echo "SHA256_ARM=$(jq -r '."containerimage.digest"' metadata.json)" >> "$GITHUB_ENV"
|
||||||
|
- name: Publish images on Docker Hub
|
||||||
|
run: |
|
||||||
|
docker load -i postgrest-docker.tar.gz
|
||||||
|
|
||||||
|
docker tag postgrest:latest "$DOCKER_REPO/postgrest:${GITHUB_REF_NAME}"
|
||||||
|
docker push "$DOCKER_REPO/postgrest:${GITHUB_REF_NAME}"
|
||||||
|
docker buildx imagetools create --append \
|
||||||
|
-t "$DOCKER_REPO/postgrest:${GITHUB_REF_NAME}" \
|
||||||
|
"$DOCKER_REPO/postgrest@$SHA256_ARM"
|
||||||
|
|
||||||
|
# Only tag 'latest' for full releases
|
||||||
|
if [ "${GITHUB_REF_NAME}" != "devel" ]; then
|
||||||
|
echo "Pushing to 'latest' tag for full release of ${GITHUB_REF_NAME} ..."
|
||||||
|
docker tag postgrest:latest "$DOCKER_REPO"/postgrest:latest
|
||||||
|
docker push "$DOCKER_REPO"/postgrest:latest
|
||||||
|
docker buildx imagetools create --append \
|
||||||
|
-t "$DOCKER_REPO/postgrest:latest" \
|
||||||
|
"$DOCKER_REPO/postgrest@$SHA256_ARM"
|
||||||
|
else
|
||||||
|
echo "Skipping push to 'latest' tag for pre-release..."
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
docker-description:
|
||||||
|
name: Docker Hub Description
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
if: |
|
||||||
|
vars.DOCKER_REPO && vars.DOCKER_USER &&
|
||||||
|
github.ref == 'refs/tags/devel'
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
|
- uses: peter-evans/dockerhub-description@e98e4d1628a5f3be2be7c231e50981aee98723ae # v4.0.0
|
||||||
|
with:
|
||||||
|
username: ${{ vars.DOCKER_USER }}
|
||||||
|
password: ${{ secrets.DOCKER_PASS }}
|
||||||
|
repository: ${{ vars.DOCKER_REPO }}/postgrest
|
||||||
|
short-description: ${{ github.event.repository.description }}
|
||||||
|
readme-filepath: ./docker-hub-readme.md
|
||||||
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
name: Upload Reports
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_run:
|
|
||||||
workflows:
|
|
||||||
- CI
|
|
||||||
- Test
|
|
||||||
branches-ignore:
|
|
||||||
- devel
|
|
||||||
- v[0-9]+
|
|
||||||
- v[0-9]+.[0-9]+.[0-9]+
|
|
||||||
types:
|
|
||||||
- completed
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
loadtest:
|
|
||||||
name: Loadtest
|
|
||||||
permissions:
|
|
||||||
checks: write
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
if: github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure'
|
|
||||||
steps:
|
|
||||||
- name: Download from Artifacts
|
|
||||||
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
|
|
||||||
with:
|
|
||||||
github-token: ${{ github.token }}
|
|
||||||
run-id: ${{ github.event.workflow_run.id }}
|
|
||||||
name: loadtest.md
|
|
||||||
path: artifacts
|
|
||||||
- name: Upload to GitHub Checks
|
|
||||||
uses: LouisBrunner/checks-action@6b626ffbad7cc56fd58627f774b9067e6118af23 # v2.0.0
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
sha: ${{ github.event.workflow_run.head_sha }}
|
|
||||||
name: Loadtest Results
|
|
||||||
conclusion: neutral
|
|
||||||
output: |
|
|
||||||
{"summary":""}
|
|
||||||
output_text_description_file: artifacts/loadtest.md
|
|
||||||
+10
-16
@@ -32,14 +32,14 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
coverage:
|
coverage:
|
||||||
name: Coverage
|
name: Coverage
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
# Hack for enabling color output, see:
|
# Hack for enabling color output, see:
|
||||||
# https://github.com/actions/runner/issues/241#issuecomment-842566950
|
# https://github.com/actions/runner/issues/241#issuecomment-842566950
|
||||||
shell: script -qec "bash --noprofile --norc -eo pipefail {0}"
|
shell: script -qec "bash --noprofile --norc -eo pipefail {0}"
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- name: Setup Nix Environment
|
- name: Setup Nix Environment
|
||||||
uses: ./.github/actions/setup-nix
|
uses: ./.github/actions/setup-nix
|
||||||
with:
|
with:
|
||||||
@@ -49,7 +49,7 @@ jobs:
|
|||||||
- name: Run coverage (IO tests and Spec tests against PostgreSQL 15)
|
- name: Run coverage (IO tests and Spec tests against PostgreSQL 15)
|
||||||
run: postgrest-coverage
|
run: postgrest-coverage
|
||||||
- name: Upload coverage to codecov
|
- name: Upload coverage to codecov
|
||||||
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
|
uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5.1.2
|
||||||
with:
|
with:
|
||||||
files: ./coverage/codecov.json
|
files: ./coverage/codecov.json
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
@@ -69,14 +69,14 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
pgVersion: ["9_6", 10, 11, 12, 13, 14, 15, 16]
|
pgVersion: ["9_6", 10, 11, 12, 13, 14, 15, 16]
|
||||||
name: PG ${{ matrix.pgVersion }}
|
name: PG ${{ matrix.pgVersion }}
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
# Hack for enabling color output, see:
|
# Hack for enabling color output, see:
|
||||||
# https://github.com/actions/runner/issues/241#issuecomment-842566950
|
# https://github.com/actions/runner/issues/241#issuecomment-842566950
|
||||||
shell: script -qec "bash --noprofile --norc -eo pipefail {0}"
|
shell: script -qec "bash --noprofile --norc -eo pipefail {0}"
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- name: Setup Nix Environment
|
- name: Setup Nix Environment
|
||||||
uses: ./.github/actions/setup-nix
|
uses: ./.github/actions/setup-nix
|
||||||
with:
|
with:
|
||||||
@@ -98,9 +98,9 @@ jobs:
|
|||||||
|
|
||||||
memory:
|
memory:
|
||||||
name: Memory
|
name: Memory
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- name: Setup Nix Environment
|
- name: Setup Nix Environment
|
||||||
uses: ./.github/actions/setup-nix
|
uses: ./.github/actions/setup-nix
|
||||||
with:
|
with:
|
||||||
@@ -112,9 +112,9 @@ jobs:
|
|||||||
|
|
||||||
loadtest:
|
loadtest:
|
||||||
name: Loadtest
|
name: Loadtest
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Setup Nix Environment
|
- name: Setup Nix Environment
|
||||||
@@ -129,10 +129,4 @@ jobs:
|
|||||||
- name: Run loadtest
|
- name: Run loadtest
|
||||||
run: |
|
run: |
|
||||||
postgrest-loadtest-against main ${{ steps.get-latest-tag.outputs.tag }}
|
postgrest-loadtest-against main ${{ steps.get-latest-tag.outputs.tag }}
|
||||||
postgrest-loadtest-report > loadtest/loadtest.md
|
postgrest-loadtest-report >> "$GITHUB_STEP_SUMMARY"
|
||||||
- name: Upload report
|
|
||||||
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
|
|
||||||
with:
|
|
||||||
name: loadtest.md
|
|
||||||
path: loadtest/loadtest.md
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|||||||
@@ -5,6 +5,22 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## [12.2.4] - 2025-01-18
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- #3779, Always log the schema cache load time - @steve-chavez
|
||||||
|
- #3706, Fix insert with `missing=default` uses default value of domain instead of column - @taimoorzaeem
|
||||||
|
|
||||||
|
## [12.2.3] - 2024-08-01
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- #3091, Broken link in OpenAPI description `externalDocs` - @salim-b
|
||||||
|
- #3659, Embed One-to-One relationship with different column order properly - @wolfgangwalther
|
||||||
|
- #3504, Remove `format` from `rowFilter` parameters in OpenAPI - @dantheman2865
|
||||||
|
- #3660, Fix regression that loaded the schema cache before the in-database configuration - @steve-chavez, @laurenceisla
|
||||||
|
|
||||||
## [12.2.2] - 2024-07-10
|
## [12.2.2] - 2024-07-10
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# PostgREST docker hub image
|
# PostgREST Docker Hub image for aarch64.
|
||||||
|
# The x86-64 is a single-static-binary image built via Nix, see:
|
||||||
|
# nix/tools/docker/README.md
|
||||||
|
|
||||||
FROM ubuntu:noble@sha256:2e863c44b718727c860746568e1d54afd13b2fa71b160f5cd9058fc436217b30 AS postgrest
|
FROM ubuntu:noble@sha256:80dd3c3b9c6cecb9f1667e9290b3bc61b78c2678c02cbdae5f0fea92cc6734ab AS postgrest
|
||||||
|
|
||||||
RUN apt-get update -y \
|
RUN apt-get update -y \
|
||||||
&& apt install -y --no-install-recommends libpq-dev zlib1g-dev jq gcc libnuma-dev \
|
&& apt install -y --no-install-recommends libpq-dev zlib1g-dev jq gcc libnuma-dev \
|
||||||
@@ -1,7 +1,6 @@
|
|||||||

|

|
||||||
|
|
||||||
[](https://www.patreon.com/postgrest)
|
[](https://www.patreon.com/postgrest)
|
||||||
[](https://gitter.im/begriffs/postgrest)
|
|
||||||
[](http://postgrest.org)
|
[](http://postgrest.org)
|
||||||
[](https://hub.docker.com/r/postgrest/postgrest/)
|
[](https://hub.docker.com/r/postgrest/postgrest/)
|
||||||
[](https://github.com/PostgREST/postgrest/actions?query=branch%3Amain)
|
[](https://github.com/PostgREST/postgrest/actions?query=branch%3Amain)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
# PostgREST
|
# PostgREST
|
||||||
|
|
||||||
[](https://gitter.im/begriffs/postgrest)
|
|
||||||
[](https://www.patreon.com/postgrest)
|
[](https://www.patreon.com/postgrest)
|
||||||
[](http://postgrest.org)
|
[](http://postgrest.org)
|
||||||
[](https://github.com/PostgREST/postgrest/actions?query=branch%3Amain)
|
[](https://github.com/PostgREST/postgrest/actions?query=branch%3Amain)
|
||||||
|
|||||||
+1
-5
@@ -16,9 +16,6 @@ PostgREST Documentation
|
|||||||
.. image:: https://img.shields.io/docker/pulls/postgrest/postgrest.svg
|
.. image:: https://img.shields.io/docker/pulls/postgrest/postgrest.svg
|
||||||
:target: https://hub.docker.com/r/postgrest/postgrest/
|
:target: https://hub.docker.com/r/postgrest/postgrest/
|
||||||
|
|
||||||
.. image:: https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92-brightgreen.svg
|
|
||||||
:target: https://gitter.im/begriffs/postgrest
|
|
||||||
|
|
||||||
.. image:: https://img.shields.io/badge/Donate-Patreon-orange.svg?colorB=F96854
|
.. image:: https://img.shields.io/badge/Donate-Patreon-orange.svg?colorB=F96854
|
||||||
:target: https://www.patreon.com/postgrest
|
:target: https://www.patreon.com/postgrest
|
||||||
|
|
||||||
@@ -110,7 +107,7 @@ PostgREST has a focused scope. It works well with other tools like Nginx. This f
|
|||||||
Getting Support
|
Getting Support
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
The project has a friendly and growing community. For discussions, use the Github `discussions page <https://github.com/PostgREST/postgrest/discussions>`_ or join our `chat room <https://gitter.im/begriffs/postgrest>`_. You can also report or search for bugs/features on the Github `issues <https://github.com/PostgREST/postgrest/issues>`_ page.
|
The project has a friendly and growing community. For discussions, use the Github `discussions page <https://github.com/PostgREST/postgrest/discussions>`_. You can also report or search for bugs/features on the Github `issues <https://github.com/PostgREST/postgrest/issues>`_ page.
|
||||||
|
|
||||||
Release Notes
|
Release Notes
|
||||||
-------------
|
-------------
|
||||||
@@ -221,7 +218,6 @@ Here are some companies that use PostgREST in production.
|
|||||||
- See how Nimbus uses PostgREST in `Paul Copplestone's blog post <https://paul.copplest.one/blog/nimbus-tech-2019-04.html>`_.
|
- See how Nimbus uses PostgREST in `Paul Copplestone's blog post <https://paul.copplest.one/blog/nimbus-tech-2019-04.html>`_.
|
||||||
* `OpenBooking <https://openbooking.ch>`_
|
* `OpenBooking <https://openbooking.ch>`_
|
||||||
* `Redsmin <https://www.redsmin.com>`_
|
* `Redsmin <https://www.redsmin.com>`_
|
||||||
* `Sompani <https://www.sompani.com>`_
|
|
||||||
* `Supabase <https://supabase.com>`_
|
* `Supabase <https://supabase.com>`_
|
||||||
|
|
||||||
.. Failing links
|
.. Failing links
|
||||||
|
|||||||
@@ -71,6 +71,40 @@ The function parameter names match the JSON object keys in the POST case, for th
|
|||||||
|
|
||||||
.. _function_single_json:
|
.. _function_single_json:
|
||||||
|
|
||||||
|
Functions with an array of JSON objects
|
||||||
|
----------------------------------------------
|
||||||
|
|
||||||
|
If you want to pass multiple JSON objects to a Postgres function (an array of objects), you can create a function with a parameter of type ``json`` or ``jsonb``.
|
||||||
|
|
||||||
|
Within the curl request, this JSON must be embedded in an object where they key matches the same name as the function's ``json`` or ``jsonb`` parameter.
|
||||||
|
This will allow you to loop over the array of JSON objects within the Postgres function.
|
||||||
|
|
||||||
|
This practice may allow you to reduce the number of ``curl`` requests required to accomplish a task.
|
||||||
|
|
||||||
|
For instance, assume we have created this function in the database.
|
||||||
|
|
||||||
|
.. code-block:: postgres
|
||||||
|
|
||||||
|
CREATE FUNCTION update_data(p_json jsonb)
|
||||||
|
RETURNS void AS $$
|
||||||
|
DECLARE
|
||||||
|
json_item json;
|
||||||
|
BEGIN
|
||||||
|
FOR json_item IN SELECT jsonb_array_elements(p_json) LOOP
|
||||||
|
UPDATE data_table SET data_text_column = (json_item->>'data_text')::text
|
||||||
|
WHERE data_int_column = (json_item->>'data_int')::integer;
|
||||||
|
END LOOP;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE SQL IMMUTABLE;
|
||||||
|
|
||||||
|
A ``curl`` request using the POST method would look like the following:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
curl "http://localhost:3000/rpc/update_data" \
|
||||||
|
-X POST -H "Content-Type: application/json" \
|
||||||
|
-d '{ "p_json": [ { "data_text": "one", "data_int": "1" }, { "data_text": "two", "data_int": "2" } ] }'
|
||||||
|
|
||||||
Functions with a single unnamed JSON parameter
|
Functions with a single unnamed JSON parameter
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -623,18 +623,34 @@ You can make an upsert with :code:`POST` and the :code:`Prefer: resolution=merge
|
|||||||
|
|
||||||
.. code-block:: bash
|
.. code-block:: bash
|
||||||
|
|
||||||
curl "http://localhost:3000/employees" \
|
curl "http://localhost:3000/products" \
|
||||||
-X POST -H "Content-Type: application/json" \
|
-X POST -H "Content-Type: application/json" \
|
||||||
-H "Prefer: resolution=merge-duplicates" \
|
-H "Prefer: resolution=merge-duplicates" \
|
||||||
-d @- << EOF
|
-d @- << EOF
|
||||||
[
|
[
|
||||||
{ "id": 1, "name": "Old employee 1", "salary": 30000 },
|
{ "sku": "CL2031", "name": "Existing T-shirt", "price": 35 },
|
||||||
{ "id": 2, "name": "Old employee 2", "salary": 42000 },
|
{ "sku": "CL2040", "name": "Existing Hoodie", "price": 60 },
|
||||||
{ "id": 3, "name": "New employee 3", "salary": 50000 }
|
{ "sku": "AC1022", "name": "New Cap", "price": 30 }
|
||||||
]
|
]
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
By default, upsert operates based on the primary key columns, you must specify all of them. You can also choose to ignore the duplicates with :code:`Prefer: resolution=ignore-duplicates`. This works best when the primary key is natural, but it's also possible to use it if the primary key is surrogate (example: "id serial primary key"). For more details read `this issue <https://github.com/PostgREST/postgrest/issues/1118>`_.
|
By default, upsert operates based on the primary key columns, so you must specify all of them.
|
||||||
|
You can also choose to ignore the duplicates with :code:`Prefer: resolution=ignore-duplicates`.
|
||||||
|
Upsert works best when the primary key is natural (e.g. ``sku``).
|
||||||
|
However, it can work with surrogate primary keys (e.g. ``id serial primary key``), if you also do a :ref:`bulk_insert_default`:
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
curl "http://localhost:3000/employees?colums=id,name,salary" \
|
||||||
|
-X POST -H "Content-Type: application/json" \
|
||||||
|
-H "Prefer: resolution=merge-duplicates, missing=default" \
|
||||||
|
-d @- << EOF
|
||||||
|
[
|
||||||
|
{ "id": 1, "name": "Existing employee 1", "salary": 30000 },
|
||||||
|
{ "id": 2, "name": "Existing employee 2", "salary": 42000 },
|
||||||
|
{ "name": "New employee 3", "salary": 50000 }
|
||||||
|
]
|
||||||
|
EOF
|
||||||
|
|
||||||
.. important::
|
.. important::
|
||||||
After creating a table or changing its primary key, you must refresh PostgREST schema cache for upsert to work properly. To learn how to refresh the cache see :ref:`schema_reloading`.
|
After creating a table or changing its primary key, you must refresh PostgREST schema cache for upsert to work properly. To learn how to refresh the cache see :ref:`schema_reloading`.
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ sphinx-rtd-dark-mode>=1.3.0
|
|||||||
sphinx-tabs>=3.2.0
|
sphinx-tabs>=3.2.0
|
||||||
sphinx>=5.0.2
|
sphinx>=5.0.2
|
||||||
sphinxext-opengraph==0.9.1
|
sphinxext-opengraph==0.9.1
|
||||||
urllib3==2.2.2
|
urllib3==2.2.3
|
||||||
|
|||||||
@@ -17,12 +17,7 @@ To make an API we'll simply be building a database. All the endpoints and permis
|
|||||||
|
|
||||||
By the end of this tutorial you'll have a working database, PostgREST server, and a simple single-user todo list API.
|
By the end of this tutorial you'll have a working database, PostgREST server, and a simple single-user todo list API.
|
||||||
|
|
||||||
Step 1. Relax, we'll help
|
Step 1. Install PostgreSQL
|
||||||
-------------------------
|
|
||||||
|
|
||||||
As you begin the tutorial, pop open the project `chat room <https://gitter.im/begriffs/postgrest>`_ in another tab. There are a nice group of people active in the project and we'll help you out if you get stuck.
|
|
||||||
|
|
||||||
Step 2. Install PostgreSQL
|
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
If you're already familiar with using PostgreSQL and have it installed on your system you can use the existing installation (see :ref:`pg-dependency` for minimum requirements). For this tutorial we'll describe how to use the database in Docker because database configuration is otherwise too complicated for a simple tutorial.
|
If you're already familiar with using PostgreSQL and have it installed on your system you can use the existing installation (see :ref:`pg-dependency` for minimum requirements). For this tutorial we'll describe how to use the database in Docker because database configuration is otherwise too complicated for a simple tutorial.
|
||||||
@@ -48,7 +43,7 @@ This will run the Docker instance as a daemon and expose port 5432 to the host s
|
|||||||
In this case, you will need to change the **first** of the two 5432 to something else, for example to :code:`5433:5432`. Remember to also adjust the port in your config file in Step 5!
|
In this case, you will need to change the **first** of the two 5432 to something else, for example to :code:`5433:5432`. Remember to also adjust the port in your config file in Step 5!
|
||||||
|
|
||||||
|
|
||||||
Step 3. Install PostgREST
|
Step 2. Install PostgREST
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
Using a Package Manager
|
Using a Package Manager
|
||||||
@@ -122,7 +117,7 @@ If everything is working correctly it will print out its version and the availab
|
|||||||
</details>
|
</details>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
Step 4. Create Database for API
|
Step 3. Create Database for API
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
Connect to the SQL console (psql) inside the container. To do so, run this from your command line:
|
Connect to the SQL console (psql) inside the container. To do so, run this from your command line:
|
||||||
@@ -185,7 +180,7 @@ Now quit out of psql; it's time to start the API!
|
|||||||
|
|
||||||
\q
|
\q
|
||||||
|
|
||||||
Step 5. Run PostgREST
|
Step 4. Run PostgREST
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
PostgREST can use a configuration file to tell it how to connect to the database. Create a file :code:`tutorial.conf` with this inside:
|
PostgREST can use a configuration file to tell it how to connect to the database. Create a file :code:`tutorial.conf` with this inside:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
owner = "NixOS";
|
owner = "NixOS";
|
||||||
repo = "nixpkgs";
|
repo = "nixpkgs";
|
||||||
date = "2024-04-20";
|
date = "2024-05-29";
|
||||||
rev = "92d295f588631b0db2da509f381b4fb1e74173c5";
|
rev = "a15e8d1b3d9e6496c4a3214e2104f6d28dfa7df7";
|
||||||
tarballHash = "162w28y4i5c8g5qhjvs827qxphf2a8n4c8fwhcywzl1j1a35h2im";
|
tarballHash = "sha256:0r4a4165f4n1zlpnyjrdrwrg86n1b6g3axsdh3j5iizpmjrlxmd7";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,14 @@ let
|
|||||||
}
|
}
|
||||||
{ });
|
{ });
|
||||||
|
|
||||||
hasql-pool = lib.dontCheck prev.hasql-pool_1_0_1;
|
hasql-pool = lib.dontCheck (prev.callHackageDirect
|
||||||
|
{
|
||||||
|
pkg = "hasql-pool";
|
||||||
|
ver = "1.0.1";
|
||||||
|
sha256 = "sha256-Hf1f7lX0LWkjrb25SDBovCYPRdmUP1H6pAxzi7kT4Gg=";
|
||||||
|
}
|
||||||
|
{ }
|
||||||
|
);
|
||||||
|
|
||||||
postgresql-libpq = lib.dontCheck
|
postgresql-libpq = lib.dontCheck
|
||||||
(prev.postgresql-libpq.override {
|
(prev.postgresql-libpq.override {
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
name: postgrest
|
name: postgrest
|
||||||
version: 12.2.2
|
version: 12.2.4
|
||||||
synopsis: REST API for any Postgres database
|
synopsis: REST API for any Postgres database
|
||||||
description: Reads the schema of a PostgreSQL database and creates RESTful routes
|
description: Reads the schema of a PostgreSQL database and creates RESTful routes
|
||||||
for tables, views, and functions, supporting all HTTP methods that security
|
for tables, views, and functions, supporting all HTTP methods that security
|
||||||
|
|||||||
+11
-11
@@ -161,7 +161,7 @@ initWithPool (sock, adminSock) pool conf loggerState metricsState observer = do
|
|||||||
deb <-
|
deb <-
|
||||||
let decisecond = 100000 in
|
let decisecond = 100000 in
|
||||||
mkDebounce defaultDebounceSettings
|
mkDebounce defaultDebounceSettings
|
||||||
{ debounceAction = internalSchemaCacheLoad appState
|
{ debounceAction = retryingSchemaCacheLoad appState
|
||||||
, debounceFreq = decisecond
|
, debounceFreq = decisecond
|
||||||
, debounceEdge = leadingEdge -- runs the worker at the start and the end
|
, debounceEdge = leadingEdge -- runs the worker at the start and the end
|
||||||
}
|
}
|
||||||
@@ -354,13 +354,6 @@ putSCacheStatus = atomicWriteIORef . stateSCacheStatus
|
|||||||
getObserver :: AppState -> ObservationHandler
|
getObserver :: AppState -> ObservationHandler
|
||||||
getObserver = stateObserver
|
getObserver = stateObserver
|
||||||
|
|
||||||
internalSchemaCacheLoad :: AppState -> IO ()
|
|
||||||
internalSchemaCacheLoad appState = do
|
|
||||||
AppConfig{..} <- getConfig appState
|
|
||||||
void $ retryingSchemaCacheLoad appState
|
|
||||||
-- We cannot retry reading the in-db config after it fails immediately, because it could have user errors. We just report the error and continue.
|
|
||||||
when configDbConfig $ readInDbConfig False appState
|
|
||||||
|
|
||||||
-- | Try to load the schema cache and retry if it fails.
|
-- | Try to load the schema cache and retry if it fails.
|
||||||
--
|
--
|
||||||
-- This is done by repeatedly: 1) flushing the pool, 2) querying the version and validating that the postgres version is supported by us, and 3) loading the schema cache.
|
-- This is done by repeatedly: 1) flushing the pool, 2) querying the version and validating that the postgres version is supported by us, and 3) loading the schema cache.
|
||||||
@@ -368,16 +361,17 @@ internalSchemaCacheLoad appState = do
|
|||||||
--
|
--
|
||||||
-- + Because connections cache the pg catalog(see #2620)
|
-- + Because connections cache the pg catalog(see #2620)
|
||||||
-- + For rapid recovery. Otherwise, the pool idle or lifetime timeout would have to be reached for new healthy connections to be acquired.
|
-- + For rapid recovery. Otherwise, the pool idle or lifetime timeout would have to be reached for new healthy connections to be acquired.
|
||||||
retryingSchemaCacheLoad :: AppState -> IO (Maybe PgVersion, Maybe SchemaCache)
|
retryingSchemaCacheLoad :: AppState -> IO ()
|
||||||
retryingSchemaCacheLoad appState@AppState{stateObserver=observer, stateMainThreadId=mainThreadId} =
|
retryingSchemaCacheLoad appState@AppState{stateObserver=observer, stateMainThreadId=mainThreadId} =
|
||||||
retrying retryPolicy shouldRetry (\RetryStatus{rsIterNumber, rsPreviousDelay} -> do
|
void $ retrying retryPolicy shouldRetry (\RetryStatus{rsIterNumber, rsPreviousDelay} -> do
|
||||||
when (rsIterNumber > 0) $ do
|
when (rsIterNumber > 0) $ do
|
||||||
let delay = fromMaybe 0 rsPreviousDelay `div` oneSecondInUs
|
let delay = fromMaybe 0 rsPreviousDelay `div` oneSecondInUs
|
||||||
observer $ ConnectionRetryObs delay
|
observer $ ConnectionRetryObs delay
|
||||||
putNextListenerDelay appState delay
|
putNextListenerDelay appState delay
|
||||||
|
|
||||||
flushPool appState
|
flushPool appState
|
||||||
(,) <$> qPgVersion <*> qSchemaCache
|
|
||||||
|
(,) <$> qPgVersion <*> (qInDbConfig *> qSchemaCache)
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
qPgVersion :: IO (Maybe PgVersion)
|
qPgVersion :: IO (Maybe PgVersion)
|
||||||
@@ -399,6 +393,11 @@ retryingSchemaCacheLoad appState@AppState{stateObserver=observer, stateMainThrea
|
|||||||
putPgVersion appState actualPgVersion
|
putPgVersion appState actualPgVersion
|
||||||
return $ Just actualPgVersion
|
return $ Just actualPgVersion
|
||||||
|
|
||||||
|
qInDbConfig :: IO ()
|
||||||
|
qInDbConfig = do
|
||||||
|
AppConfig{..} <- getConfig appState
|
||||||
|
when configDbConfig $ readInDbConfig False appState
|
||||||
|
|
||||||
qSchemaCache :: IO (Maybe SchemaCache)
|
qSchemaCache :: IO (Maybe SchemaCache)
|
||||||
qSchemaCache = do
|
qSchemaCache = do
|
||||||
conf@AppConfig{..} <- getConfig appState
|
conf@AppConfig{..} <- getConfig appState
|
||||||
@@ -437,6 +436,7 @@ retryingSchemaCacheLoad appState@AppState{stateObserver=observer, stateMainThrea
|
|||||||
oneSecondInUs = 1000000 -- one second in microseconds
|
oneSecondInUs = 1000000 -- one second in microseconds
|
||||||
|
|
||||||
-- | Reads the in-db config and reads the config file again
|
-- | Reads the in-db config and reads the config file again
|
||||||
|
-- | We don't retry reading the in-db config after it fails immediately, because it could have user errors. We just report the error and continue.
|
||||||
readInDbConfig :: Bool -> AppState -> IO ()
|
readInDbConfig :: Bool -> AppState -> IO ()
|
||||||
readInDbConfig startingUp appState@AppState{stateObserver=observer} = do
|
readInDbConfig startingUp appState@AppState{stateObserver=observer} = do
|
||||||
AppConfig{..} <- getConfig appState
|
AppConfig{..} <- getConfig appState
|
||||||
|
|||||||
@@ -87,9 +87,6 @@ observationLogger loggerState logLevel obs = case obs of
|
|||||||
o@(HasqlPoolObs _) -> do
|
o@(HasqlPoolObs _) -> do
|
||||||
when (logLevel >= LogDebug) $ do
|
when (logLevel >= LogDebug) $ do
|
||||||
logWithZTime loggerState $ observationMessage o
|
logWithZTime loggerState $ observationMessage o
|
||||||
o@(SchemaCacheLoadedObs _) -> do
|
|
||||||
when (logLevel >= LogDebug) $ do
|
|
||||||
logWithZTime loggerState $ observationMessage o
|
|
||||||
PoolRequest ->
|
PoolRequest ->
|
||||||
pure ()
|
pure ()
|
||||||
PoolRequestFullfilled ->
|
PoolRequestFullfilled ->
|
||||||
|
|||||||
@@ -296,8 +296,7 @@ makeRowFilter tn c =
|
|||||||
& required ?~ False
|
& required ?~ False
|
||||||
& schema .~ ParamOther ((mempty :: ParamOtherSchema)
|
& schema .~ ParamOther ((mempty :: ParamOtherSchema)
|
||||||
& in_ .~ ParamQuery
|
& in_ .~ ParamQuery
|
||||||
& type_ ?~ SwaggerString
|
& type_ ?~ SwaggerString))
|
||||||
& format ?~ colType c))
|
|
||||||
|
|
||||||
makeRowFilters :: Text -> [Column] -> [(Text, Param)]
|
makeRowFilters :: Text -> [Column] -> [(Text, Param)]
|
||||||
makeRowFilters tn = fmap (makeRowFilter tn)
|
makeRowFilters tn = fmap (makeRowFilter tn)
|
||||||
@@ -402,7 +401,7 @@ postgrestSpec (prettyVersion, docsVersion) rels pds ti (s, h, p, b) sd allowSecu
|
|||||||
& description ?~ fromMaybe "This is a dynamic API generated by PostgREST" dDesc)
|
& description ?~ fromMaybe "This is a dynamic API generated by PostgREST" dDesc)
|
||||||
& externalDocs ?~ ((mempty :: ExternalDocs)
|
& externalDocs ?~ ((mempty :: ExternalDocs)
|
||||||
& description ?~ "PostgREST Documentation"
|
& description ?~ "PostgREST Documentation"
|
||||||
& url .~ URL ("https://postgrest.org/en/" <> docsVersion <> "/api.html"))
|
& url .~ URL ("https://postgrest.org/en/" <> docsVersion <> "/references/api.html"))
|
||||||
& host .~ h'
|
& host .~ h'
|
||||||
& definitions .~ fromList (makeTableDef rels <$> ti)
|
& definitions .~ fromList (makeTableDef rels <$> ti)
|
||||||
& parameters .~ fromList (makeParamDefs ti)
|
& parameters .~ fromList (makeParamDefs ti)
|
||||||
|
|||||||
@@ -818,20 +818,20 @@ tablesSqlQuery pgVer =
|
|||||||
columnDefault -- typbasetype and typdefaultbin handles `CREATE DOMAIN .. DEFAULT val`, attidentity/attgenerated handles generated columns, pg_get_expr gets the default of a column
|
columnDefault -- typbasetype and typdefaultbin handles `CREATE DOMAIN .. DEFAULT val`, attidentity/attgenerated handles generated columns, pg_get_expr gets the default of a column
|
||||||
| pgVer >= pgVersion120 = [q|
|
| pgVer >= pgVersion120 = [q|
|
||||||
CASE
|
CASE
|
||||||
WHEN t.typbasetype != 0 THEN pg_get_expr(t.typdefaultbin, 0)
|
WHEN (t.typbasetype != 0) AND (ad.adbin IS NULL) THEN pg_get_expr(t.typdefaultbin, 0)
|
||||||
WHEN a.attidentity = 'd' THEN format('nextval(%s)', quote_literal(seqsch.nspname || '.' || seqclass.relname))
|
WHEN a.attidentity = 'd' THEN format('nextval(%s)', quote_literal(seqsch.nspname || '.' || seqclass.relname))
|
||||||
WHEN a.attgenerated = 's' THEN null
|
WHEN a.attgenerated = 's' THEN null
|
||||||
ELSE pg_get_expr(ad.adbin, ad.adrelid)::text
|
ELSE pg_get_expr(ad.adbin, ad.adrelid)::text
|
||||||
END|]
|
END|]
|
||||||
| pgVer >= pgVersion100 = [q|
|
| pgVer >= pgVersion100 = [q|
|
||||||
CASE
|
CASE
|
||||||
WHEN t.typbasetype != 0 THEN pg_get_expr(t.typdefaultbin, 0)
|
WHEN (t.typbasetype != 0) AND (ad.adbin IS NULL) THEN pg_get_expr(t.typdefaultbin, 0)
|
||||||
WHEN a.attidentity = 'd' THEN format('nextval(%s)', quote_literal(seqsch.nspname || '.' || seqclass.relname))
|
WHEN a.attidentity = 'd' THEN format('nextval(%s)', quote_literal(seqsch.nspname || '.' || seqclass.relname))
|
||||||
ELSE pg_get_expr(ad.adbin, ad.adrelid)::text
|
ELSE pg_get_expr(ad.adbin, ad.adrelid)::text
|
||||||
END|]
|
END|]
|
||||||
| otherwise = [q|
|
| otherwise = [q|
|
||||||
CASE
|
CASE
|
||||||
WHEN t.typbasetype != 0 THEN pg_get_expr(t.typdefaultbin, 0)
|
WHEN (t.typbasetype != 0) AND (ad.adbin IS NULL) THEN pg_get_expr(t.typdefaultbin, 0)
|
||||||
ELSE pg_get_expr(ad.adbin, ad.adrelid)::text
|
ELSE pg_get_expr(ad.adbin, ad.adrelid)::text
|
||||||
END|]
|
END|]
|
||||||
|
|
||||||
@@ -872,7 +872,7 @@ allM2OandO2ORels pgVer =
|
|||||||
JOIN LATERAL (
|
JOIN LATERAL (
|
||||||
SELECT
|
SELECT
|
||||||
array_agg(row(cols.attname, refs.attname) order by ord) AS cols_and_fcols,
|
array_agg(row(cols.attname, refs.attname) order by ord) AS cols_and_fcols,
|
||||||
jsonb_agg(cols.attname order by ord) AS cols
|
jsonb_agg(cols.attname order by cols.attnum) AS cols
|
||||||
FROM unnest(traint.conkey, traint.confkey) WITH ORDINALITY AS _(col, ref, ord)
|
FROM unnest(traint.conkey, traint.confkey) WITH ORDINALITY AS _(col, ref, ord)
|
||||||
JOIN pg_attribute cols ON cols.attrelid = traint.conrelid AND cols.attnum = col
|
JOIN pg_attribute cols ON cols.attrelid = traint.conrelid AND cols.attnum = col
|
||||||
JOIN pg_attribute refs ON refs.attrelid = traint.confrelid AND refs.attnum = ref
|
JOIN pg_attribute refs ON refs.attrelid = traint.confrelid AND refs.attnum = ref
|
||||||
|
|||||||
@@ -218,6 +218,40 @@
|
|||||||
pdSchema: public
|
pdSchema: public
|
||||||
pdVolatility: Volatile
|
pdVolatility: Volatile
|
||||||
|
|
||||||
|
- - qiName: reset_db_schemas_config
|
||||||
|
qiSchema: public
|
||||||
|
- - pdDescription: null
|
||||||
|
pdFuncSettings: []
|
||||||
|
pdHasVariadic: false
|
||||||
|
pdName: reset_db_schemas_config
|
||||||
|
pdParams: []
|
||||||
|
pdReturnType:
|
||||||
|
contents:
|
||||||
|
contents:
|
||||||
|
qiName: void
|
||||||
|
qiSchema: pg_catalog
|
||||||
|
tag: Scalar
|
||||||
|
tag: Single
|
||||||
|
pdSchema: public
|
||||||
|
pdVolatility: Volatile
|
||||||
|
|
||||||
|
- - qiName: change_db_schemas_config
|
||||||
|
qiSchema: public
|
||||||
|
- - pdDescription: null
|
||||||
|
pdFuncSettings: []
|
||||||
|
pdHasVariadic: false
|
||||||
|
pdName: change_db_schemas_config
|
||||||
|
pdParams: []
|
||||||
|
pdReturnType:
|
||||||
|
contents:
|
||||||
|
contents:
|
||||||
|
qiName: void
|
||||||
|
qiSchema: pg_catalog
|
||||||
|
tag: Scalar
|
||||||
|
tag: Single
|
||||||
|
pdSchema: public
|
||||||
|
pdVolatility: Volatile
|
||||||
|
|
||||||
- - qiName: change_db_schema_and_full_reload
|
- - qiName: change_db_schema_and_full_reload
|
||||||
qiSchema: public
|
qiSchema: public
|
||||||
- - pdDescription: null
|
- - pdDescription: null
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ GRANT
|
|||||||
CREATE SCHEMA v1;
|
CREATE SCHEMA v1;
|
||||||
GRANT USAGE ON SCHEMA v1 TO postgrest_test_anonymous;
|
GRANT USAGE ON SCHEMA v1 TO postgrest_test_anonymous;
|
||||||
|
|
||||||
|
CREATE SCHEMA test;
|
||||||
|
GRANT USAGE ON SCHEMA test TO postgrest_test_anonymous;
|
||||||
|
|
||||||
CREATE TABLE authors_only ();
|
CREATE TABLE authors_only ();
|
||||||
GRANT SELECT ON authors_only TO postgrest_test_author;
|
GRANT SELECT ON authors_only TO postgrest_test_author;
|
||||||
|
|
||||||
@@ -226,3 +229,17 @@ $$ language sql;
|
|||||||
create function get_statement_timeout(items) returns text as $$
|
create function get_statement_timeout(items) returns text as $$
|
||||||
select current_setting('statement_timeout', true) as statement_timeout
|
select current_setting('statement_timeout', true) as statement_timeout
|
||||||
$$ language sql;
|
$$ language sql;
|
||||||
|
|
||||||
|
create function change_db_schemas_config() returns void as $_$
|
||||||
|
begin
|
||||||
|
alter role postgrest_test_authenticator set pgrst.db_schemas = 'test';
|
||||||
|
end $_$ volatile security definer language plpgsql;
|
||||||
|
|
||||||
|
create function reset_db_schemas_config() returns void as $_$
|
||||||
|
begin
|
||||||
|
alter role postgrest_test_authenticator reset pgrst.db_schemas;
|
||||||
|
end $_$ volatile security definer language plpgsql ;
|
||||||
|
|
||||||
|
create function test.get_current_schema() returns text as $$
|
||||||
|
select current_schema()::text;
|
||||||
|
$$ language sql;
|
||||||
|
|||||||
@@ -1579,3 +1579,20 @@ def test_admin_metrics(defaultenv):
|
|||||||
assert "pgrst_db_pool_waiting" in response.text
|
assert "pgrst_db_pool_waiting" in response.text
|
||||||
assert "pgrst_db_pool_available" in response.text
|
assert "pgrst_db_pool_available" in response.text
|
||||||
assert "pgrst_db_pool_timeouts_total" in response.text
|
assert "pgrst_db_pool_timeouts_total" in response.text
|
||||||
|
|
||||||
|
|
||||||
|
def test_schema_cache_startup_load_with_in_db_config(defaultenv, metapostgrest):
|
||||||
|
"verify that the Schema Cache loads correctly at startup, using the in-db `pgrst.db_schemas` config"
|
||||||
|
|
||||||
|
response = metapostgrest.session.post("/rpc/change_db_schemas_config")
|
||||||
|
assert response.text == ""
|
||||||
|
assert response.status_code == 204
|
||||||
|
|
||||||
|
with run(env=defaultenv) as postgrest:
|
||||||
|
response = postgrest.session.get("/rpc/get_current_schema")
|
||||||
|
assert response.text == '"test"'
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
response = metapostgrest.session.post("/rpc/reset_db_schemas_config")
|
||||||
|
assert response.text == ""
|
||||||
|
assert response.status_code == 204
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ spec actualPgVersion = describe "OpenAPI" $ do
|
|||||||
|
|
||||||
let docsUrl = r ^? key "externalDocs" . key "url"
|
let docsUrl = r ^? key "externalDocs" . key "url"
|
||||||
|
|
||||||
liftIO $ docsUrl `shouldBe` Just (String ("https://postgrest.org/en/" <> docsVersion <> "/api.html"))
|
liftIO $ docsUrl `shouldBe` Just (String ("https://postgrest.org/en/" <> docsVersion <> "/references/api.html"))
|
||||||
|
|
||||||
describe "schema" $ do
|
describe "schema" $ do
|
||||||
|
|
||||||
|
|||||||
@@ -579,6 +579,15 @@ spec actualPgVersion = do
|
|||||||
, matchHeaders = ["Preference-Applied" <:> "missing=default, return=representation"]
|
, matchHeaders = ["Preference-Applied" <:> "missing=default, return=representation"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it "inserts a COLUMN default before a DOMAIN default with missing=default" $
|
||||||
|
request methodPost "/evil_friends_with_column_default?columns=id,name" [("Prefer", "return=representation"), ("Prefer", "missing=default")]
|
||||||
|
[json| { "name": "Demon" } |]
|
||||||
|
`shouldRespondWith`
|
||||||
|
[json| [{"id": 420, "name": "Demon"}] |]
|
||||||
|
{ matchStatus = 201
|
||||||
|
, matchHeaders = ["Preference-Applied" <:> "missing=default, return=representation"]
|
||||||
|
}
|
||||||
|
|
||||||
it "inserts json that has duplicate keys" $ do
|
it "inserts json that has duplicate keys" $ do
|
||||||
request methodPost "/tbl_w_json" [("Prefer", "return=representation")]
|
request methodPost "/tbl_w_json" [("Prefer", "return=representation")]
|
||||||
[json| { "data": { "a": 1, "a": 2 }, "id": 3 } |]
|
[json| { "data": { "a": 1, "a": 2 }, "id": 3 } |]
|
||||||
|
|||||||
Vendored
+6
-1
@@ -2872,7 +2872,7 @@ CREATE TABLE test.students_info(
|
|||||||
, code text
|
, code text
|
||||||
, address text
|
, address text
|
||||||
, primary key(id, code)
|
, primary key(id, code)
|
||||||
, foreign key (id, code) references test.students(id, code) on delete cascade
|
, foreign key (code, id) references test.students(code, id) on delete cascade
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE test.country(
|
CREATE TABLE test.country(
|
||||||
@@ -3319,6 +3319,11 @@ create table evil_friends(
|
|||||||
, name text
|
, name text
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create table evil_friends_with_column_default(
|
||||||
|
id devil_int default 420
|
||||||
|
, name text
|
||||||
|
);
|
||||||
|
|
||||||
create table bets (
|
create table bets (
|
||||||
id int
|
id int
|
||||||
, data_json json
|
, data_json json
|
||||||
|
|||||||
Reference in New Issue
Block a user