# backend/scripts One-off scripts: data migrations, ad-hoc maintenance, schema regeneration. **Not** a deployed service. See the [root CLAUDE.md](../../CLAUDE.md) for monorepo context. ## Layout Each script is a single TS or SQL file at the top level, dated for ordering: ``` backend/scripts/ ├── run-script.ts runScript({pg}) helper — loads .env + Supabase client ├── 2026-03-10-delete-users-without-profile.ts ├── 2026-03-09-migrate-unencrypted-messages.ts ├── 2025-04-23-migrate-social-links.ts ├── regen-schema.ts Regenerate common/src/supabase/schema.ts ├── *.sql Raw SQL one-offs └── import-tables.sh Bulk import from prod ``` ## The `runScript` pattern Every TS script lives inside `runScript`. It calls `initAdmin()`, loads secrets via dotenv from `.env`, and hands you a pg-promise client: ```ts import {runScript} from 'run-script' runScript(async ({pg}) => { const rows = await pg.manyOrNone('select id from users where ...') for (const r of rows) { await pg.none('update users set ... where id = $1', [r.id]) } }) ``` Run with `bun run