Skip to main content

Django Auto Rebase

What is this?

This is a command-line tool that allows you to rebase a conflicting Django migration on top of the other Django migration renaming (and renumbering) the migration filename and also editing the dependencies attribute on the Migration class within the file.

Installation

$ pip install django-auto-rebase

Usage

$ dar [app-name] [migration-file-to-be-rebased]

Requirements

  • Python 3.7 (for now. file an issue if you need an earlier version supported)
  • Django 2.2 (earlier versions will likely work, but it's untested for now.

Limitations

  • Only works on leaf nodes that have migration conflicts.
  • Only works on leaf nodes within the same app.

FAQ

Is this a Django Command?

No, although this package is tightly coupled to Django, it is NOT a Django app that you need to add to your INSTALLED_APPS or call through a manage.py.

How does it find the root Django path?

The first thing the script does after parsing your arguments is it walks up the current working directory until it finds the manage.py file that all if not most Django applications have. The folder that holds the first manage.py directory is appended to sys.path.

Why do you even need this?

Well, you don't really need it, but I find it helpful.

Suppose the migration tree looks like this:

0001_xxx <-- 0002_xxx <-- 0003_xxx

Then two developers, working in separate branches, generate their own 0004_xxx migration. Once the first developer gets their code merged to master, the second developer's migration tree is immediately stale/in conflict because its 0004_xxx will still be pointing at 0003_xxx as a dependency. You may find yourself getting this error message:

Conflicting migrations detected; multiple leaf nodes in the migration graph:
(0004_xxx, 0004_yyy in my_app_name).
To fix them run 'python manage.py makemigrations --merge'

As the message suggests, you could run makemigrations --merge, which generates a new leaf node 0005_xxx and specifies the two 0004_xxx migrations as a dependencies. This works in small doses, but I'm not a huge fan. (see below)

What's wrong with makemigrations --merge?

The magic numbers of each migration starts meaning less and less.

Strictly speaking, they really do mean nothing - Django doesn't care at all about the number: A 0004_xxx migration could depend on a migration named 9999_xxx, which depends on 1234_xxx.

Practically speaking, I do find value in seeing the dependency order of the migration tree follow their actual numbers. This tool helps rebase two conflicting migrations with ease.

Author

Christopher Sabater Cordero

Release files for django-auto-rebase 1.0.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 django-auto-rebase 1.0.0
File Size Uploaded
django-auto-rebase-1.0.0.tar.gz 16.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-auto-rebase 1.0.0
File Interpreter ABI Platform
django_auto_rebase-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.1 kB

Release files / django-auto-rebase-1.0.0.tar.gz

Download URL django-auto-rebase-1.0.0.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7edb82d799b102b0d17cf63923c09c99896f8c4f3350e7e792394f5361188d41
BLAKE2b-256 checksum
How to use checksums
4b3e3301f6d0c8cca2ff8340ed10161b323a8a3e1248c84773ae22951f984b72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.17 CPython/3.7.3 Darwin/18.7.0

Release files / django_auto_rebase-1.0.0-py3-none-any.whl

Download URL django_auto_rebase-1.0.0-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e6ca73ea7ce0246692eecbfb759bb45296c3f4c98f5903dd75d9899869b38a4
BLAKE2b-256 checksum
How to use checksums
a6893e1d248f4e0882ae032131068319dd92f2799b9e42c23c54908fc1f8f348
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.17 CPython/3.7.3 Darwin/18.7.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

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