{"catalogRevision":"cat_f13ab9a494120b5e","recipeId":"page:guides:fastapi:schema-changes","recipeRevision":"r1","canonicalPath":"/guides/fastapi/schema-changes","label":"Apply database schema changes for FastAPI","family":"Framework operation","summary":"Apply database schema changes for a FastAPI app on Ample with a release command. `python3 migrate.py` runs against the injected DATABASE_URL before the new release goes live, and the release fails instead of activating if the migration fails.","representativeQueries":["Apply database schema changes for FastAPI","Where can I host Apply database schema changes built with FastAPI?","I need a framework-specific schema migration and rollback procedure; no managed migration service is assumed."],"breadcrumbIds":["discovery","stack","stack:frameworks","stack:framework-fastapi","page:guides:fastapi:schema-changes"],"breadcrumbs":[{"id":"discovery","label":"Agent hosting discovery","canonicalPath":"/discover/discovery","kind":"root"},{"id":"stack","label":"Frameworks and execution targets","canonicalPath":"/discover/stack","kind":"facet"},{"id":"stack:frameworks","label":"Frameworks","canonicalPath":"/discover/stack/frameworks","kind":"group"},{"id":"stack:framework-fastapi","label":"FastAPI","canonicalPath":"/discover/stack/framework-fastapi","kind":"atom"},{"id":"page:guides:fastapi:schema-changes","label":"Apply database schema changes for FastAPI","canonicalPath":"/guides/fastapi/schema-changes","kind":"recipe"}],"parentIds":["stack:framework-fastapi","intent:configure-deployment","pattern:transactional-workflows"],"parents":[{"id":"stack:framework-fastapi","label":"FastAPI","canonicalPath":"/discover/stack/framework-fastapi","kind":"atom"},{"id":"intent:configure-deployment","label":"Configure deployment","canonicalPath":"/discover/intent/configure-deployment","kind":"atom"},{"id":"pattern:transactional-workflows","label":"Transactional workflows","canonicalPath":"/discover/pattern/transactional-workflows","kind":"atom"}],"resourceRequirements":["primitive:compute","primitive:postgres"],"infrastructureRequirements":[{"primitiveId":"primitive:compute","label":"Compute","canonicalPath":"/discover/primitive/compute","status":"verified","summary":"Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes."},{"primitiveId":"primitive:postgres","label":"Postgres","canonicalPath":"/discover/primitive/postgres","status":"verified","summary":"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":"FastAPI","workload":"Apply database schema changes","releaseStatus":"published","supportStatus":"verified","executionStatus":"ready","docsOnly":false,"prerequisites":["A migration command that reads DATABASE_URL and exits non-zero on failure","A PostgreSQL database (supplied or managed)","An Ample account token with servers:write and databases:read"],"testedConfiguration":{"template":"python-3.12","runtime":"python","size":"s-1vcpu-1gb","install":"python3 -m pip install --target .ample/python -r requirements.txt","start":"PYTHONPATH=.ample/python:${PYTHONPATH:-} python3 run.py"},"inputSchema":{"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"},"start":{"description":"Start command override when detection cannot infer it (Python apps pass one explicitly)","maxLength":512,"type":"string"}},"required":["name","path","release_command","start"],"type":"object"},"outputSchema":null,"workflowSteps":[{"title":"Write an idempotent migration","body":"Create tables and markers with IF NOT EXISTS or a migration framework so a re-run is safe."},{"title":"Deploy with the release command","body":"Ample runs the command before activation; a non-zero exit fails the release.","command":"ample deploy . --name <app-name> --public --start \"python3 run.py\" --release-command \"python3 migrate.py\""},{"title":"Verify the marker through the app","body":"Serve a route (/migrated) that reads something only the migration creates."},{"title":"Verify","body":"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.","command":"ample logs <deployment_id> --kind build"}],"examples":[{"title":"FastAPI release-command canary","description":"python3 migrate.py runs before activation against the auto-provisioned managed database.","sourceRef":"tests/deploy-canaries/fastapi-postgres-api"}],"successChecks":[{"description":"migration marker is readable","kind":"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."],"costEstimate":{"currency":"USD","monthlyAmount":10.0,"authoritative":true,"basis":"size prices from pricing.toml (loaded by the API) at build revision 7cf090725a6f16dd91af7d28356fe72c1b404d6e","components":[{"name":"app server","size":"s-1vcpu-1gb","quantity":1.0,"monthlyAmount":5.0},{"name":"managed PostgreSQL database","size":"s-1vcpu-1gb","quantity":1.0,"monthlyAmount":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."},"evidenceSummary":[{"kind":"canary_run","summary":"The same FastAPI app deployed with --release-command python3 migrate.py against its auto-provisioned managed database; /migrated reported the marker the migration created.","observedAt":"2026-09-20T00:46:07Z","implementationRevision":"4967a99ad18b66a11b8b4c86cb06f29c8327f5df (CLI e3181f5)","expiresAt":"2027-03-19T00:46:07Z","scope":{"cliVersion":"0.1.20","platform":"hosted","template":"node-22"}}],"lastVerifiedAt":"2026-09-20T00:46:07Z","mcpBinding":{"registryRef":"mcp:ample_deploy","toolName":"ample_deploy","schemaHash":"876465fce906da0c224d62961d3343064108ebe30af80cf1b87094974e948853","observedAt":"2026-09-20T01:55:48.667900+00:00","implementationRevision":"199ff1dfd526","requiredScopes":["servers:write","databases:read"],"bindingState":"current"},"unknowns":["region availability is unknown until a verified region fact is recorded","compliance attestations are unknown; none are claimed"],"formats":{"html":"https://ample.computer/guides/fastapi/schema-changes","markdown":"https://ample.computer/guides/fastapi/schema-changes.md","json":"https://api.ample.computer/v1/catalog/recipes/page%3Aguides%3Afastapi%3Aschema-changes"},"nextActions":[{"actionId":"browse-catalog","label":"Browse the catalog index","operationId":"catalog_index","method":"GET","relativePath":"/v1/catalog","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"search-recipes","label":"Search published recipes by intent, stack and constraints","operationId":"search_recipes","method":"POST","relativePath":"/v1/catalog/search","origin":"api","parameters":{"body":{"limit":5,"query":"Apply database schema changes for FastAPI"}},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"plan:page:guides:fastapi:schema-changes","label":"Prepare a side-effect-free deployment plan for an authorized project","operationId":"plan_deployment","method":"POST","relativePath":"/v1/catalog/plan","origin":"api","parameters":{"body":{"inputs":{},"projectId":"<workspace or server id you own>","recipeId":"page:guides:fastapi:schema-changes","recipeRevision":"r1"}},"requiresAuthentication":true,"requiresApproval":false},{"actionId":"auth-setup","label":"Read the existing agent authentication setup","operationId":"existing_auth_setup","method":"GET","relativePath":"/mcp/setup","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:stack:framework-fastapi","label":"Browse FastAPI","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/stack%3Aframework-fastapi","origin":"api","parameters":{"nodeId":"stack:framework-fastapi"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:intent:configure-deployment","label":"Browse Configure deployment","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/intent%3Aconfigure-deployment","origin":"api","parameters":{"nodeId":"intent:configure-deployment"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:pattern:transactional-workflows","label":"Browse Transactional workflows","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/pattern%3Atransactional-workflows","origin":"api","parameters":{"nodeId":"pattern:transactional-workflows"},"requiresAuthentication":false,"requiresApproval":false}]}