You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-19Lines changed: 18 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,12 @@
1
-
# django-replace-migrations
1
+
# gg-django-replace-migrations
2
2
3
-
This package is an extension to djangos `makemigrations.py`.
4
-
It can be used to get rid of old migrations as an alternative to djangos`squashmigration` command.
3
+
This package offers a new django command: `replace_all_migrations`.
4
+
It can be use to get rid of old migrations as an alternative to django's`squashmigration` command.
5
5
6
6
## Reasoning
7
7
8
8
In big django projects, migration files easily pile up and get an increasing problem.
9
-
Django comes with the squashmigration command - however, it is hard to handle because of multiple reasons.
10
-
Especially, it can not handle circular dependencies - they must be resolved [manually and with great care](https://stackoverflow.com/questions/37711402/circular-dependency-when-squashing-django-migrations).
9
+
Django comes with the squashmigration command - however, it is hard to handle because of multiple reasons. Especially, it can not handle circular dependencies - they must be resolved [manually and with great care](https://stackoverflow.com/questions/37711402/circular-dependency-when-squashing-django-migrations).
11
10
12
11
One possible solution is to:
13
12
@@ -17,13 +16,11 @@ One possible solution is to:
17
16
18
17
This workflow might work fine, if you have only few (production) servers - however, it becomes hard, when you have many environments with different versions of your application.
19
18
20
-
With django-replace-migrations also creates new initial migrations, but also, additionally, adds the already existing migrations to the `replace` list of the new migration
21
-
(That list is used by `squashmigrations` as well). By doing that, faking migrations is not needed anymore.
19
+
gg-django-replace-migrations also creates new initial migrations, but also, additionally, it adds the already existing migrations to the `replace` list of the new migration (That list is used by `squashmigrations` as well). By doing that, faking migrations is not needed anymore.
22
20
23
21
## Warning
24
22
25
-
The new replacing migrations will not consider any `RunPython` or `RunSQL` operations.
26
-
That might be acceptable depending on your use of those operations and if you need those to prepare a fresh database.
23
+
The new replacing migrations will add not elidable special operations (`RunPython`, `RunSQL` or `SeparateDatabaseAndState`) at the end of the squash files. You will have to manually add them when suitable.
27
24
28
25
## Installation
29
26
@@ -32,20 +29,26 @@ Before you install, read the workflow below. You need to have the app installed
32
29
Run
33
30
34
31
```
35
-
pip install django-replace-migrations
32
+
pip install gg-django-replace-migrations
36
33
```
37
34
38
-
and add `django_replace_migrations` to your list of installed apps.
35
+
and add `gg_django_replace_migrations` to your list of installed apps.
39
36
40
37
## Simple Workflow
41
38
42
39
If your apps are not depending on each other, you can use django-replace-migrations like this:
Note, that you will need to list all of your apps explicitly - otherwise django will also try to replace migrations from dependencies:
46
+
47
+
```
48
+
from django.apps import apps
49
+
print(" ".join(map(str, sorted({model._meta.app_label for model in apps.get_models()}))))
46
50
```
47
51
48
-
Note, that you will need to [list all of your apps](https://stackoverflow.com/questions/4111244/get-a-list-of-all-installed-applications-in-django-and-their-attributes) explicitly - otherwise django will also try to replace migrations from dependencies.
49
52
While `--name` could be omitted, it is highly recommended to use it so that you can easily recognize the new migrations.
50
53
51
54
If for any of your apps there are not one but two or more migrations created, your apps are depending on each other (see below).
@@ -70,8 +73,8 @@ The workflow for this would be:
70
73
- commit and note the commit hash
71
74
-`git checkout 2.0`
72
75
- create a new branch `git checkout -b 2-0-replace-migrations`
73
-
- Install `django-replace-migration` here.
74
-
- run `./manage.py makemigrations --replace-all --name replace_2_0 app1, app2, ...` ([How to get all apps](https://stackoverflow.com/questions/4111244/get-a-list-of-all-installed-applications-in-django-and-their-attributes))
76
+
- Install `gg-django-replace-migration` here.
77
+
- run `./manage.py replace_all_migrations --name replace_2_0 app1, app2, ...` ([How to get all apps](https://stackoverflow.com/questions/4111244/get-a-list-of-all-installed-applications-in-django-and-their-attributes))
75
78
- commit and note the commit hash
76
79
-`git checkout [your main/feature branch]`
77
80
-`git cherry-pick [commit-hash from 2-0-delete-migrations]`
@@ -87,7 +90,3 @@ If your app is below 2.0 and you want to update to something after 2.0, you firs
87
90
- upgrading from 1.0 to 1.5 will be possible
88
91
- upgrading from 2.0 to 3.0 will be possible
89
92
- upgrading from 1.0 to 3.0 will be **not** possible
90
-
91
-
## `makemigration.py` compatibility
92
-
93
-
This package requires deep integration into `makemigrations.py` so that I needed to copy the whole `makemigrations.py` here. Currently the version of `makemigrations.py` is copied from Django 2.1, however it is also tested with Django 3.0 and works there as well. If you encounter problems, please write what version of Django you are using.
0 commit comments