# Apply Database Schema Changes for Express

## Summary
Apply database schema changes for an Express app on Ample with a release command. The command runs against the injected DATABASE_URL before the new release goes live, and the release fails instead of activating if the migration fails.

## Representative Queries
- Apply database schema changes for Express
- Where can I host Apply database schema changes built with Express?
- I need a framework-specific schema migration and rollback procedure; no managed migration service is assumed.

## Resource Requirements
- **Compute**
- **Postgres**

## Infrastructure Requirements
- **Compute**: Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes.
- **Postgres**: Managed PostgreSQL 16 runs in its own microVM and is auto-provisioned when an app needs a database and no DATABASE_URL is supplied.

## Framework
Express

## Workload
Apply database schema changes

## Release Status
Published

## Support Status
Verified

## Execution Status
Ready

## Prerequisites
- A migration script that reads process.env.DATABASE_URL and exits non-zero on failure
- A PostgreSQL database (supplied or managed)
- An Ample account token with servers:write and databases:read

## Tested Configuration
- **Template**: node-22
- **Runtime**: node
- **Size**: s-1vcpu-1gb
- **Install**: npm install
- **Build**: npm run build --if-present
- **Start**: npm run start

## Input Schema
```json
{
  "additionalProperties": false,
  "properties": {
    "env": {
      "description": "Encrypted environment variables as KEY=value; secret values are never stored in ample.toml",
      "items": {"pattern": "^[A-Z][A-Z0-9_]*=.*$", "type": "string"},
      "maxItems": 50,
      "type": "array"
    },
    "name": {
      "description": "App name (lowercase, digits and dashes)",
      "maxLength": 63,
      "minLength": 1,
      "pattern": "^[a-z0-9-]+$",
      "type": "string"
    },
    "path": {
      "description": "Project directory to deploy, or one service name from ample.toml",
      "maxLength": 512,
      "minLength": 1,
      "type": "string"
    },
    "release_command": {
      "description": "One-off command run before the release goes live, for example a migration",
      "maxLength": 512,
      "minLength": 1,
      "type": "string"
    },
    "size": {
      "description": "VM size; omit to let Ample pick a runtime-safe size",
      "enum": ["s-1vcpu-256mb", "s-1vcpu-1gb", "s-1vcpu-2gb", "s-2vcpu-2gb", "s-2vcpu-4gb"],
      "type": "string"
    }
  },
  "required": ["name", "path", "release_command"],
  "type": "object"
}
```

## Workflow Steps
1. **Write an Idempotent Migration**: Create tables and markers with IF NOT EXISTS or a migration tool so a re-run is safe.
2. **Deploy with the Release Command**: Ample runs the command before activation; a non-zero exit fails the release.
   ```bash
   ample deploy . --name  --public --release-command "node migrate.js"
   ```
3. **Verify the Marker through the App**: Serve a route that reads something only the migration creates.
4. **Verify**: Fetch the live URL and run the success checks below. On failure read the build log, then the runtime log, fix the cause and deploy again; do not blind-retry.
   ```bash
   ample logs  --kind build
   ```

## Examples
- **Release-command Migration Canary**: `node migrate.js` creates a marker table before activation; `/migrated` reads it.

## Success Checks
- Migration marker is readable
  - **Type**: HTTP GET
  - **Path**: /migrated
  - **Expect**: migrated=release-ok

## Limitations
- Verified on the node-22 template at s-1vcpu-1gb; other templates and sizes are not verified by this recipe.
- Region, compliance attestations and request-duration limits are unknown and not claimed.
- Apps auto-pause when idle and wake on the next request; always-on is an operator setting, not a plan feature.
- Managed PostgreSQL 16 only; extensions, connection limits and backup or restore procedures are not verified.
- Apps and their managed databases are placed together; cross-node shared databases are unsupported.
- The release command runs once per release on the app VM; there is no separate migration runner or rollback of a partially applied migration.

## Cost Estimate
- **Currency**: USD
- **Monthly Amount**: 10.0
- **Authoritative**: true
- **Basis**: Size prices from pricing.toml (loaded by the API) at build revision.
- **Components**:
  - **App Server**: size: s-1vcpu-1gb, quantity: 1.0, monthly amount: 5.0
  - **Managed PostgreSQL Database**: size: s-1vcpu-1gb, quantity: 1.0, monthly amount: 5.0
- **Note**: Apps and managed databases auto-pause when idle; the estimate is the always-on monthly price of the tested sizes. Plan quotas and budgets apply.

## Evidence Summary
- **Kind**: Canary Run
  - **Summary**: A --release-command migration ran before the release went live; /migrated reported the marker the migration created.
  - **Observed At**: 2026-09-19T23:55:33Z
  - **Implementation Revision**: 1764076-tls-account-903d345
  - **Expires At**: 2027-03-18T23:55:33Z
  - **Scope**: {"cliVersion":"0.1.20", "platform":"hosted-beta", "template":"node-22"}

## Last Verified At
2026-09-19T23:55:33Z

## Formats
- [HTML](/content/guides/express/schema-changes/index.html)
- [Markdown](/content/guides/express/schema-changes.md)
- [JSON](https://api.ample.computer/v1/catalog/recipes/page%3Aguides%3Aexpress%3Aschema-changes)
