MySQL
Edit on GitHubReference for the python-fastapi-mysql deployment target
Last updated:
This page documents only how the python-fastapi-mysql target differs from
python-fastapi-postgres. Everything not listed here (file
tree, naming conventions, HTTP contract, OpenAPI, the FastAPI app/Docker app stage, extension
points, limitations) is identical; read the PostgreSQL page for
the full reference.
The database axis is a pluggable Dialect strategy
(modules/codegen/src/main/scala/specrest/codegen/migration/Dialect.scala); it decides the
SQLAlchemy column type, trigger shape, partial-index handling, and the connection / docker-compose
wiring (DialectView). Selecting MySQL is one flag: no emitter or template changes.
sbt "cli/run compile --framework fastapi --db mysql --ignore-verify --out /tmp/out fixtures/spec/url_shortener.spec"Deltas from PostgreSQL
| Aspect | PostgreSQL | MySQL |
|---|---|---|
| Async driver | asyncpg | aiomysql |
| URL scheme | postgresql+asyncpg:// | mysql+aiomysql:// |
| Database service | postgres in compose | mysql:8.4 service in compose |
| Unbounded strings | TEXT | VARCHAR(255) |
- The emitted
docker-compose.ymlprovisions amysql:8.4database service (replacing the Postgres one); themigrationsandappservices wait on its healthcheck. The app container is otherwise unchanged. - Unbounded string fields map to
VARCHAR(255)rather than PostgresTEXT, since MySQL cannot index unbounded text without a key length. - Remaining Postgres-specific types are mapped to their MySQL equivalents by the
Dialect; the emitter is canonical. - Test generation is unchanged. The default-on conformance / property / stateful suite
(opt out with
--no-tests) emits here exactly as for PostgreSQL: the suite is dialect-invariant (black-box HTTP, ORM-based admin reset) and is byte-identical across every fastapi dialect.
CI gate
.github/workflows/python-build.yml runs the mysql matrix leg: it emits the project
(test suite included by default), runs uv sync --all-extras, and performs an Alembic
upgrade head → downgrade base → upgrade head round-trip against a real mysql:8.4 service,
proving the test-suite-included project generates, installs, and migrates on MySQL. The emitted suite is
dialect-invariant: byte-identical across every fastapi dialect, asserted deterministically by
TestEmitTest, so MySQL gets exactly the suite PostgreSQL does. (End-to-end execution of the
generated app/suite is exercised by the nightly mutation job; it needs --with-synthesis to fill
non-CRUD bodies and is independent of the database axis.)
If this page and the emitted output disagree, the emitter wins, file an issue or PR to correct the doc.