mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-05 16:17:10 +01:00
public.profiles had NO foreign key at all. `profiles.id` held an auth.users id by convention only, so deleting a user removed the auth row and left the profile standing forever: a public page, a username still taken, and a row counted by every "how many users" query. Measured in production today: 115 orphaned profiles. 113 came from the per-run `e2e-reset-*` CI fixtures minted since 2026-06-12. refresh-e2e-reset-tokens.mjs was doing its job the whole time — it calls admin.deleteUser on throwaways older than a day — but with no cascade the profile survived every single deletion. The consequence was not cosmetic: 136 of 185 profile rows (73%) were test accounts, so OrangeCat's own signup numbers were mostly synthetic. The real figure — 39 profiles, 5 with a bio, 3 created in the last 30 days — was invisible behind them. A metric nobody can trust is worse than no metric, because it still gets used to decide what to build. No real end user has been orphaned yet; the other 2 are our own memtest_* / selfhost-verify+* fixtures. But nothing prevented it, and "delete my account" must not leave a public profile behind. - FK profiles.id -> auth.users(id) ON DELETE CASCADE. A delete path you have to remember to call is one that eventually is not called; a foreign key cannot be forgotten. Added NOT VALID so it governs every future write without requiring the 115 existing rows to be deleted — purging live production data is a separate, explicit decision and this migration must not smuggle it in. - count_orphaned_profiles(), service_role only, because auth.users is not reachable through PostgREST and the nightly gate needs to see it. - New `profiles.orphaned` invariant in check-data-invariants.mjs — the backstop for the constraint being dropped, bypassed, or left NOT VALID while something writes around it. Verified against the production schema in a rolled-back transaction: migration applies clean, the gate reports 115, and end to end an auth user insert creates a profile (1) while deleting that user now removes it (0). Before this, that second number was 1. The gate will report the 115 existing orphans until they are cleared; that is the honest state, not a regression. After clearing: ALTER TABLE public.profiles VALIDATE CONSTRAINT profiles_id_fkey; Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Scripts Directory
This directory contains all automation scripts organized by purpose.
Directory Structure
analysis/- Bundle analysis, documentation checking, and optimization toolsauth-fix/- Scripts to fix authentication and RLS policy issuesdb/- Database operations, migrations, and schema management- Migration scripts moved from root:
apply-migration.js,apply-*-migration.js - Old schema files archived in
db/archive/
- Migration scripts moved from root:
deployment/- Deployment, production setup, and monitoring scriptsdev/- Development helpers, local setup, and debugging toolsdiagnostics/- Health checks and system diagnosticsmaintenance/- Cleanup, optimization, and maintenance scriptsmonitoring/- Performance monitoring and bundle size trackingoauth/- OAuth provider setup and configurationprofile-fix/- Scripts to fix profile-related issuesschema-fix/- Database schema fixes and migrationsstorage/- Supabase storage bucket setup and managementtest/- Testing utilities and validation scripts- Test/debug scripts moved from root:
test-*.js,check-*.js,debug-*.js
- Test/debug scripts moved from root:
Usage
Most scripts can be run with:
node scripts/{category}/script-name.js
For deployment scripts:
bash scripts/deployment/script-name.sh
Important Scripts
scripts/dev/dev-start.js- Main development server starterscripts/deployment/browser-verify.js- Post-deploy browser smoke test (deploys themselves happen on the box — see docs/deployment/DEPLOYMENT_PROCESS.md)scripts/db/apply-migrations.ts- Database migrationsscripts/maintenance/cleanup-console-logs.ts- Remove console.log statements