Skip to content

Commit 7cf8716

Browse files
committed
docs: howto combine migrations
1 parent 6487a79 commit 7cf8716

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
tags:
3+
- Django
4+
- migrations
5+
---
6+
7+
# Combine migrations
8+
9+
This howto assumes we have `django-linear-migrations` installed, and that we have a migration file `max_migration.txt` for each app that contains the latest migration for that app.
10+
11+
To combine migrations `0025-0027` in the `core` app, where the last migration is `0027`
12+
13+
1. Roll back migrations to before all the target migrations, e.g. `0024`
14+
15+
```bash
16+
./script/migrate.sh core 0024
17+
```
18+
19+
1. Delete migration files to be combined.
20+
21+
```bash
22+
rm app/core/migrations/00{25,26,27}_*
23+
```
24+
25+
1. Recreate `max_migration.txt`
26+
27+
```bash
28+
docker-compose exec web python manage.py create_max_migration_files --recreate core
29+
# the file core/max_migration.txt should now contain "0024_..."
30+
```
31+
32+
1. Generate combined migration file
33+
34+
```bash
35+
./script/migrate.sh core
36+
```
37+
38+
## When to use this
39+
40+
- PRs can have multiple migration files that should be made into a single create migration for merging.
41+
42+
## Who should use this
43+
44+
- Developers

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ plugins:
3030
- Onboarding
3131
- database
3232
- postgres
33+
- Django
34+
- migrations
3335

3436
markdown_extensions:
3537
- abbr

0 commit comments

Comments
 (0)