# Deploy commands

> Commands that run once for every deployment, before the new version takes traffic. The place for database migrations.

Deploy commands run once for every deployment, after the build and before the new version takes traffic. They are the place for work that has to happen once per release, such as a database migration.

## Set them

Open **Settings**, **Deploy commands**, write one command per line and save:

```sh
npm run migrate
```

They are used from the next deployment on.

## How they run

- **Once, not on every replica.** They run on a separate, short-lived copy of the new version. That copy takes no traffic and is removed afterwards.
- **With your variables.** All your [environment variables](https://arrangic.com/docs/environment-variables.md) are set, so a command can reach your database.
- **In order.** The first command that fails stops the rest.
- **For up to 15 minutes** in total.

## If one fails

The deployment fails and the app that is running is not changed. The deployment page shows the message:

| Message | Meaning |
| --- | --- |
| A deploy command failed (exit code N) | A command ended with an error. Its output is in the build log |
| The deploy commands did not finish within 15 minutes | They took too long |
| The deploy commands ran out of memory | They need more memory than the size of the app has |

## When they run

| Deployment | Deploy commands |
| --- | --- |
| Git push, manual deploy | Run |
| Restart, redeploy | Run |
| Rollback | Do not run |
| Domain change | Do not run |

## What to keep in mind

- **Old code is still running.** While a migration runs, the previous version still answers requests. Write migrations that the old code can live with.
- **A rollback does not undo them.** Rolling back brings back old code, not old data.
- **Files they write are not kept.** The copy they run on is thrown away. To create files for the app, use a [build command](https://arrangic.com/docs/build-settings.md#build-commands).

---

This page on the site: https://arrangic.com/docs/deploy-commands  
All pages of the documentation: https://arrangic.com/llms.txt
