Skip to content

postgres ​

PostgreSQL driver, DATABASE_URL configuration, database management recipes, and a Docker Compose service.


When to use it ​

Choose postgres when your project needs:

  • Async PostgreSQL access via asyncpg
  • A DATABASE_URL environment variable for connection configuration
  • A PostgreSQL container in Docker Compose (requires docker addon)
  • Database creation and reset scripts

What it adds ​

Files ​

FilePurpose
my_project/scripts/wait_db.pyPolls PostgreSQL until ready (used by justfile)

Code injections ​

PointTargetWhat it adds
settings_fieldssettings.pydatabase_url: str = "postgresql+asyncpg://..."

Environment variables ​

KeyDefault
DATABASE_URLpostgresql+asyncpg://postgres:postgres@localhost:5432/my_project

Compose services ​

When the docker addon is also installed, the following service is added to compose.yml:

ServiceImagePurpose
dbpostgres:16PostgreSQL with persistent volume (./.pgdata)

Dependencies ​

PackagePurpose
asyncpgAsync PostgreSQL driver
python-dotenv.env file loading

Justfile recipes ​

RecipeCommand
just wait-dbuv run python scripts/wait_db.py
just db-createStart postgres, create dev/test databases, run migrations
just db-resetDrop and recreate both databases

NOTE

The db-create and db-reset recipes only start the PostgreSQL container when the docker addon is installed.


Usage ​

With the docker addon:

bash
cd my-project
just db-create

Without Docker, set DATABASE_URL in .env to point at your own PostgreSQL instance.

Released under the MIT License.