# Apply Pending Migration

`POST /migrations/pending/{pendingId}/apply` · Core · Storage & Schema

Approves and executes a queued pending migration, transitioning it from `queued` to `applied` and running its DDL atomically against the project's schema.

Returns `data: { pendingId, applied[], skipped[] }` where `applied` and `skipped` list the migration slugs disposed by the underlying apply run. Attempting this on a row that is not in `queued` state returns `K9O_INVALID_FIELD_VALUE` (400).

Emits a `migration.applied_from_pending` audit event on successful DDL execution. Requires `PROJECT_ADMIN`.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `pendingId` | path | yes | The pending migration's id (`pmig_...`). Example: `"pmig_4Fh2kQ9xLm7a"`. |
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The pending migration that was applied, and what ran. |
| `data.pendingId` | string | yes | The pending migration's id (`pmig_...`). |
| `data.applied` | array of object | yes | The migrations applied by this call, in the order they ran. |
| `data.applied.[]version` | integer | yes | The migration's version, an integer from 1 to 2147483647. Versions apply in ascending order. |
| `data.applied.[]slug` | string | yes | The migration's slug, as given when it was submitted. |
| `data.applied.[]checksum` | string | yes | SHA-256 (hex) of the migration's canonical JSON (`version`, `slug`, `up`, `down`, `policy`). Re-applying a version with a different checksum is refused. |
| `data.skipped` | array of object | yes | The migrations skipped because they were already applied with the same checksum. |
| `data.skipped.[]version` | integer | yes | The migration's version, an integer from 1 to 2147483647. Versions apply in ascending order. |
| `data.skipped.[]slug` | string | yes | The migration's slug, as given when it was submitted. |
| `data.skipped.[]reason` | enum ("already_applied") | yes | Why the migration was skipped. `already_applied`: this version is already in the project with the same checksum. |
| `meta` | object | yes | Request metadata: cost, timing and correlation ids. |


## Errors

| HTTP | Code | When |
|---|---|---|
| 403 | `K9O_ACCESS_DENIED` | Applying a pending migration requires the PROJECT_ADMIN role, or the caller is not a project member. |
| 403 | `K9O_RBAC_DENY` | A session is required to apply a pending migration: a personal access token alone is refused with `context.reason` `session_required`, and a service, workload or extension token with `human_only`. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/migrations/pending/<pendingId>/apply' \
  -H 'Authorization: Bearer $K9O_TOKEN'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/migrations/pending/<pendingId>/apply', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`
  },
});
const { data, meta } = await res.json();
```

### k9o CLI

```bash
k9o migration apply-pending <pendingId>
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.migrations.applyPending('pmig_4Fh2kQ9xLm7a')
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.migrations.apply_pending("pmig_4Fh2kQ9xLm7a")
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Migrations.ApplyPending(ctx, "pmig_4Fh2kQ9xLm7a")
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.migrations.apply_pending("pmig_4Fh2kQ9xLm7a").await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.migrations().applyPending("pmig_4Fh2kQ9xLm7a")
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Migrations.ApplyPendingAsync("pmig_4Fh2kQ9xLm7a")
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.migrations.apply_pending("pmig_4Fh2kQ9xLm7a")
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->migrations->apply_pending('pmig_4Fh2kQ9xLm7a')
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/apply-pending-migration
