# axle migrate

Update axle.toml, its presets and plugin settings to what this version of Axle reads, and the tools plugins know about to their new versions.

```sh
axle migrate
axle migrate --check
axle migrate --upgrade
```

When a setting is renamed or changes shape, Axle refuses the old one with [`migration-needed`](https://axlers.dev/docs/messages/migration-needed.md), so a repository never runs with settings Axle reads differently. `axle migrate` rewrites them for you, in every file Axle reads its settings from:

- the root `axle.toml`;
- each preset it [extends](https://axlers.dev/docs/reference/configuration.md#presets) from a folder in the repository, such as `./config/axle.toml`, and the presets those extend in turn;
- the settings of each plugin under `[plugins]` that can [`migrate`](https://axlers.dev/docs/reference/plugins.md#migrate) them.

Everything else in those files stays as it is, comments and formatting included. Presets installed as npm packages aren't changed: update the package instead. `axle migrate` prints each file it updates, then one line for each change, such as:

```text
Updated axle.toml

axle.toml: env at the root is now globalEnv
```

Running it again changes nothing, and prints "Nothing to migrate: the settings are up to date."

## Migrations

| Since | Before                       | After                  |
| ----- | ---------------------------- | ---------------------- |
| 0.1   | `env` at the root            | `globalEnv`            |
| 0.1   | `passThroughEnv` at the root | `globalPassThroughEnv` |

`env` and `passThroughEnv` in a task keep their names. A file that sets both the old and the new name stops `axle migrate` with [`file-has-a-mistake`](https://axlers.dev/docs/messages/file-has-a-mistake.md) before anything is written: move what the old key lists into the new one, and delete the old one.

## Upgrading tools

`axle migrate --upgrade` also asks each plugin under `[plugins]` that can [`upgrade`](https://axlers.dev/docs/reference/plugins.md#upgrade) to move the projects it knows about to the version of its tool that it supports, and to make the changes to their code and settings that the new version needs, which a codemod would. The [Next.js plugin](https://axlers.dev/docs/official-plugins/next.md#upgrading-to-nextjs-16), for example, moves apps to Next.js 16 and replaces `next lint` in their scripts.

```text
Updated apps/web/package.json

plugin next: web: next ^15.3.0 is now ^16.0.0
plugin next: web: the lint script runs eslint . instead of next lint, which Next.js 16 removed
```

A plugin knows the version it supports, so updating the plugin's `source` in `axle.toml` and running `axle migrate --upgrade` is how a repository moves to a new version of a tool. A project that's already there, or that takes the tool from `workspace:`, a link or a tag, is left alone. The settings are migrated first, then the plugins read the files as they are on disk. With `--dry-run` or `--check` and settings that still need migrating, the plugins' changes show once you've run `axle migrate`.

When a `package.json` changed, Axle says to install the dependencies again, so the lockfile has the new versions. Then run the builds and tests, check the changes, and commit them. Two plugins that would change the same file [stop](https://axlers.dev/docs/messages/upgrade-files-conflict.md) `axle migrate --upgrade` before it writes anything.

## Options

| Option      | What it does                                                                                                         |
| ----------- | -------------------------------------------------------------------------------------------------------------------- |
| `--check`   | changes nothing, and fails with [`migration-needed`](https://axlers.dev/docs/messages/migration-needed.md) when any file needs migrating |
| `--dry-run` | shows the changes as a diff, and writes nothing                                                                      |
| `--upgrade` | also asks the plugins to [upgrade](#upgrading-tools) the tools they know about, and the code that needs it           |

Run `axle migrate` after updating Axle, check the changes, and commit them.
