name: create-backend-migration description: Create safe erxes backend MongoDB migrations or command scripts. Use when existing persisted data needs idempotent migration, backfill, repair, or cleanup.
Skill: Create Backend Migration
Workflow
- Confirm a migration or command is actually needed for existing data.
- Search for service-local migration or command patterns before adding files.
- Put the script in the owning service or plugin's existing location, such as
src/migrationsorsrc/commands. - Make the script idempotent so running it twice does not corrupt data.
- Read
MONGO_URLor service env values consistently with nearby scripts. - Process large collections in batches when practical.
- Log useful progress without logging secrets, tokens, or sensitive payloads.
- Close database connections or exit cleanly.
- Run focused validation, usually
pnpm nx build <api-project>.
Important
- Do not add migrations for purely frontend changes.
- Prefer guarded
$set,$unset,$addToSet, and filtered updates over full document replacement. - Avoid hardcoded tenant, brand, user, or subdomain data.
- Preserve existing ID conventions.
- Do not add temporary public GraphQL mutations or routes for migrations unless explicitly requested.