# Roll back

An environment serves one release. To roll back, [deploy](/docs/concepts/project-lifecycle.md#deployments) an earlier release to it again.

## Before you start

You need an environment with more than one release deployed to it. See [Publish](/docs/deployment/publish.md).

## Put an earlier release back

**Studio**

1. Open **Deployment** > **Releases**.
2. Open the menu of the release you want back.
3. Click **Deploy**.
4. Leave **Production** ticked.
5. Untick **Staging**.
6. Click **Deploy**.
7. Open **Deployments**. You should now see the earlier release's ID in the top row, on Production.

**API**

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. Get the project with your [API key](/docs/authentication/api-keys.md):

```bash
curl https://api.veryfront.com/projects/$PROJECT \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

3. Set `ENVIRONMENT_ID` to the `id` of the entry named `production` in its `environments`: `export ENVIRONMENT_ID=<id>`. Its `active_release_id` is the release it serves now.
4. List the releases:

```bash
curl https://api.veryfront.com/projects/$PROJECT/releases \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

5. Set `RELEASE_ID` to the `id` of the last good release, by its `version`: `export RELEASE_ID=<id>`.
6. Deploy it to production again:

```bash
curl -X POST https://api.veryfront.com/projects/$PROJECT/deployments \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"release_id\":\"$RELEASE_ID\",\"environment_id\":\"$ENVIRONMENT_ID\"}"
```

7. Get the project again. You should now see production's `active_release_id` is that release:

```bash
curl https://api.veryfront.com/projects/$PROJECT \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

### Try it in a sandbox

```playground
step: Create a project | npm create -y veryfront@latest support-desk -- --template minimal --yes
step: Push it | cd support-desk && npx veryfront push
step: Deploy release 0.0.1 | export R=$(curl -s -X POST https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID/releases -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"branch_reference":"main"}' | jq -r .id) && until curl -s https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID/releases/$R -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -e '.asset_manifest.state == "ready"'; do sleep 3; done && curl -X POST https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID/deployments -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d "{\"release_id\":\"$R\",\"environment_id\":\"$(curl -s https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r '.environments[] | select(.name == "production") | .id')\"}"
step: Change the heading | sed -i 's/Welcome to Veryfront/Support desk/' app/page.tsx
step: Push the change | npx veryfront push
step: Deploy release 0.0.2 | export R=$(curl -s -X POST https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID/releases -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"branch_reference":"main"}' | jq -r .id) && until curl -s https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID/releases/$R -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -e '.asset_manifest.state == "ready"'; do sleep 3; done && curl -X POST https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID/deployments -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d "{\"release_id\":\"$R\",\"environment_id\":\"$(curl -s https://api.veryfront.com/projects/$VERYFRONT_PROJECT_ID -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r '.environments[] | select(.name == "production") | .id')\"}"
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_ID
step: Set ENVIRONMENT_ID | export ENVIRONMENT_ID=$(curl -s https://api.veryfront.com/projects/$PROJECT -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r '.environments[] | select(.name == "production") | .id')
step: Set RELEASE_ID | export RELEASE_ID=$(curl -s https://api.veryfront.com/projects/$PROJECT/releases -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r '.data[] | select(.version == "0.0.1") | .id')
step: Deploy it to production again | curl -X POST https://api.veryfront.com/projects/$PROJECT/deployments -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d "{\"release_id\":\"$RELEASE_ID\",\"environment_id\":\"$ENVIRONMENT_ID\"}"
check: curl -s https://api.veryfront.com/projects/$PROJECT -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r '.environments[] | select(.name == "production") | .active_release_id == env.RELEASE_ID'
expect: true
```

## With MCP

1. Call `veryfront__list_releases` with `project_reference` (the project's slug or ID). Keep the `id` of the release whose `version` you want back (`0.0.1`).
2. Call `veryfront__list_environments` with `project_reference`. Keep the `id` of the one named `production`.
3. Call `veryfront__create_deployment` with `project_reference`, the `release_id` and the `environment_id`.
4. Call `veryfront__list_deployments` with `project_reference` and the `environment_id`. It worked when the newest deployment names the earlier release.

## Next steps

* [Debug a run](/docs/observability/debug.md)
* [Set variables](/docs/runtime/environments.md)
