Change a live schema
Add, rename and remove fields on a site that already has content, without losing what your client wrote.
Open with AI
Schemas change as websites grow. atmyapp migrate makes those changes safe: it compares your new schema with the content that is already stored, shows you a plan, and changes nothing until you approve it.
The everyday flow
Section titled “The everyday flow”-
Edit
atmyapp.schema.ts. -
Check it locally. This compiles and validates the schema without contacting the server:
Terminal window npx atmyapp migrate --dry-run -
Run the migration:
Terminal window npx atmyapp migrateThe CLI asks the project for a plan. The plan lists the schema changes, how many stored items they rewrite, anything removed, and content problems the change would cause. Problems that existed before are listed separately.
-
Read the plan and confirm. If the change touches stored content, the CLI asks before applying it. Applying runs exactly the plan you saw. If someone edited content in the meantime, nothing is written, and you run it again to review a fresh plan.
-
Deploy the code that uses the new fields.
Changes that don’t touch stored content, such as adding an optional field, a new document or a new collection, apply without a question.
What the plan blocks, and how to unblock it
Section titled “What the plan blocks, and how to unblock it”A plan is blocked when applying it would leave stored content invalid. Nothing is changed. The common cases:
| You changed | Why it’s blocked | Fix |
|---|---|---|
| Added a required field | Existing entries don’t have it | Make it optional: true, or backfill it |
| Made an optional field required | Some entries are empty | Backfill it, or fill the entries in the dashboard first |
| Removed a collection | Its entries would be deleted | Confirm with --clear-collection <name> |
| Removed a document | Its content would be deleted | Confirm with --clear-content <name> |
| Removed a field | Editors would lose it | Confirm with --clear-column <collection.field>. The field is hidden; its stored values are kept. |
Warnings are softer. A shorter max than some stored values, for example, doesn’t block the plan, but you must confirm it. Your client will need to shorten those values before they can publish them again.
Rename a field
Section titled “Rename a field”The CLI never guesses renames. A field that disappears and another that appears are a removal plus an addition, which would lose the old values. Declare the rename in an operations file instead:
[ { "type": "renameField", "definition": "posts", "from": "title", "to": "headline" }]Rename the field in your schema, then run:
npx atmyapp migrate --operations migrations/rename-title.jsonrenameField moves the stored values, including translations, and moves the dashboard’s form layout to the new name. Update your website code in the same release.
Fill a new required field
Section titled “Fill a new required field”To add a required field to entries that already exist, give them a value as part of the migration:
[ { "type": "backfillField", "definition": "posts", "field": "summary", "value": "" }]backfillField fills the field only where it’s missing. Pick a value that renders well, or one your client will recognise and replace. A default in the schema is not a backfill: it only applies to new content.
Operations can be combined in one file. Each field can appear in only one operation.
Run migrations in CI
Section titled “Run migrations in CI”Store the CLI URL and key as CI secrets, connect, then migrate:
npx atmyapp use --url "$ATMYAPP_CLI_URL" --token "$ATMYAPP_CLI_KEY"npx atmyapp migrate --yes --jsonWithout a terminal, a plan that needs confirmation stops with confirmation-required. Add --yes only to pipelines that should apply such plans, after a person has reviewed them. With --json, the plan and the result are printed as one JSON document.
Run migrations against the project your website code expects. If you keep separate projects for staging and production, use a separate CLI key for each.
If the connection drops
Section titled “If the connection drops”Before it applies anything, the CLI saves a record in .ama/migrations/<operation-id>.json. It includes the server, the compiled schema and the operations, but never your token. If the response is lost, the migration may or may not have been applied. Ask:
npx atmyapp migrate-status # the last migration started herenpx atmyapp migrate-status <operation-id>If it reports the migration as committed but its follow-up work as unfinished, finish it with:
npx atmyapp migrate-status <operation-id> --reconcile--reconcile uses the recorded schema and operations, so later edits to your schema file don’t matter.
Safe habits
Section titled “Safe habits”- Add first, remove later. Add the new field, ship the code that reads it, move the content, and remove the old field in a later release.
- Commit operations files next to the schema change they belong to.
- Keep code tolerant during the switch. For one release, handle both the old and new shape, or deploy right after the migration.
- Never use
--dangerously-resolve-all-conflictson a client’s project unless you mean to delete everything the plan lists.
See every option in the CLI reference.
