Let's talk Databases in Python: SQLAlchemy and Alembic
summary
Shows concrete use of SQLAlchemy and Alembic to model tables, run multi-step migrations, and deploy schema and data changes (adds an organization table, adds organization_id to groups, then assigns a default org to existing rows). Demonstrates connection pools with pool_size/overflow and a 60s TCP keepalive, an indexed shadow‑ban field and a partial index, exposes an N+1 query cost (1 + number_of_members) and the join_load fix, and warns against importing evolving models into migrations.
AI-written summary · about
chapters (33)
- 0:00Intro
- 1:20What's an ORM?
- 1:48Available Python ORMS
- 2:43User Model
- 4:12Common Base
- 4:52Validation
- 6:17Relationships
- 7:11Unique Constraints
- 7:45Multi Column Indexes
- 8:42Partial Indexing
- 10:14Functional/Expression Indexing
- 12:02Connecting to the DB
- 12:41Inserting Data
- 13:06Using a Session Context Manager
- 13:56Session Scoping
- 14:26Establishing a DB Connection
- 15:04Connection Pools
- 20:15Creating the DB
- 20:53Database Migrations
- 22:35Database Migration Libraries
- 22:57Configuration
- 23:20Creating a Migration
- 26:13Run the migration
- 26:29Downgrade the migration
- 26:39Modify an Existing Table
- 27:23Modify Data
- 30:00Problems in the Wild: Lazy Loading
- 30:12Lazy Loading: What is it?
- 30:56Lazy Loading: Why is it a problem?
- 31:37Lazy Loading: Use Eager Load Instead!
- 32:04Problems in the Wild: Unexpected Query Generation
- 33:01Review
- 33:19Questions
related talks
01h 28mSQLAlchemy and You - Making SQL the Best Thing Since Sliced Bread
56mSane schema migrations with Alembic and Postgres
28mThe Ultimate Python Database Toolkit: SQLAlchemy
31mBeyond Alembic and Django Migrations
32mNo More Raw SQL: SQLAlchemy & ORMs
29mDatabase Sorcery 101 Ditch the Ancient SQL Scrolls for SQLModel
01h 44mTUTORIAL: SQLAlchemy 2.0
30mThe magic of SQLAlchemy
