Skip to main content

forge-db

Use Postgres for local Django development via Docker.

Installation

First, install forge-db from PyPI:

pip install forge-db

Now you will have access to the db command:

forge db

You will need to have a DATABASE_URL environment variable, which is where the database name, username, password, and port are parsed from:

# .env
DATABASE_URL=postgres://postgres:postgres@localhost:54321/postgres

You can use a POSTGRES_VERSION environment variable to override the default Postgres version (13):

# .env
POSTGRES_VERSION=12

In most cases you will want to use dj_database_url in your settings.py to easily set the same settings (works in most deployment environments too):

# settings.py
import dj_databse_url

DATABASES = {
    "default": dj_database_url.parse(
        environ["DATABASE_URL"], conn_max_age=environ.get("DATABASE_CONN_MAX_AGE", 600)
    )
}

You will also notice a new .forge directory in your project root. This contains your local database files and should be added to .gitignore.

Usage

If you use forge-work, then most of the time you won't need to interact with forge-db directly. But it has a few commands that come in handy.

  • forge db start - starts a new database container and runs it in the background (use --logs to foreground it or connect to the logs)
  • forge db stop - stop the database container
  • forge db reset - drops and creates a new database
  • forge db pull - pulls the latest database backup from Heroku and imports it into the local database

In the end, the database container is like any other Docker container. You can use the standard Docker commands and tools to interact with it when needed.

Snapshots

The forge db snapshot command manages local copies of your development database. This is useful for testing migrations or switching between git branches that have different db states.

Snapshots are simply additional Postgres databases that are created and dropped as needed (createdb {snapshot_name} -T postgres).

Metadata

Release files for forge-db 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for forge-db 1.2.0
File Size Uploaded
forge_db-1.2.0.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for forge-db 1.2.0
File Interpreter ABI Platform
forge_db-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.8 kB

Release files / forge_db-1.2.0.tar.gz

Download URL forge_db-1.2.0.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c10683a3878b0449ef0070049da6e2954a31fa5f590bda915fa7374e5deba4b0
BLAKE2b-256 checksum
How to use checksums
149be75123caf737666f4adfd20e2c90da820f8049e89cc99ce929472111c60a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.0 CPython/3.11.2 Linux/5.15.0-1033-azure

Release files / forge_db-1.2.0-py3-none-any.whl

Download URL forge_db-1.2.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
281a369fea8874687a0f6504864237a4223c9777a32f05af5d16ff9dc8f44a77
BLAKE2b-256 checksum
How to use checksums
2a99c965bfafb3dd2b9a61c64113f94485f52741b7bc40a1297edecb4d3c0d4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.0 CPython/3.11.2 Linux/5.15.0-1033-azure

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page