Files
Jyotisha/debug-admin-payments-500.md
T
linmeng 2f4d00c528
Deploy staging to test server / deploy (push) Successful in 6m34s
fix: complete self-hosted staging identity integration
Align staging deployment, authentication, and admin access with the self-hosted identity boundary, including regression coverage and deployment diagnostics.
2026-07-30 14:54:46 +08:00

48 lines
1.9 KiB
Markdown

# Debug Session: admin-payments-500
Status: [OPEN]
## Symptom
Staging admin payment and package endpoints return HTTP 500. Confirmed example:
`GET https://staging.jyotisha.chat/api/admin/payments?limit=20&offset=0`
## Constraints
- Do not modify business logic before runtime evidence identifies the root cause.
- Do not expose database URLs, JWTs, cookies, passwords, or keys.
- Preserve unrelated dirty workspace files.
## Hypotheses
1. Staging still runs an older SHA and the direct PostgreSQL fix is not deployed.
2. `ADMIN_DATABASE_URL` is absent or PostgreSQL is unreachable from the web container.
3. `admin_runtime` lacks SELECT privileges on payment/package/identity tables.
4. Required staging migrations have not been applied.
5. The SQL query does not match the staging schema.
## Evidence Log
- Pre-fix staging health reports deployment SHA `dd8e2ad9c7e76d0152b4563c43a45b1e26137035`.
- Health reports both local business and identity databases as healthy; deployment drift and general database unreachability are rejected.
- SSH application logs are blocked because this workstation has no staging private key; no server stack trace is claimed.
- Static migration audit confirms `20260727020000_epay_packages_orders.sql` grants payment objects only to Supabase roles, not `admin_runtime`.
- Both failing APIs use `ADMIN_DATABASE_URL` through `queryAdminRows`, so the missing grants and RLS policies explain the shared HTTP 500 failure.
## Fix
Added forward migration `20260730010000_admin_payment_permissions.sql` with least privilege:
- package SELECT/INSERT/UPDATE for `admin_runtime`;
- payment-order SELECT only;
- matching RLS policies;
- epay settings SELECT and save-function EXECUTE.
No API business logic was changed.
## Verification
- Pre-fix contract test failed because the permission migration did not exist.
- Post-fix payment/package/epay contract suite: 21/21 passed.
- Staging migration and authenticated endpoint smoke are still pending.