DEV Community

FastAPI in Prod: Handling DB migrations, auth, and more

FastAPI is a modern Python framework known for its speed, developer-friendly features, and automatic OpenAPI schema generation. This post creates a full example backend using FastAPI, dbmate, PugSQL, PropelAuth, Pydantic, and nanoid. The example backend is a multi-tenant "bookmark aggregator" that allows users to bookmark URLs and share them with their team. The database is set up using dbmate, which offers a simple approach to managing database migrations. PugSQL is used to interact with the database, allowing for plain SQL in separate files. PropelAuth is used for out-of-the-box B2B authentication, handling multi-tenant org checks and user roles. Pydantic is used for data validation, ensuring incoming data is valid. nanoid is used to generate short, unique IDs. The backend is set up using FastAPI, with routes for creating and retrieving bookmarks, and PropelAuth is used to add authentication and multi-tenancy. Finally, the database schema is updated to include user and organization IDs, and the queries are updated to include these fields.
favicon
dev.to
dev.to
Create attached notes ...