How Deployz finds your migration command
The analysis looks for a migration script in thepackage.json of the package your container image runs: the repository root, the Dockerfile’s directory, or the container image’s working directory. It accepts only a command that’s safe to run on every deploy. It rejects:
- Steps that create, generate, push, reset, roll back, or seed a database, and test or build steps.
- Scripts that run through a workspace or monorepo runner, such as
pnpm --filter,yarn workspaces,turbo, ornx, or that use a../path. These don’t work from the container image’s working directory. - Scripts whose migration tool isn’t installed in the final container image. For example, a CLI such as
prismaorknexindevDependenciesis missing unless your Dockerfile keeps development dependencies.
python manage.py migrate. See Set or change the migration command.
The analysis result is one of these:
Choose how Deployz runs database migrations is usually listed under Set in Deployz. When the AI part of the analysis couldn’t tell how your application migrates its database, it’s listed under Change in your repository instead, because you might need to check the repository before you choose.
Set or change the migration command
Who: you (the vendor), in the Deployz dashboard.1
Open the migrations setting
Open your application, select Configuration, then Resources. On the Database migrations row, select Edit database migrations, or Add database migrations when no command is set. The Migration command dialog opens.
2
Choose how migrations run
In Use for deployment, enter a command the container image can run, for example
npm run migrate. The command must be installed in the final container image. If your application doesn’t need a separate migration step, turn on No separate migration instead.3
Save
Select Save.
Reset to detected
After you save your own choice, the dialog shows Reset to detected. Select it to undo your choice. New deployments then use the command the analysis found, and existing deployments go back to the command they were created with.Deployments created without a migration step
You can’t add a migration command to a deployment that was created without a separate migration step. If you set a command for the application, Deployz refuses to deploy a release to that deployment, and no update starts. The message reads: “This deployment was created without a separate migration step, so a migration command cannot be added to it. Choose “No separate migration” for the application, or create a new deployment.” To deploy to it, choose No separate migration for the application, or create a new deployment for that customer.How migrations run
When you deploy a release, Deployz runs these steps in the customer’s AWS account:- Waits until the infrastructure and the database are ready.
- Runs the migration command once, as a one-shot task that uses the release’s container image.
- Updates the web service and workers to the new release, only after the migration succeeds.
0. Deployz runs the command through sh -c, so your container image must include sh.
If the migration fails, Deployz doesn’t update or start any service, and the deployment shows Migration failed:
- First install. Nothing was serving yet, so Deployz starts the service only after the first migration succeeds. If it fails, the deployment is Failed. Fix the migration and deploy again.
- Later releases. The update fails and the previous release keeps serving customers.
MIGRATION_FAILED and The database migration failed.
When a migration runs again
Deployz skips the migration only when an earlier update of the deployment finished successfully with the same command and release. A changed command counts as a new migration, so it runs even for the same release. Retry update starts a new update. If an earlier attempt ran the migration and then failed, for example during the rollout, the migration runs again. Write migrations that are safe to run more than once, for example by using a migration tool that records which migrations it has applied.Rollback and restart skip migrations
Rolling back and restarting a deployment never run your migration command.Keep migrations safe for rollback
A rollback restores the previous release only. It doesn’t reverse database migrations. The rollback screen shows this warning: “Application rollback does not automatically reverse database migrations.” After a rollback, the previous release runs against the newer schema. To keep that working, write backward-compatible migrations:- Add new tables and columns before code depends on them. Make new columns nullable or give them defaults.
- Don’t rename or drop a column in the same release that stops using it. Stop using it in one release, then remove it in a later one.
- Avoid changing a column’s type in place. Add a new column, copy the data, and switch reads over in a later release.
Spread a schema change across releases so that each rollback still works.
