Skip to main content

Smart Django migration manager.

Project description

djmigrator

djmigrator is a Django management extension that provides smart migration handling by deeply comparing Django models with the actual database schema. It automates missing migrations generation and applies them safely, ensuring that the models and database remain consistent without manually tracking changes.


Introduction

In large Django projects, inconsistencies between models and the actual database often happen due to missing migrations, manual database edits, or legacy systems. Traditional Django commands such as makemigrations and migrate assume perfect sync between models and the database.

djmigrator solves this by:

  • Performing deep inspections of your actual database schema.
  • Comparing models and fields directly against database tables and columns.
  • Identifying missing tables or missing columns.
  • Generating and applying only necessary migrations.
  • Using smart application strategies to avoid common errors like "table already exists" or "column already exists".

Key Features

  • Automatic detection of missing tables or missing columns based on model comparison.
  • Safe skipping of already existing tables and fields during migration.
  • Automatic generation of migration files only when necessary.
  • Application of migrations with --fake-initial to synchronize existing tables.
  • Clear reporting of discrepancies between models and database.
  • Minimal downtime and human intervention required for database synchronization.

How It Works

  1. The smart_makemigrations command inspects all Django models and their respective tables in the connected database.
  2. It identifies:
    • Tables missing in the database.
    • Columns missing inside an existing table.
    • Extra columns existing in the database but not defined in the Django models (reported but not modified).
  3. If discrepancies are found:
    • makemigrations is automatically triggered to generate new migration files.
    • migrate --fake-initial is applied to safely sync without duplicating existing tables.
  4. If no discrepancies are found, the command reports a clean synchronization status.

Installation and Setup

To install and set up djmigrator, follow these steps:

1. Install the Package

pip install djmigrator

2. Add to Django Settings

Add djmigrator to your Django project's INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    ...
    'djmigrator',
]

Why is INSTALLED_APPS required?

Django discovers management commands by scanning the management/commands/ directories within each application listed in INSTALLED_APPS. This is Django's standard mechanism for command discovery. While we've added setuptools entry points for potential future compatibility, Django's current implementation requires apps to be in INSTALLED_APPS for their management commands to be discovered.

3. Use the Migration Command

python manage.py smart_makemigrations

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djmigrator-1.0.9.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djmigrator-1.0.9-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file djmigrator-1.0.9.tar.gz.

File metadata

  • Download URL: djmigrator-1.0.9.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for djmigrator-1.0.9.tar.gz
Algorithm Hash digest
SHA256 85c20b584024f1a57c027fad7cf4de6357dd4575aa7357b6c854fa5157a2592f
MD5 f3f2bccf3d9d540e74a66baf0470561e
BLAKE2b-256 b071a1e1b52d401afc822e9c2af83d10ce9153961deb3855ccbd6a4bce85cbf8

See more details on using hashes here.

File details

Details for the file djmigrator-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: djmigrator-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.5

File hashes

Hashes for djmigrator-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 1582a1f2770f64a688126305a01ee6a1cd453bcd6bca18ed4d376560c5cdb8b7
MD5 05bf0bedfe4d0d8d28a1b628e7d47390
BLAKE2b-256 ec6342d777a859e88b1bc6c89757cbacdb726dd9767dd180b4ddd84672e3f4cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page