Skip to content

5. Data Layer Foundations

Welcome to the Data Layer chapter. Up until now, our application has had amnesia. Every time we restart the server, all our data disappears.

In this chapter, we're going to connect our FastAPI application to a real PostgreSQL database:

  1. Database Infrastructure:

    Spinning up a local PostgreSQL instance using Docker.

  2. Object-Relational Mapping (ORM):

    Using SQLModel to define data schemas that serve as both database blueprints and Pydantic validation models.

  3. Database Migrations:

    Setting up Alembic to track and apply changes to our database schema over time.

  4. Seeding Data:

    Writing a script to populate our new database with sample records.

Let's get started by setting up our database container.