Complete M7.2 PostgreSQL adapter and migration bootstrap

This commit is contained in:
dingo
2026-09-28 07:55:18 -04:00
parent 0b9ed18503
commit 60bb492123
24 changed files with 784 additions and 4 deletions
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -euo pipefail
root="$(cd "$(dirname "$0")/../.." && pwd)"
prefix="$root/.cache/postgres/install"
export PATH="$prefix/bin:$PATH"
export LD_LIBRARY_PATH="$prefix/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
test_dir="$(mktemp -d /tmp/evo-pg-test.XXXXXXXX)"
chmod 700 "$test_dir"
export PGHOST="$test_dir" PGPORT=55432 PGDATABASE=postgres PGUSER="$(id -un)"
unset PGHOSTADDR PGPASSWORD PGSERVICE PGSERVICEFILE
initdb -D "$test_dir/data" --no-locale --encoding=UTF8 --auth-local=trust --auth-host=reject > "$test_dir/init.log"
trap 'pg_ctl -D "$test_dir/data" -m immediate stop > /dev/null || true' EXIT
pg_ctl -D "$test_dir/data" -l "$test_dir/server.log" -o "-k $test_dir -p 55432 -c listen_addresses=''" -w start
psql -X -v ON_ERROR_STOP=1 -c 'CREATE ROLE evo_runtime_test NOLOGIN'
bash "$root/tools/migrate-postgres.sh"
bash "$root/tools/migrate-postgres.sh" # exact supported upgrade/restart is a no-op
"${1:?path to evo-postgres-tests}"
# Migration failure must not publish a partial schema.
createdb migration_rollback
if (export PGDATABASE=migration_rollback; psql -X -v ON_ERROR_STOP=1 -1 \
-v migration_sha=invalid -f "$root/migrations/0001_region_bootstrap.sql"); then
echo 'Expected failed migration' >&2; exit 1
fi
test "$(PGDATABASE=migration_rollback psql -XAtc "SELECT count(*) FROM pg_namespace WHERE nspname='evolution'")" = 0
# Unknown future versions and checksum drift must not be repaired silently.
psql -X -v ON_ERROR_STOP=1 -c 'UPDATE evolution.schema_migrations SET version=2'
if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi
psql -X -v ON_ERROR_STOP=1 -c "UPDATE evolution.schema_migrations SET version=1,sha256=repeat('0',64)"
if bash "$root/tools/migrate-postgres.sh"; then exit 1; fi
echo 'postgres migrations, rollback, constraints and permissions passed'
+1 -1
View File
@@ -19,7 +19,7 @@ DOCKER_CONFIG="$(mktemp -d "$RUNNER_TEMP/aevolution-docker.XXXXXX")"
trap 'rm -rf -- "$DOCKER_CONFIG"' EXIT
printf '%s' "$HARBOR_PASSWORD" | docker login registry.aeternalisgames.com \
--username "$HARBOR_USERNAME" --password-stdin
source_image="aevolution-proof:${GITHUB_SHA}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
source_image="${SOURCE_IMAGE:-aevolution-proof:${GITHUB_SHA}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}}"
target_image="registry.aeternalisgames.com/${HARBOR_PROJECT}/${HARBOR_REPOSITORY}:sha-${GITHUB_SHA}-run-${GITHUB_RUN_NUMBER}-${GITHUB_RUN_ATTEMPT}"
docker tag "$source_image" "$target_image"
docker push "$target_image"
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail
root="$(cd "$(dirname "$0")/.." && pwd)"
if [ -n "${EVO_PGPASS_SOURCE:-}" ]; then
umask 077
export PGPASSFILE
PGPASSFILE="$(mktemp /tmp/evo-pgpass.XXXXXXXX)"
trap 'rm -f -- "$PGPASSFILE"' EXIT
cat "$EVO_PGPASS_SOURCE" > "$PGPASSFILE"
fi
# Connection comes from PG* environment / mounted service and password files.
# Never print the connection or enable shell tracing here.
digest="$(sha256sum "$root/migrations/0001_region_bootstrap.sql")"
digest="${digest%% *}"
psql -X --no-password --set=ON_ERROR_STOP=1 --set="migration_sha=$digest" \
--file="$root/migrations/apply.sql"
+20
View File
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -euo pipefail
# Explicit preparation only; never downloaded by CMake configure.
root="$(cd "$(dirname "$0")/.." && pwd)"
cache="$root/.cache/postgres"
mkdir -p "$cache"
cd "$cache"
archive=postgresql-18.6.tar.bz2
if [ ! -f "$archive" ]; then
curl --fail --location --proto '=https' --tlsv1.2 \
"https://ftp.postgresql.org/pub/source/v18.6/$archive" -o "$archive"
fi
echo "555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f $archive" | sha256sum --check -
if [ ! -d postgresql-18.6 ]; then tar -xjf "$archive"; fi
mkdir -p build
cd build
../postgresql-18.6/configure --prefix="$cache/install" --without-readline --without-icu --with-ssl=openssl
make -j2
make install
"$cache/install/bin/pg_config" --version