#!/bin/bash # Reproduces every factual claim in # https://www.heatware.net/postgresql/how-to-drop-a-constraint/ # # Creates a throwaway PostgreSQL cluster in a temp directory on port 55494, builds two # small tables, asserts each documented error message and result, then stops the cluster # and deletes it. It does not touch any existing PostgreSQL installation, database, # data directory, or role. # # Requires: initdb, pg_ctl, psql on PATH. # Runtime: about 10 seconds. # Usage: bash verify-how-to-drop-a-constraint.sh set -u PORT=55494 PGDATA_TMP="$(mktemp -d -t hwdrc)" # The socket directory must be short: PostgreSQL caps the Unix socket path at 103 bytes. SOCK="$(mktemp -d /tmp/hwdc.XXXXXX)" cleanup() { pg_ctl -D "$PGDATA_TMP/data" stop -m immediate >/dev/null 2>&1 rm -rf "$PGDATA_TMP" "$SOCK" } trap cleanup EXIT PASSES=0; FAILS=0; SKIPS=0 pass() { PASSES=$((PASSES+1)); printf 'PASS %s\n' "$1"; } fail() { FAILS=$((FAILS+1)); printf 'FAIL %s\n expected: %s\n actual: %s\n' "$1" "$2" "$3"; } skip() { SKIPS=$((SKIPS+1)); printf 'SKIP %s (needs %s)\n' "$1" "$2"; } check(){ [ "$2" = "$3" ] && pass "$1" || fail "$1" "$2" "$3"; } # contains