SQLAlchemy + Postgres Cheatsheet 10 — Upsert, RETURNING, and COPY
Cheatsheet: ON CONFLICT DO UPDATE / DO NOTHING, RETURNING, bulk insert via execute(insert(), list), asyncpg COPY.
Cheatsheet: ON CONFLICT DO UPDATE / DO NOTHING, RETURNING, bulk insert via execute(insert(), list), asyncpg COPY.
Cheatsheet: PgBouncer, read replica routing, OTEL instrumentation, multi-tenancy (RLS), DR / failover.
Streaming replication, read replica routing, failover handling in SQLAlchemy, and using pgvector for embeddings.
Schema migrations: Alembic integration, autogenerate, manual edits, branching, online schema changes, deploy patterns.
Cheatsheet: declarative partitioning, partition creation, query pruning, pg_partman automation.
Cheatsheet: engine events (connect/checkout/before_cursor_execute), session events (before_commit), mapper hooks (before_insert/update/delete), attribute events.
Testing SQLAlchemy: real DBs via testcontainers, per-test transactions, factory_boy, async fixtures, and CI patterns.
Cheatsheet: vector column, HNSW vs IVFFlat, cosine / L2 / inner-product distance, RAG hybrid filter.
Cheatsheet: per-tenant schemas, search_path, multi-schema Alembic env, onboarding.
Cheatsheet: repository classes, unit-of-work, generic base repo, service-layer separation.