Metadata-Version: 2.1
Name: django-migration-fixer
Version: 0.0.1
Summary: Resolve migration errors
Home-page: https://github.com/tj-django/django-migratiion-fixer
Author: Tonye Jack
Author-email: jtonye@ymail.com
License: MIT license
Keywords: migration fixer,django migrations,migrations auto fix,django migrations,django migrations autofix
Platform: UNKNOWN
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires-Python: >=3.6
Description-Content-Type: text/markdown
Requires-Dist: django
Requires-Dist: djangorestframework
Provides-Extra: deploy
Requires-Dist: bump2version ; extra == 'deploy'
Requires-Dist: readme-renderer[md] ; extra == 'deploy'
Requires-Dist: changes ; extra == 'deploy'
Requires-Dist: git-changelog ; extra == 'deploy'
Requires-Dist: twine ; extra == 'deploy'
Requires-Dist: wheel ; extra == 'deploy'
Provides-Extra: development
Requires-Dist: django ; extra == 'development'
Requires-Dist: djangorestframework ; extra == 'development'
Requires-Dist: bump2version ; extra == 'development'
Requires-Dist: readme-renderer[md] ; extra == 'development'
Requires-Dist: changes ; extra == 'development'
Requires-Dist: git-changelog ; extra == 'development'
Requires-Dist: twine ; extra == 'development'
Requires-Dist: wheel ; extra == 'development'
Requires-Dist: pytest (>=3) ; extra == 'development'
Requires-Dist: tox ; extra == 'development'
Requires-Dist: tox-gh-actions ; extra == 'development'
Requires-Dist: coverage ; extra == 'development'
Requires-Dist: codacy-coverage ; extra == 'development'
Requires-Dist: flake8 ; extra == 'development'
Requires-Dist: yamllint ; extra == 'development'
Requires-Dist: isort ; extra == 'development'
Requires-Dist: black ; extra == 'development'
Requires-Dist: mypy ; extra == 'development'
Provides-Extra: docs
Requires-Dist: watchdog[watchmedo] ; extra == 'docs'
Requires-Dist: Sphinx ; extra == 'docs'
Provides-Extra: lint
Requires-Dist: flake8 ; extra == 'lint'
Requires-Dist: yamllint ; extra == 'lint'
Requires-Dist: isort ; extra == 'lint'
Requires-Dist: black ; extra == 'lint'
Requires-Dist: mypy ; extra == 'lint'
Provides-Extra: test
Requires-Dist: pytest (>=3) ; extra == 'test'
Requires-Dist: tox ; extra == 'test'
Requires-Dist: tox-gh-actions ; extra == 'test'
Requires-Dist: coverage ; extra == 'test'
Requires-Dist: codacy-coverage ; extra == 'test'

# django-migration-fixer

## Problem

Maintain a linear migration history when conflicts as a result of changes made using different versions of the default branch.


### Example

**Branch:** `main`

```text

migrations
  ├── 0001_initial.py
  ├── 0002_auto_20210521_2328.py 

```


**Branch:** `feature/test-a`

```text

migrations
  ├── 0001_initial.py
  ├── 0002_auto_20210521_2328.py
  ├── 0003_auto_20210522_1128.py 

```

**Branch:**`feature/test-b`

```text

migrations
  ├── 0001_initial.py
  ├── 0002_auto_20210521_2328.py
  ├── 0003_auto_20210522_1228.py 

```


Both `feature/test-a` and `feature/test-b` share the last migration on `main` (`0002_auto_20210521_2328.py`) 


Once `feature/test-a` is merged into `main` you run into the problem of resolving migrations on `feature/test-b` which was dependent on `0002_auto_20210521_2328.py`

**Branch:** `main`

```text

migrations
  ├── 0001_initial.py
  ├── 0002_auto_20210521_2328.py
  ├── 0003_auto_20210522_1128.py 

```

**Branch:** `feature/test-b`

```text

migrations
  ├── 0001_initial.py
  ├── 0002_auto_20210521_2328.py
  ├── 0003_auto_20210522_1128.py \___________________ Both dependent on 0002_auto_20210521_2328.py
  ├── 0003_auto_20210522_1228.py /

```


Error running [`makemigrations`](https://docs.djangoproject.com/en/3.2/ref/django-admin/#django-admin-makemigrations)

```
CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0003_auto_20210522_1128, 0003_auto_20210522_1228 in my_app).
To fix them run 'python manage.py makemigrations --merge'
```

Using the default `--merge` option creates a new migration file which might not be desired.


## Solution

Using `django-migration-fixer` identifies changes between the default branch `main`, and the feature branch `feature/test-b` by maintaining a linear dependency as shown below:

**Branch:** `feature/test-b`

```text

migrations
  ├── 0001_initial.py
  ├── 0002_auto_20210521_2328.py
  ├── 0003_auto_20210522_1128.py
  ├── 0004_auto_20210522_1228.py

```

### Assumptions

The final migration on the default branch would be used as the base for all subsequent migrations.


after running 

```bash script
$ python manage.py makemigrations --fix
```


## Installation

```bash script
$ pip install django-view-breadcrumbs
```

#### Add `migration_fixer` to your INSTALLED_APPS

```python
INSTALLED_APPS = [
    ...,
    "migration_fixer",
    ...,
]
```


## Usage

```bash script
$ python manage.py makemigrations --fix 
```

### Specifying a different default branch name

Use:

```bash script
$ python manage.py makemigrations -b master --fix 
```


## Features
- Resolve migration dependencies
- Supports numbered migration files i.e (`0001_....py`)
- Supports non-numbered migration files i.e (`custom_migration.py`)
- Re-index all migrations using the last migration on the default branch i.e `main`


