Easily migrate your Django PostgreSQL database between platforms
Project description
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]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_db_migrator-0.1.1.tar.gz.
File metadata
- Download URL: django_db_migrator-0.1.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a41f96d778fd6f6914af991adcb7f9ce269589306504bd3998ba6fefe1dbba72
|
|
| MD5 |
229e2b03424dcd5995745c8ddc476091
|
|
| BLAKE2b-256 |
2f68ab187d6ab6c15dad719c1c10cace3e60f998cae62962ab9d49772d0193cc
|
File details
Details for the file django_db_migrator-0.1.1-py3-none-any.whl.
File metadata
- Download URL: django_db_migrator-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b419720ee333182cb1ca854c51358d6bd0821fac77a99e86bb0d8e069f271b35
|
|
| MD5 |
b02a976e755d984c7f2f6625746d546e
|
|
| BLAKE2b-256 |
515c91755c4fc649b071719cc78afd7a38a3d1e231369696f07b165abe03a614
|