Files
orangecat/scripts
de30fdb346 feat(profiles): let a handle be retired without breaking what points at it (#773)
75 accounts still publish their email local part as a public username.
Renaming them is the fix, and #769/#770 deliberately renamed nobody,
because a username here is not just a display name:

  * a public profile URL   /profiles/<username>
  * a LIGHTNING ADDRESS    <username>@orangecat.ch
    (.well-known/lnurlp, /api/lnurlp/<username>/callback)

A bare rename would silently break saved payment addresses and every
inbound link. Silently: the wallet gets "no such recipient", nobody sees
an error, and the money just does not arrive.

profile_username_history makes a rename safe. The old handle keeps
resolving forever, so a rename changes what a profile is CALLED without
changing what can still find it:

  /profiles/<old>       301s to the new handle (permanentRedirect, so
                        search engines move the entry instead of
                        recording a 404 against the account)
  <old>@orangecat.ch    LNURL resolves through history to the account

Old handles are kept, not expired: a Lightning address someone saved has
no expiry either, and a dangling payment identifier is worse than a stale
row. The primary key is the old handle, so one can never be re-issued to
a second account — that would silently redirect the first person's
payments to somebody else.

Also fixes a live matcher bug on the payment path. resolveLnurlRecipient
used `.ilike('username', handle)`; ilike treats `_` as a
single-character wildcard and `_` is a legal username character. Now that
every newly minted handle is shaped `user_<hex>`, an ilike lookup for
`user_823e4d9d2714` also matches `userX823e4d9d2714`. It now matches
exactly on username_lower, the generated column added in 20260826120000.
The history column is stored lowercase with a CHECK enforcing it, for the
same reason: PostgREST can only filter on columns, so a lower() index
would be unusable and the code would fall back to ilike again.

scripts/rename-email-derived-usernames.sql performs the rename: records
history first (a renamed profile with no history row is a dangling
payment address), then renames, then clears the 13 display names that are
also the email local part — the same leak wearing another label. It is
NOT a migration: it rewrites rows for real accounts, so it is a
deliberate operation someone runs and checks. It documents its own dry
run and is reversible from the history table.

Dry run on production: 75 to rename, 13 names to clear.

npm run verify green; 2373 tests pass, including four new ones covering
the case that matters — a payment sent to a retired handle still reaches
its owner.

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 15:22:32 +02:00
..
…
…

Scripts Directory

This directory contains all automation scripts organized by purpose.

Directory Structure

  • analysis/ - Bundle analysis, documentation checking, and optimization tools
  • auth-fix/ - Scripts to fix authentication and RLS policy issues
  • db/ - Database operations, migrations, and schema management
    • Migration scripts moved from root: apply-migration.js, apply-*-migration.js
    • Old schema files archived in db/archive/
  • deployment/ - Deployment, production setup, and monitoring scripts
  • dev/ - Development helpers, local setup, and debugging tools
  • diagnostics/ - Health checks and system diagnostics
  • maintenance/ - Cleanup, optimization, and maintenance scripts
  • monitoring/ - Performance monitoring and bundle size tracking
  • oauth/ - OAuth provider setup and configuration
  • profile-fix/ - Scripts to fix profile-related issues
  • schema-fix/ - Database schema fixes and migrations
  • storage/ - Supabase storage bucket setup and management
  • test/ - Testing utilities and validation scripts
    • Test/debug scripts moved from root: test-*.js, check-*.js, debug-*.js

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 starter
  • scripts/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 migrations
  • scripts/maintenance/cleanup-console-logs.ts - Remove console.log statements