deploy(prod): NOTIFY pgrst reload schema after migrations + after rollback
Post-deploy, PostgREST keeps its pre-migration pg_proc snapshot and 404s any RPC added in the just-applied migrations until the rest container restarts. Confirmed on 2026-05-18 after migration 026 (set_item_frequency_weight + purge_item_frequency) — the "Purgar" button in /collective/manage returned "Could not find the function public.purge_item_frequency in the schema cache". `NOTIFY pgrst, 'reload schema'` triggers the same reload path the container would do on restart, but without a 2s blip in flight requests. Added at the end of the migration loop in deploy-erosi.sh, and at the end of the rebuild step in rollback-erosi.sh (rollback can change RPC shapes too). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -206,6 +206,16 @@ for f in supabase/migrations/*.sql; do
|
||||
fi
|
||||
done
|
||||
|
||||
# Force PostgREST to reload its schema cache. Without this, RPCs added in
|
||||
# the migrations above 404 with "Could not find the function ... in the
|
||||
# schema cache" until the rest container is restarted. Confirmed bug on
|
||||
# 2026-05-18 after migration 026 added set_item_frequency_weight +
|
||||
# purge_item_frequency. NOTIFY is cheaper than a container restart.
|
||||
echo "--- Reloading PostgREST schema cache"
|
||||
docker compose --env-file .env -f infra/docker-compose.erosi.yml exec -T db \
|
||||
psql -U postgres -d postgres </dev/null \
|
||||
-c "NOTIFY pgrst, 'reload schema';"
|
||||
|
||||
# Record the successful deploy in .deploys.log (read by rollback-erosi.sh).
|
||||
backup_file=$(cat /tmp/.colectivo-last-backup 2>/dev/null || echo "")
|
||||
deploy_ts=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
@@ -175,6 +175,13 @@ cd /opt/colectivo
|
||||
GIT_SHA="$GIT_SHA" docker compose --env-file .env -f infra/docker-compose.erosi.yml \
|
||||
build --build-arg GIT_SHA="$GIT_SHA" app
|
||||
GIT_SHA="$GIT_SHA" docker compose --env-file .env -f infra/docker-compose.erosi.yml up -d
|
||||
|
||||
# Reload PostgREST schema cache so any RPCs that changed shape between
|
||||
# the rolled-back schema and the current rest container snapshot are
|
||||
# resolved. Mirrors the same step at the end of deploy-erosi.sh.
|
||||
docker compose --env-file .env -f infra/docker-compose.erosi.yml exec -T db \
|
||||
psql -U postgres -d postgres </dev/null \
|
||||
-c "NOTIFY pgrst, 'reload schema';"
|
||||
REMOTE
|
||||
|
||||
echo ""
|
||||
|
||||
Reference in New Issue
Block a user