Skip to content

Commit a0a3062

Browse files
committed
update readme
1 parent 84e4746 commit a0a3062

File tree

1 file changed

+108
-1
lines changed

1 file changed

+108
-1
lines changed

README.md

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,108 @@
1-
Test
1+
# Django auto rollback
2+
This package allow to easily manage apps migrations based on GIT repository (it use commits to store apps state).
3+
So you can easily return to any previous state that is stored in DB by one command.
4+
5+
## Version
6+
This is the first release of package. Current version is `0.1.0`
7+
8+
It works with:
9+
- django == 1.11
10+
- GitPython >= 2.1.8
11+
- PostgreSQL
12+
13+
## Installing
14+
15+
First yoy need to install package with pip:
16+
```bash
17+
pip install git+https://bitbucket.gcore.lu/scm/~aleksey.yakovlev_gcore.lu/django-auto-rollback.git@0.1.0
18+
```
19+
20+
Then install it to your `INSTALLED_APPS`
21+
```python
22+
INSTALLED_APPS = [
23+
# ...
24+
'django_rollback',
25+
]
26+
```
27+
28+
You are also should execute `./manage.py migrate` before using additional management commands.
29+
30+
## Using
31+
There is only two commands to manage migrations state:
32+
33+
### Storing current state
34+
```bash
35+
./manage.py store_migrations_state
36+
```
37+
This command used to store current commit state to DB (it create new or update existing state).
38+
39+
Successful output example below:
40+
```bash
41+
Data = [(4, 'admin', '0002_logentry_remove_auto_add'), (12, 'auth', '0008_alter_user_username_max_length'), (5, 'contenttypes', '0002_remove_content_type_name'), (16, 'django_auto_rollback', '0001_initial'), (17, 'django_rollback', '0001_initial'), (14, 'sessions', '0001_initial')].
42+
Successfully created for commit "84e47461a95fa325d9e933bbe8cca8c52bbea203".
43+
```
44+
45+
### Return to previous state
46+
```bash
47+
./manage.py rollback_migrations
48+
```
49+
Help message below:
50+
```bash
51+
usage: manage.py rollback_migrations [-t TAG] [-c COMMIT] [--fake]
52+
53+
Rollback migrations state of all django apps to chosen tag or commit if
54+
previously stored.
55+
56+
optional arguments:
57+
-t TAG, --tag TAG Git tag in witch needs to rollback migrations.
58+
-c COMMIT, --commit COMMIT
59+
Git commit hash in witch needs to rollback migrations.
60+
--fake Used to block migrate commands execution, so it allow
61+
to only print info about processed actions without
62+
execution.
63+
```
64+
65+
You can use git commit hash (hex) directly.
66+
You don`t need to specify full commit hash, you just can use first letters.
67+
The commands below are equal:
68+
```bash
69+
./manage.py rollback_migrations -c 0e02e741c5953212428adc1cac9060b2a0b8626b
70+
./manage.py rollback_migrations -c 0e02e74
71+
./manage.py rollback_migrations --commit 0e02e74
72+
```
73+
Or you can use git tag (it will be translated to related commit).
74+
```bash
75+
./manage.py rollback_migrations -t v.0.0.1
76+
./manage.py rollback_migrations --tag v.0.0.2
77+
```
78+
79+
Either tag or commit argument is required:
80+
```bash
81+
./manage.py rollback_migrations
82+
CommandError: Tag or commit should be described by -t or -c arguments.
83+
```
84+
And it can`t be used together:
85+
```bash
86+
./manage.py rollback_migrations -c 0e02e74 -t v.0.0.1
87+
CommandError: Tag and commit arguments should not be described together.
88+
```
89+
90+
Successful output example below:
91+
```bash
92+
./manage.py rollback_migrations -c c257a23
93+
>>> Executing command: migrate django_rollback zero
94+
Operations to perform:
95+
Unapply all migrations: django_rollback
96+
Running migrations:
97+
Rendering model states... DONE
98+
Unapplying django_rollback.0001_initial... OK
99+
Rollback successfully finished.
100+
```
101+
102+
As you can see above, apps can be rollbacked to `zero` state too, if in previous state this app not used.
103+
104+
### Successful rollback conditions
105+
So rollback will be successfully finished if two conditions are satisfied:
106+
- state for current commit are stored (if not - use `./manage.py store_migrations_state` command)
107+
- state for specified commit or commit witch relates to specified tag was stored in the past
108+

0 commit comments

Comments
 (0)