Skip to main content

Cleaning up test entities

Scope: deleting the ephemeral fixtures (Clerk users/orgs, local DB rows) a manual testing session created. Test entities are real Clerk dev-instance records + real DB rows — leaving them behind pollutes the shared instance.

Source-checked against optolink-backend @ 29f8589, 2026-10-06 (unique Organization.clerkOrgId / User.clerkUserId columns in prisma/schema.prisma — the DB deletes key off exactly these). The Clerk free-tier organization cap is recorded 2026-09; re-verify live on next use — it is Clerk pricing, not repo code.

pkill -f "clerk webhooks listen"; pkill -f "nest start"

clerk api "/organizations/$O" -X DELETE --yes | jq -c '{deleted:.deleted,id:.id}'
clerk api "/users/$U" -X DELETE --yes | jq -c '{deleted:.deleted,id:.id}'

DBURL="${DATABASE_URL%%\?*}"
psql "$DBURL" -tAc "DELETE FROM \"Organization\" WHERE \"clerkOrgId\"='$O';"
psql "$DBURL" -tAc "DELETE FROM \"User\" WHERE \"clerkUserId\" ='$U';"

What is NOT ephemeral​

  • The pinned relay token (c_Nvj2aA97D0) — the Svix endpoint points at it for all future sessions. Leave it alone (webhook-relay).
  • The seeded orgs/users (Demo Org, OptoLink Ops, admin@, demo@) — stable fixtures other tests depend on.

Quota rule for automated tests​

Never create new Clerk orgs in high-volume automated tests — the Clerk free tier caps monthly retained organizations at 100. Use the stable seeded orgs, or DB-only org records (no clerkOrgId) for unit tests.