Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+46
-11
@@ -3,7 +3,7 @@
|
||||
# objects that no committed migration creates (the AD-21 footgun: feature
|
||||
# branches use `prisma db push`, so a forgotten merge migration only surfaces
|
||||
# as P2021 at runtime on deploy-managed databases — see
|
||||
# prisma/migrations/20260703150000_ak_schema_parity_catchup).
|
||||
# the consolidated Prisma baseline).
|
||||
#
|
||||
# Replays the full migration history into an ephemeral PostgreSQL container
|
||||
# (shadow DB) and diffs the result against prisma/schema. Any non-empty diff
|
||||
@@ -20,6 +20,11 @@ PARITY_NAME="hivegrid-migrations-parity-$$"
|
||||
PARITY_USER="parity"
|
||||
PARITY_PASSWORD="parity"
|
||||
PARITY_DB="parity"
|
||||
PARITY_MIGRATOR_PASSWORD="migrator_parity_0123456789abcdef0123"
|
||||
PARITY_APP_PASSWORD="app_parity_0123456789abcdef012345678"
|
||||
PARITY_PORTAL_PASSWORD="portal_parity_0123456789abcdef01234"
|
||||
PARITY_WORKER_PASSWORD="worker_parity_0123456789abcdef01234"
|
||||
PARITY_AUTHENTIK_JIT_PASSWORD="authentik_jit_parity_0123456789abcdef"
|
||||
PG_IMAGE="${PARITY_PG_IMAGE:-postgres:16-alpine}"
|
||||
|
||||
require_cmd() {
|
||||
@@ -31,8 +36,11 @@ require_cmd() {
|
||||
}
|
||||
|
||||
require_cmd docker
|
||||
require_cmd node
|
||||
require_cmd pnpm
|
||||
|
||||
node scripts/verify-prisma-baseline.mjs
|
||||
|
||||
cleanup() {
|
||||
docker rm -f "$PARITY_NAME" >/dev/null 2>&1 || true
|
||||
}
|
||||
@@ -45,25 +53,52 @@ docker run -d --name "$PARITY_NAME" -p 127.0.0.1::5432 \
|
||||
"$PG_IMAGE" >/dev/null
|
||||
|
||||
PARITY_PORT="$(docker port "$PARITY_NAME" 5432/tcp | awk -F: 'NR == 1 { print $NF }')"
|
||||
SHADOW_URL="postgresql://${PARITY_USER}:${PARITY_PASSWORD}@127.0.0.1:${PARITY_PORT}/${PARITY_DB}?schema=public"
|
||||
SHADOW_ADMIN_URL="postgresql://${PARITY_USER}:${PARITY_PASSWORD}@127.0.0.1:${PARITY_PORT}/${PARITY_DB}?schema=public"
|
||||
SHADOW_MIGRATOR_URL="postgresql://hivegrid_migrator:${PARITY_MIGRATOR_PASSWORD}@127.0.0.1:${PARITY_PORT}/${PARITY_DB}?schema=public"
|
||||
|
||||
for attempt in $(seq 1 30); do
|
||||
if docker exec "$PARITY_NAME" pg_isready -U "$PARITY_USER" -d "$PARITY_DB" >/dev/null 2>&1; then
|
||||
# Probe over TCP, not the unix socket. On first boot the postgres image starts a
|
||||
# temporary server that listens on the socket ONLY (initdb + init scripts), then
|
||||
# shuts it down before starting the real one. A socket-based pg_isready reports
|
||||
# ready during that window, so the very next psql can hit
|
||||
# "FATAL: the database system is shutting down". The temp server sets
|
||||
# listen_addresses='', so a TCP probe cannot succeed too early.
|
||||
#
|
||||
# The window is deliberately generous. First boot is initdb plus a full
|
||||
# "syncing data to disk", and on a CI runner that is building images in
|
||||
# parallel that I/O can stall for far longer than the container needs when it
|
||||
# runs alone. A 30s window missed a real, healthy boot by 150ms once; the cost
|
||||
# of waiting longer is nothing (the loop exits as soon as the probe answers),
|
||||
# the cost of being too tight is a red pipeline that says "not ready" about a
|
||||
# database that was fine.
|
||||
PARITY_READY_ATTEMPTS=90
|
||||
for attempt in $(seq 1 "$PARITY_READY_ATTEMPTS"); do
|
||||
if docker exec "$PARITY_NAME" pg_isready -h 127.0.0.1 -U "$PARITY_USER" -d "$PARITY_DB" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
if [[ "$attempt" == "30" ]]; then
|
||||
echo "Parity gate Postgres did not become ready" >&2
|
||||
if [[ "$attempt" == "$PARITY_READY_ATTEMPTS" ]]; then
|
||||
echo "Parity gate Postgres did not become ready after ${PARITY_READY_ATTEMPTS}s" >&2
|
||||
docker logs "$PARITY_NAME" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# prisma.config.ts resolves DATABASE_URL at load time; point it at the
|
||||
# ephemeral DB so the gate does not depend on a local .env. The diff itself
|
||||
# only uses the migrations dir, the schema dir and the shadow DB.
|
||||
# The RLS cutover deliberately requires externally provisioned roles and a
|
||||
# non-superuser migrator. Rehearse that same prerequisite in the disposable
|
||||
# database instead of weakening the migration for Prisma's shadow replay.
|
||||
HIVEGRID_RLS_PROVISION_DATABASE_URL="$SHADOW_ADMIN_URL" \
|
||||
HIVEGRID_RLS_MIGRATOR_PASSWORD="$PARITY_MIGRATOR_PASSWORD" \
|
||||
HIVEGRID_RLS_APP_PASSWORD="$PARITY_APP_PASSWORD" \
|
||||
HIVEGRID_RLS_PORTAL_PASSWORD="$PARITY_PORTAL_PASSWORD" \
|
||||
HIVEGRID_RLS_WORKER_PASSWORD="$PARITY_WORKER_PASSWORD" \
|
||||
HIVEGRID_RLS_AUTHENTIK_JIT_PASSWORD="$PARITY_AUTHENTIK_JIT_PASSWORD" \
|
||||
node scripts/provision-rls-roles.mjs >/dev/null
|
||||
|
||||
# prisma.config.ts resolves the datasource at load time. Use the exact
|
||||
# restricted migrator for both datasource and shadow replay so the parity gate
|
||||
# exercises the same ownership and role contract as deployment.
|
||||
set +e
|
||||
DATABASE_URL="$SHADOW_URL" SHADOW_DATABASE_URL="$SHADOW_URL" \
|
||||
DATABASE_URL="$SHADOW_MIGRATOR_URL" DIRECT_URL="$SHADOW_MIGRATOR_URL" SHADOW_DATABASE_URL="$SHADOW_MIGRATOR_URL" \
|
||||
pnpm exec prisma migrate diff \
|
||||
--from-migrations prisma/migrations \
|
||||
--to-schema prisma/schema \
|
||||
@@ -81,7 +116,7 @@ if [[ "$DIFF_EXIT" == "2" ]]; then
|
||||
echo "" >&2
|
||||
echo "FAIL prisma/schema contains changes no migration covers (AD-21: write the merge migration)." >&2
|
||||
echo "Drift script:" >&2
|
||||
DATABASE_URL="$SHADOW_URL" SHADOW_DATABASE_URL="$SHADOW_URL" \
|
||||
DATABASE_URL="$SHADOW_MIGRATOR_URL" DIRECT_URL="$SHADOW_MIGRATOR_URL" SHADOW_DATABASE_URL="$SHADOW_MIGRATOR_URL" \
|
||||
pnpm exec prisma migrate diff \
|
||||
--from-migrations prisma/migrations \
|
||||
--to-schema prisma/schema \
|
||||
|
||||
Reference in new issue
Block a user