django-modern-migration-fixer


Namedjango-modern-migration-fixer JSON
Version 0.1.2 PyPI version JSON
download
home_pageNone
SummaryFix conflicting Django migrations (numbered) with robust git + worktree support
upload_time2025-09-13 17:05:43
maintainerNone
docs_urlNone
authorResQ
requires_python>=3.10
licenseMIT
keywords django migrations git worktree
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-modern-migration-fixer

[![CI](https://github.com/getresq/django-modern-migration-fixer/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/getresq/django-modern-migration-fixer/actions/workflows/ci.yml)

Fix conflicting Django migrations (numbered styles) using plain git CLI, with robust support for normal repos and git worktrees. No GitPython dependency.

This is a fork and drop-in replacement for [django-migration-fixer](https://github.com/tj-django/django-migration-fixer) which is not actively maintained by the author.

- Detects conflicting leaf nodes and renumbers local migrations to form a single linear chain.
- Rewrites `dependencies` to point to the last migration on the default branch.
- Works in git worktrees by discovering the repo root via `git rev-parse --show-toplevel`.

## Install

```bash
uv pip install django-modern-migration-fixer
```

Add to your Django settings:

```python
INSTALLED_APPS = [
    # ...
    "django_modern_migration_fixer",
    # ...
]
```

## Usage

```bash
./manage.py makemigrations --fix [apps...]
```

Useful flags:
- `-b, --default-branch`: Name of the default branch (default: `master`).
- `-r, --remote`: Git remote (default: `origin`).
- `-s, --skip-default-branch-update`: Skip fetching remote default branch.
- `-f, --force-update`: Force update the default branch refs before fixing.

Examples:

```bash
./manage.py makemigrations --fix
./manage.py makemigrations --fix -b master --skip-default-branch-update
./manage.py makemigrations --fix -r upstream --force-update
```

## How it works

- On a `Conflicting migrations` error, the command:
  - Verifies the repo is clean.
  - Optionally fetches the default branch.
  - Resolves default-branch and HEAD SHAs robustly.
  - Loads the migration graph and finds conflicts per app.
  - Filters changed migration files under the app’s migration folder between default SHA and HEAD.
  - Renumbers local files and rewrites dependencies to form a single chain.

## Limitations

- Only supports numbered migration file names (e.g., `0001_initial`). Non-numbered names fail fast with a clear message.
- Cross-app dependency rewrites beyond simple renumbering are out of scope.

## Make targets

Convenient shortcuts are available via `make`:

- `make tests` — Run unit and e2e tests (unittest discovery).
- `make tests-unit` — Discover and run tests under `tests/unit`.
- `make tests-e2e` — Discover and run tests under `tests/e2e` (safe if empty).
- `make build` — `uv sync --extra dev` then `uv build` to produce wheels/sdist.
- `make distribute` — `twine check` then upload artifacts in `dist/` to PyPI.

Notes:
- Test runs set `PYTHONPATH=src` so the package imports without installation.
- `build` and `distribute` require `uv` to be installed and available on PATH.

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "django-modern-migration-fixer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "django, migrations, git, worktree",
    "author": "ResQ",
    "author_email": "ResQ <engineering@getresq.com>",
    "download_url": "https://files.pythonhosted.org/packages/4a/57/b81a196198ed1893c18349dffcc0785572d594233d6ceda43774eed9f01d/django_modern_migration_fixer-0.1.2.tar.gz",
    "platform": null,
    "description": "# django-modern-migration-fixer\n\n[![CI](https://github.com/getresq/django-modern-migration-fixer/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/getresq/django-modern-migration-fixer/actions/workflows/ci.yml)\n\nFix conflicting Django migrations (numbered styles) using plain git CLI, with robust support for normal repos and git worktrees. No GitPython dependency.\n\nThis is a fork and drop-in replacement for [django-migration-fixer](https://github.com/tj-django/django-migration-fixer) which is not actively maintained by the author.\n\n- Detects conflicting leaf nodes and renumbers local migrations to form a single linear chain.\n- Rewrites `dependencies` to point to the last migration on the default branch.\n- Works in git worktrees by discovering the repo root via `git rev-parse --show-toplevel`.\n\n## Install\n\n```bash\nuv pip install django-modern-migration-fixer\n```\n\nAdd to your Django settings:\n\n```python\nINSTALLED_APPS = [\n    # ...\n    \"django_modern_migration_fixer\",\n    # ...\n]\n```\n\n## Usage\n\n```bash\n./manage.py makemigrations --fix [apps...]\n```\n\nUseful flags:\n- `-b, --default-branch`: Name of the default branch (default: `master`).\n- `-r, --remote`: Git remote (default: `origin`).\n- `-s, --skip-default-branch-update`: Skip fetching remote default branch.\n- `-f, --force-update`: Force update the default branch refs before fixing.\n\nExamples:\n\n```bash\n./manage.py makemigrations --fix\n./manage.py makemigrations --fix -b master --skip-default-branch-update\n./manage.py makemigrations --fix -r upstream --force-update\n```\n\n## How it works\n\n- On a `Conflicting migrations` error, the command:\n  - Verifies the repo is clean.\n  - Optionally fetches the default branch.\n  - Resolves default-branch and HEAD SHAs robustly.\n  - Loads the migration graph and finds conflicts per app.\n  - Filters changed migration files under the app\u2019s migration folder between default SHA and HEAD.\n  - Renumbers local files and rewrites dependencies to form a single chain.\n\n## Limitations\n\n- Only supports numbered migration file names (e.g., `0001_initial`). Non-numbered names fail fast with a clear message.\n- Cross-app dependency rewrites beyond simple renumbering are out of scope.\n\n## Make targets\n\nConvenient shortcuts are available via `make`:\n\n- `make tests` \u2014 Run unit and e2e tests (unittest discovery).\n- `make tests-unit` \u2014 Discover and run tests under `tests/unit`.\n- `make tests-e2e` \u2014 Discover and run tests under `tests/e2e` (safe if empty).\n- `make build` \u2014 `uv sync --extra dev` then `uv build` to produce wheels/sdist.\n- `make distribute` \u2014 `twine check` then upload artifacts in `dist/` to PyPI.\n\nNotes:\n- Test runs set `PYTHONPATH=src` so the package imports without installation.\n- `build` and `distribute` require `uv` to be installed and available on PATH.\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Fix conflicting Django migrations (numbered) with robust git + worktree support",
    "version": "0.1.2",
    "project_urls": {
        "Homepage": "https://github.com/getresq/django-modern-migration-fixer",
        "Issues": "https://github.com/getresq/django-modern-migration-fixer/issues",
        "Repository": "https://github.com/getresq/django-modern-migration-fixer"
    },
    "split_keywords": [
        "django",
        " migrations",
        " git",
        " worktree"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e2e842f3c8f3155353e0349817609af7a9c43128f74985b5a5cd4769174f947b",
                "md5": "39bfd5af06410ab87a81073c560491a6",
                "sha256": "9faf26379cabe5f230869ee5205e640d90bf53a5d66b71d87c3b45ef4dab22c7"
            },
            "downloads": -1,
            "filename": "django_modern_migration_fixer-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "39bfd5af06410ab87a81073c560491a6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 9201,
            "upload_time": "2025-09-13T17:05:41",
            "upload_time_iso_8601": "2025-09-13T17:05:41.744378Z",
            "url": "https://files.pythonhosted.org/packages/e2/e8/42f3c8f3155353e0349817609af7a9c43128f74985b5a5cd4769174f947b/django_modern_migration_fixer-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4a57b81a196198ed1893c18349dffcc0785572d594233d6ceda43774eed9f01d",
                "md5": "c5ff1dced7c4e10806b734e1f637734f",
                "sha256": "bbd49092baa7d4641328df8a10588a428b961de0ca687b4e5d82e80acb2bb328"
            },
            "downloads": -1,
            "filename": "django_modern_migration_fixer-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "c5ff1dced7c4e10806b734e1f637734f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 6936,
            "upload_time": "2025-09-13T17:05:43",
            "upload_time_iso_8601": "2025-09-13T17:05:43.138749Z",
            "url": "https://files.pythonhosted.org/packages/4a/57/b81a196198ed1893c18349dffcc0785572d594233d6ceda43774eed9f01d/django_modern_migration_fixer-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-13 17:05:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "getresq",
    "github_project": "django-modern-migration-fixer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "django-modern-migration-fixer"
}
        
Elapsed time: 1.99186s