06.02
Models, sessions, and Alembic migrations
skillmaxingPython with AIModels, sessions, and Alembic migrations
Visual lesson
Models, sessions, and Alembic migrations
Lessons · 1,007 words
A schema changes more often than the code that reads it stays still. Adding a customers table, a foreign key from tickets, a priority column next month: each change has to reach every database the app runs against, in order, exactly once. Alembic is the tool that makes a schema change a file you can review, run, and roll back, and the async template it ships with fits the engine from the last lesson without adaptation.
Before migrations, though, two smaller things need to be right: how models relate to each other, and how a session gets into a request handler and out again.
Pro
Continue reading
Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.
Unlock full access to
Python with AIAI researchComplete system design
30% off with LAUNCH30ends in 7h 40m