Skip to content

Scripts & maintenance CLIs

All scripts run under Bun. Two conventions apply everywhere:

  • Destructive CLIs are dry-run by default and only act with --execute (dev:refresh, queue:admin, backfill-cfdi-encryption, enrich-viewports). There are no interactive prompts; each prints an env banner before acting.
  • Env comes from Doppler: run every script as doppler run -- bun run <script-name> from its package directory (see Local setup). The no-Doppler fallback depends on cwd: root scripts/* rely on Bun auto-loading .env.local from the repo root; package-local scripts are registered with --env-file=../../.env.local in their package.json (filled only for keys not already set, and skipped when the file is absent), so always run them via bun run <script-name> from the package directory.

bun run dev:refresh (scripts/dev-refresh.ts) resets the entire dev environment in one command:

OrderStepWhat happens
1streamFull sweep — hard-deletes ALL GetStream messaging channels, then all users (app is dev-dedicated)
2knockFull sweep — deletes ALL Knock users in the environment (workflows/layouts untouched)
3stripeDeletes ONLY customers referenced by the local DB — the test account is shared with staging, so there is no sweep mode by design; products/prices are never touched
4facturapiCancels test CFDIs (motive 02), then deletes customers referenced by the local DB
5storageDeletes the R2 app-upload prefixes (properties/ — incl. the AI-staging outputs under properties/{id}/staged/ —, pending/properties/, avatars/, agent-avatars/, teams/, floor_plans/, print-ads/) — never search-seeds/, the Meili restore artifacts
6dbRuns bun run db:reset in packages/database as a subprocess (drop schema public + migrate to latest)
7valkeyFLUSHDB on db0 of the volatile instance (cache) and, when VALKEY_DURABLE_URL names a second instance, on its db0 too (psearch:*); then obliterates every suffixed BullMQ queue in QUEUE_BASES (nine, mirrored from apps/worker/scripts/queue-admin.ts) on the durable db1 (never FLUSHDB there)
8meiliDeletes the locations / service_areas / agents indexes; the worker’s ensureSearchIndexes() restores them at boot

Flags: --execute (required to act), --only <csv>, --skip-<step>, --allow-remote-db (needed against Railway DEV because Postgres/Valkey/Meili are remote private services), --allow-unsuffixed, --keep-going.

Preflight. Valkey and Meilisearch are reset after the schema drop, so the script probes both (for the steps selected) right after the banner and exits before any deletion if either fails — otherwise Postgres would be gone while psearch:*, the queues and the indexes stayed stale. Valkey: DBSIZE, then ACL DRYRUN for every command the step will run (FLUSHDB, and SCAN / EVALSHA / EVAL / DEL on the queue keys when queues are selected), so a command-restricted ACL user is refused up front rather than failing after the drop. Meilisearch: an authenticated index listing, so a wrong MEILISEARCH_ADMIN_API_KEY fails here, not after the drop. If a store has no route from where the script runs (a Railway service without a TCP proxy, say), fix the connection or pass --skip-valkey / --skip-meili deliberately (and accept the staleness).

Guards: refuses under NODE_ENV=production, with a non-sk_test_ Stripe or Knock key, an sk_live_ FacturAPI key, or a data-store host that is not provably local without the flag. Note the FacturAPI check is a denylist (sk_live_), not the allowlist Stripe and Knock get — a key in neither format passes. A DATABASE_URL / VALKEY_URL / MEILISEARCH_HOST that is unset is skipped, but one that is set and unparsable (or scheme-less, which parses to an empty host) is treated as non-local and blocked. Because Stream keys and bucket names carry no dev/prod marker, --execute additionally requires the sweep-target pins in .env.local: DEV_REFRESH_STREAM_KEY must match PUBLIC_GETSTREAM_API_KEY and DEV_REFRESH_BUCKET must match AWS_S3_BUCKET_NAME — a production env copied into .env.local fails the match instead of being swept. External ids are collected before the schema drop, and recorded external failures abort before the DB is touched — unless --keep-going, and excepting CFDI cancellation failures, which are warnings by design (a stamped CFDI that refuses cancellation can’t be fixed by re-running) and so do not block the drop. An orphan-risk guard refuses to drop the DB while Stripe/FacturAPI are unconfigured but the DB still references their objects — skipping those steps silently would strand the external records forever.

After an execute run:

  • Restart the worker. Obliterate removed the repeatable schedulers, so boot re-registers them and restores Meilisearch from the existing R2 search-seeds/*.ndjson.gz artifacts.
  • Restart api and svelte-web too. The schema drop recreated the enum types with new OIDs; a running pg pool keeps decoding users.roles as the raw {A,B} literal until it reconnects (packages/database/src/kysely.ts).
  • Re-set the search readiness marker. FLUSHDB removed psearch:schema-version; the worker logs a Sentry error at every boot until cd apps/worker && doppler run -- bun run search:schema -- --verify runs (it passes trivially on an empty index).
  • PostgreSQL remains empty after its migrations; no application data is restored.

bun run scripts/vendor-sync/index.ts (scripts/vendor-sync/) converges the vendor dashboards on what the repo says. CI runs it — together with the Knock CLI push — as the vendor-sync job of ci.yml on every push to development once CI gate is green, so Knock, Stripe and GetStream change in the same run as the code (PRO-102). Every step reads the live state and writes only the differences; a push with nothing to sync is a no-op, which is why the job is not path-gated.

VendorSource of truthWhat converges
stripeBASE_PLANS / ADDON_UNITS (@repo/validation plan-rules), STRIPE_EVENT_ALLOWLIST (apps/api/src/stripe-webhook-events.ts), PORTAL_FEATURES (stripe-portal.ts)One product per catalog entry (metadata.catalog_id) and one price per lookup_key — MXN, catalog cents, tax-inclusive, 1×month / 1×year, the same invariants checkout verifies; a hand-made price that already matches is adopted, product included. The endpoint at STRIPE_WEBHOOK_URL gets exactly the allowlisted events (never created here — a new endpoint means a new signing secret in Doppler). The default Customer Portal configuration’s features.
streamstream/channel-types/messaging.json, stream/app-settings.jsonOnly the keys present in the files, from an allowlist of non-secret settings; push-provider / SQS / SNS / event-hook keys are rejected outright. {} manages nothing.

Flags: --only stripe,stream, --dry-run (print the plan, write nothing), --pull stream (operator seed: write the live app’s allowlisted settings into stream/*.json — the first sync after a pull is a no-op by construction), --allow-price-transfer (let a catalog amount change create a new price, move the lookup_key to it and archive the old one; refused by default because subscriptions still billing on the old price would lose their catalog entry — migrate them first; dev and staging share the test account).

Guards: STRIPE_SECRET_KEY must be a test-mode key (sk_test_ / rk_test_). Env: in CI the job’s GitHub environment development (see Secrets); locally doppler run -- bun run scripts/vendor-sync/index.ts --dry-run. scripts/vendor-sync/*.test.ts run in the tests job and fail a PR whose stream/*.json carries an unknown or forbidden key.

CommandPurpose
bun run db:reset [--allow-remote-db]Drop schema public, rerun the ordered Kysely migration chain (scripts/db-reset.ts). Refuses NODE_ENV=production and any non-localhost DATABASE_URL without the flag; prints the target host first. Postgres only — pair with dev:refresh for the full environment (which forwards its own --allow-remote-db)
bun run db:migrateRun pending Kysely migrations to latest (scripts/migrate.ts). Connects to DATABASE_URL from .env.local — it has no notion of an environment; prints the target host:port/db first and refuses to run without DATABASE_URL. Local databases only: on Railway the same script is the pre-deploy command of api and worker, run automatically before each deploy goes live (see deploy/README.md § Database migrations)
bun run db:codegenRegenerate src/generated/db.ts from the live DB (kysely-codegen)
bun run scripts/check-enum-array-parser.tsVerify the "UserRole"[] enum-array node-pg parser fix (roles must decode as string[])
CommandPurpose
bun --env-file=../../.env.local run queue:admin <cmd>Operational queue CLI — counts, inspect, retry-failed, promote, DLQ replay. See Incident guides
bun run backfill:searchEnqueue sync-agent / sync-team for all public agents + teams → rebuilds the Meili agents index
bun run backfill:propertiesEnqueue sync-property for every ACTIVE property → rebuilds psearch:*
bun run backfill:main-imagesOne-off repair: promote a cover image for properties with photos but no isMain row
bun run search:schemaProperty-search schema migration command (--dry-run / --enqueue / --verify)

Backfills only enqueue — a running worker does the work.

CommandPurpose
bun run sync:locationsWipe + rebuild the Meili locations index from the SEPOMEX XML (not in git — slow path; prefer the S3 seed restore)
bun run sync:service-areasSame wipe-and-rebuild for service_areas
bun run export:search-seedExport locations + service_areas to gzipped NDJSON seeds in R2 (search-seeds/) — what ensureSearchIndexes() restores from
bun --env-file=../../.env.local run scripts/enrich-viewports.tsRe-geocode _geo + viewport bounds via Google Geocoding (--execute gated)
CommandPurpose
bun native/tooling/src/sync-native-i18n.tsFan the shared native/i18n/{user,agent}/{en,es}.json catalogs out to the four native apps
bun design-tokens/export-native-tokens.mjsRegenerate Tokens.swift / Tokens.kt / tokens.generated.css from design-tokens/tokens.cjs and copy the brand TTFs from design-tokens/fonts/ into MeridianUI and :core:design-system — commit the output
bun run packages/contract/scripts/codegen-models.tsRegenerate the native Swift/Kotlin DTOs from the @repo/contract Zod schemas
bun run scripts/contract-fixtures/generate-fixtures.tsCapture real tRPC response envelopes into the canonical packages/contract/fixtures/{user,agent}/
bun native/tooling/src/sync-contract-fixtures.tsCopy packages/contract/fixtures/ into the iOS/Android test trees (--check fails on a drifted copy; CI runs it)
cd packages/contract && bun run fixtures:validateParse each committed fixture through its authoritative Zod schema — fails on contract drift

Guards & CI checks (root scripts/ + native/tooling/)

Section titled “Guards & CI checks (root scripts/ + native/tooling/)”
CommandPurpose
bun run scripts/check-job-data-casts.tsEnforce that BullMQ processors Zod-parse job.data instead of type-asserting (FSR-019/086)
bun run scripts/check-env-schema.tsCompare the @repo/config env schemas with turbo.json (globalEnv, task env) and the root + per-app .env.example files; fails on a key missing from either side (PRO-170)
bun run scripts/check-process-env.tsFail on an environment read outside @repo/config: process.env, Bun.env or SvelteKit’s $env/*/private in src/ of a host or package. Walks the TypeScript AST, so comments never trip it; tests, scripts and build config are out of scope (PRO-170)
bun native/tooling/src/check-i18n-parity.tsNative catalog invariants: en↔es key parity, synced copies byte-equal, every native t("…") key exists
bun test scripts/ci-change-scopes.test.tsAssert ci.yml and the /commit classifier both source .github/scripts/change-scopes.sh and pick the same jobs for pinned native paths
bun run docs:checkBuild the docs site, then run docs-stale-check.ts (stale references) + docs-link-check.ts (broken relative links)
bun run scripts/generate-email-previews.tsRegenerate the static email-templates/ previews from the real email builders — commit the output
CommandPurpose
packages/api/scripts/parity-*.ts (14 scripts)Behavior + atomicity tests for the Kysely-migrated services — run against a scratch DB (they write and clean up): DATABASE_URL=<scratch> bun run scripts/parity-leads.ts
bun run packages/api/scripts/backfill-cfdi-encryption.tsEncrypt pre-FSR-014 plaintext fiscal PII rows in place (--execute gated)
bun run packages/integrations/scripts/backfill-inquiry-chat-channels.tsOne-off backfill of Inquiry.chatChannelId from derived GetStream channel ids (migration 0012)
bun native/tooling/src/firebase-distribute.tsBuild + upload a signed native app artifact to Firebase App Distribution. See Release playbooks