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:
2026-05-19 00:15:06 +02:00
parent abfb64b177
commit 1638d2f6e8
2 changed files with 17 additions and 0 deletions

View File

@@ -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")