forked from peterldowns/djoauth2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_migrations.py
executable file
·58 lines (41 loc) · 1.49 KB
/
generate_migrations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# coding: utf-8
import sys
from argparse import ArgumentParser
from os.path import abspath
from os.path import dirname
# Modify the path so that our djoauth2 app is in it.
parent_dir = dirname(abspath(__file__))
sys.path.insert(0, parent_dir)
# Load Django-related settings; necessary for tests to run and for Django
# imports to work.
import local_settings
# Now, imports from Django will work properly without raising errors related to
# missing or badly-configured settings.
from django.core import management
from refactor_migrations import refactor
def generate_migrations(initial):
management.call_command('syncdb', interactive=False)
if initial:
management.call_command('schemamigration', 'djoauth2', initial=True)
else:
management.call_command('schemamigration', 'djoauth2', auto=True)
refactor('./djoauth2/migrations/')
def test_migrations():
management.call_command('syncdb', interactive=False)
management.call_command('migrate', 'djoauth2')
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--initial-migration',
action='store_true',
default=False,
dest='initial')
parser.add_argument('--test-migrations',
action='store_true',
default=False,
dest='test_migrations')
args = parser.parse_args()
if args.test_migrations:
test_migrations()
else:
generate_migrations(args.initial)