Treat each request as a unit of work: commit once when the operation succeeds and roll back on errors (the session dependency can wrap this), keep transactions short, and make multi-step operations atomic.
Use a migration tool such as Alembic to version schema changes, generate and review migration scripts, run them in CI and deployment, and never rely on create_all in production.
Loading…