---
title: "Apply migrations to the database of an app"
method: POST
path: "/apps/{id}/migrations"
tags: ["Apps"]
---

# Apply migrations to the database of an app

`POST /apps/{id}/migrations`

## Request

- Base URL: `https://api.hypamoon.com/api/v1`
- URL: `https://api.hypamoon.com/api/v1/apps/{id}/migrations`
- Auth: one of:
  - HTTP bearer
  - OAuth 2 (authorization code, authorization URL `https://app.hypamoon.com/oauth/authorize`, token URL `https://api.hypamoon.com/oauth/token`, scopes: `sites:write`)

Runs new SQL migrations on the app's own database (env.DB), in order, each as one batch: all or nothing. A migration that was already applied with the same content is skipped; a new name must sort after the last applied one. Only DDL and DML on that database: CREATE TABLE, CREATE INDEX, CREATE VIEW, ALTER, DROP, INSERT, UPDATE, DELETE. No ATTACH, PRAGMA, VACUUM, triggers or transactions. The app needs database: true.

## Path parameters

- `id` string, uuid, required

## Request body

- object
  - `migrations` object[], required: New migrations in order. Ones already applied (same name and content) are skipped.
    - `name` string, required: A file name that sorts in order, like 0001_init.sql.
    - `sql` string, required: SQLite DDL and DML: CREATE TABLE, CREATE INDEX, ALTER TABLE, INSERT, UPDATE, DELETE. No ATTACH, PRAGMA, VACUUM, triggers or transactions.

## Response `200`

Applied (or already applied).

- object
  - `applied` string[], required: Applied now.
  - `skipped` string[], required: Already applied before.
  - `data` object[], required: Every migration of this app, oldest first.
    - `name` string, required
    - `sha256` string, required
    - `statements` integer, required
    - `applied_at` string, required
  - `database_bytes` integer, required

## Other responses

- `400`: Bad Request: invalid_json.
- `401`: Unauthorized: unauthorized, missing_api_key, invalid_api_key, api_key_revoked, project_deleted.
- `402`: Payment Required: plan_limit_reached.
- `403`: Forbidden: project_not_enabled, key_mode_mismatch, missing_scope, verification_required, site_offline.
- `404`: Not Found: not_found.
- `409`: Conflict: conflict, plan_limit_reached.
- `422`: Unprocessable Content: validation_failed, migration_failed.
- `429`: Too Many Requests: rate_limited.
- `500`: Internal Server Error: internal_error.
- `503`: Service Unavailable: service_unavailable.

---

[API](https://skmtc.dev/hypamoon/apis/hypamoon-api.md) · [All operations](https://skmtc.dev/hypamoon/apis/hypamoon-api/llms.txt) · [OpenAPI document](https://skmtc.dev/hypamoon/apis/hypamoon-api/revisions/9f0b90004c06?raw)
