django-db-migrator
A lightweight CLI tool to migrate a Django PostgreSQL database between environments or platforms. Perfect for moving data between servers, staging/production, or local/dev environments.
Features
- Reads database credentials from
.envfiles - Dumps PostgreSQL database using
pg_dump - Creates destination PostgreSQL user and database (if needed)
- Restores dump using
pg_restore - Clear logs for every step
- PyPI-installable with a single CLI command
What It Automates (Checklist)
✅ Reads .env Files
- Parses source and destination environments
- Auto-extracts:
DB_NAME,DB_USER,DB_PASSWORD,DB_HOST,DB_PORT - Destination also supports
DB_SUPERUSER,DB_SUPERUSER_PASSWORD
✅ Connects to Source DB
- Tests connection using environment credentials
✅ Dumps Database
- Uses
pg_dumpto export schema and data from source DB
✅ Connects to Destination with Superuser
- Uses
psqlwith destination superuser credentials
✅ Creates User and Database if Missing
- Checks existence of destination DB and user
- Runs
CREATE USER,CREATE DATABASE, andGRANT ALL PRIVILEGESas needed
✅ Restores Dump
- Uses
pg_restoreto import data into destination
✅ Cleans Up
- Deletes temporary dump file after successful migration
✅ Logging
- Logs each step clearly with
INFOandERRORmessages
Installation
pip install django-db-migrator
Usage
django-db-migrate --source-env .env --dest-env .env.prod
.env Format (both source and destination)
DB_NAME=your_db_name
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_HOST=localhost
DB_PORT=5432
# Destination .env only
DB_SUPERUSER=postgres
DB_SUPERUSER_PASSWORD=supersecret
Requirements
- PostgreSQL CLI tools:
pg_dump,pg_restore,psql - Python 3.7+
python-dotenv
Install PostgreSQL tools:
sudo apt install postgresql-client # Linux
brew install postgresql # macOS
Development
git clone https://github.com/MhmdRdbri/Django-db-migrator
cd django-db-migrator
pip install -e .
Run locally:
python -m django_db_migrator.cli --source-env .env --dest-env .env.prod
License
MIT License Copyright (c) [2025] [Mohammad Roudbari]
Metadata
Release files for django-db-migrator 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_db_migrator-0.1.1.tar.gz | 3.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_db_migrator-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.9 kB
Release files / django_db_migrator-0.1.1.tar.gz
| Download URL | django_db_migrator-0.1.1.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a41f96d778fd6f6914af991adcb7f9ce269589306504bd3998ba6fefe1dbba72
|
|
BLAKE2b-256 checksum How to use checksums |
2f68ab187d6ab6c15dad719c1c10cace3e60f998cae62962ab9d49772d0193cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.0
|
Release files / django_db_migrator-0.1.1-py3-none-any.whl
| Download URL | django_db_migrator-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b419720ee333182cb1ca854c51358d6bd0821fac77a99e86bb0d8e069f271b35
|
|
BLAKE2b-256 checksum How to use checksums |
515c91755c4fc649b071719cc78afd7a38a3d1e231369696f07b165abe03a614
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.0
|
Security for django-db-migrator 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.