# Migrate Commands

The `migrate` command provides operations for managing Limo infrastructure migrations. Migrations are a flexible, reusable format for defining executable infrastructure changes using YAML.

## Commands

### `migrate apply`

Applies pending migrations in sequence.

```bash
limo migrate apply [options]
```

Options:

- `-d, --directory <directory>`: Directory for the base infrastructure folder (defaults to current directory)

The apply command:

1. Reads unapplied migrations from `infrastructure/migrations/`
2. Applies them in chronological order
3. Updates `history.yaml` after each successful migration

### `migrate revert`

Reverts the most recently applied migration.

```bash
limo migrate revert [options]
```

Options:

- `-d, --directory <directory>`: Directory for the base infrastructure folder (defaults to current directory)

The revert command:

1. Reads the last applied migration from `history.yaml`
2. Executes the down operations in reverse order
3. Updates `history.yaml` to remove the migration

## Migration File Structure

Migrations are YAML files that define infrastructure changes:

```yaml
id: unique-migration-id
up:
  - type: operation-type
    options:
      args:
        key: value
down:
  - type: operation-type
    options:
      args:
        key: value
```

### Operation Types

- `initResourceGroup`: Initialize a new resource group
- `removeResourceGroup`: Remove an existing resource group
- `configureFramework`: Configure framework-specific settings
- `addComponents`: Add infrastructure components
- `removeComponents`: Remove infrastructure components
- `installComponents`: Install component dependencies
- `addInstance`: Add a component instance
- `removeInstance`: Remove a component instance
- `applyResourceGroupChanges`: Apply changes to a resource group
- `undoResourceGroupChanges`: Undo changes to a resource group
- `runCodeMod`: Run code modifications

## Examples

### Resource Group Initialization

```yaml
id: init-nextjs-fullstack-aws
up:
  - type: initResourceGroup
    options:
      args:
        name: nextjs-fullstack-aws
        type: fullstack-aws
        framework: nextjs
        inputs:
          port: 3000
          networkType: public
          includeStorage: public
          includeDb: true
down:
  - type: removeResourceGroup
    options:
      args:
        name: nextjs-fullstack-aws
```

Migrations support a declarative API that enables developers to use YAML to orchestrate and execute infrastructure changes, including Pulumi/Terraform changes and code modifications. They can be added gradually from composable, predefined templates for popular development tools like Laravel and NextJS.
