This is an example of using pgtemp with Python, SQLAlchemy, and Alembic. # Why use pgtemp for this You could do this with a regular "dev cluster" running locally permanently, but using pgtemp here makes it so that your local setup is always the same as CI, and you don't have to worry about getting your local db in a bad state. You can also load a dump from `pg_dump`, start pgtemp with a database name like `my_template`, and then do `CREATE DATABASE TEMPLATE my_template` in the `get_db_and_run_migrations` function to automatically get testing data pre-loaded. # How to set up ## Create venv and install deps `make install` ## Alembic setup - already run and in the repo ``` venv/bin/alembic init alembic venv/bin/alembic revision -m "create tasks table" # edit migration to create tables vim alembic/versions/745aa71c5729_create_tasks_table.py # edit env.py as per # to use an existing connection to run migrations, for running pgtemp in normal mode vim alembic/env.py ``` ## Running tests ``` # In a separate shell cargo run --features cli -- --single postgresql://postgres@localhost:11432 # single mode cargo run --features cli -- postgresql://postgres@localhost:22432 # normal mode ``` Then run `make test` In CI, both the servers are started automatically.