i’ve ran a migration, but it missed a step. How can i get it to re-run an already run migration.
I don’t want to have to takedown and rebuild the environment. I feel like i should be able to just keep running my migration script.
The script has checks and balances for manging if the field exists or not etc. so it won’t fail if run again. But if i’ve fixed the migration, i don’t see an easy way to run and test it again.
ah, theres a schema migration model i can acess via the playground. Which i assume if i delete the entry will let me re-run it.
Is there a command line to do this?
For example i’m eusing --in-place and --source so being able to add something like --re-run or --re-run-migration-id=123 would be helpful.
Hey @emile.swain
The CLI keeps a ledger of executed scripts in a special “schema_migration” model inside the target environment, keyed by the script filename. That’s why re-running with --source and --in-place skips it. You can see that behavior described here: Write and test migration scripts | Documentation — DatoCMS
There isn’t a --re-run or --re-run-migration-id flag today unfortunately
. The simplest way to re-run a fixed script in the same environment is to delete the tracking record for that script in that environment, then run your usual command again. If your script has idempotent checks, it will just apply the missing step.
The simplest way to re-run a fixed script in the same environment is to delete the tracking record for that script in that environment, then run your usual command again. If your script has idempotent checks, it will just apply the missing step. From the command line you can remove that record via the Content Management API, for example with curl once you know the record ID of the “Schema migration” entry:
curl -X DELETE "https://site-api.datocms.com/items/<ITEM_ID>" \
-H "Authorization: Bearer <YOUR_CMA_TOKEN>" \
-H "Accept: application/json" \
-H "X-Api-Version: 3"
API reference for deleting a record is here: Delete a record — Record — Content Management API — DatoCMS
If you would rather not touch the tracking entry, a common alternative is to create a tiny follow up migration that only performs the missing step and run it with npx datocms migrations:run --source=<ENV_NAME> --in-place. The CLI will treat it as a new script and execute it normally.
However I do agree that having a simple --re-run tag would make way easier to tackle this use, so I’m turning this into a feature request, and renaming the title so we can consider it in future product releases