Skip to main content

Python library for Django migration conflict resolution during git rebases

Project description

rebase-migrations

A Python library for Django migration conflict resolution during git rebases. Automatically renumbers Django migration files to resolve conflicts when rebasing feature branches.

The Problem

When rebasing Django feature branches, you often encounter migration number conflicts:

# Main branch has:
migrations/0010_main_change.py
migrations/0011_main_change.py
migrations/0012_latest_feature.py

# Your feature branch has:
migrations/0010_your_feature.py     ← Conflict!
migrations/0011_another_change.py   ← Conflict!

This library automatically detects and renumbers conflicting migrations during rebase.

Installation

pip install rebase-migrations

Usage

Basic Usage

import rebase_migrations

# Preview changes (dry run)
rebase_migrations.dry_run('/path/to/django/project')

# Apply changes
rebase_migrations.execute('/path/to/django/project')

Path Handling

The library supports various path formats:

# Absolute paths
rebase_migrations.execute('/home/user/my-django-project')

# Relative paths
rebase_migrations.execute('.')  # Current directory
rebase_migrations.execute('../my-project')

# Tilde expansion
rebase_migrations.execute('~/my-django-project')

Parameters

Both functions accept the same parameters:

  • path (str): Path to the Django project directory
  • all_dirs (bool, optional): If True, scan all directories for migrations. Default: False
    • When False: Skips common directories like node_modules, venv, .git, etc. for better performance
    • When True: Comprehensive scan of all directories (slower but finds migrations in unusual locations)

How It Works

  1. Discovers migrations: Finds Django migration files in your project
  2. Detects conflicts: Identifies migration number conflicts from git rebase
  3. Renumbers safely: Assigns new sequential numbers to resolve conflicts
  4. Updates dependencies: Modifies migration dependencies to maintain integrity
  5. Updates tracking files: Updates max_migration.txt files for django-linear-migrations

Requirements

  • Python 3.8+
  • Django project with migration files following naming convention (NNNN_name.py)
  • Git repository
  • django-linear-migrations package installed and configured

The library automatically updates max_migration.txt files that django-linear-migrations uses to track the latest migration in each app.

Features

  • 🔍 Automatic Detection: Finds migration conflicts during rebase
  • 🔄 Smart Renumbering: Renumbers migrations to resolve conflicts
  • 🔗 Dependency Updates: Updates migration dependencies automatically
  • 📄 File Updates: Updates max_migration.txt tracking files
  • 🧪 Dry Run Mode: Preview changes before applying them
  • 🚀 Fast Performance: Skips irrelevant directories by default
  • 🛠️ Path Flexibility: Supports relative paths, tilde expansion, and absolute paths

CLI Alternative

If you prefer command-line usage, a standalone CLI binary is also available. See the main repository for installation instructions.

License

MIT License - see LICENSE for details.

Contributing

Contributions welcome! Please see the main repository for contributing guidelines.

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

rebase_migrations-0.3.0.tar.gz (41.9 kB view details)

Uploaded Source

Built Distribution

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

rebase_migrations-0.3.0-cp38-abi3-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file rebase_migrations-0.3.0.tar.gz.

File metadata

  • Download URL: rebase_migrations-0.3.0.tar.gz
  • Upload date:
  • Size: 41.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.9.4

File hashes

Hashes for rebase_migrations-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b948f8241c3701a85568ede08f43d623441dba1286ea154baf4bafecc6f95f42
MD5 7567f502d0ac326f56f25e930337f685
BLAKE2b-256 94630711df42085d5809adf9f8c8b469a72ca6c377e5ec36b1906ad3eda5066b

See more details on using hashes here.

File details

Details for the file rebase_migrations-0.3.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rebase_migrations-0.3.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 299fc32c40544e28b8220e841ff7a43dd3591e84c504c13ecf68c3f185ce6bbf
MD5 0a2a0027f9a4a02c321ee3c7ec0c4b4b
BLAKE2b-256 b0a752fce9010b71a79a74548080174c26816a05b1e70340dc5ebd93e5e461fe

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