This repository has been archived by the owner on Feb 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
reset-db
executable file
·49 lines (36 loc) · 1.6 KB
/
reset-db
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
#!/usr/bin/python
import sys
import os
path = os.path.abspath(os.path.join(os.path.dirname(__file__)))
sys.path.append(path)
os.environ['RAPIDSMS_INI'] = os.path.join(path, "rapidsms.ini")
os.environ['DJANGO_SETTINGS_MODULE'] = 'rapidsms.webui.settings'
if "--force" not in sys.argv:
print """******** WARNING **********
This DELETES all the data from the database and recreates
all the key fixtures for this project from the file system.
Are you sure you want to do that?
If so pass repeat this command with --force at the end."""
sys.exit(1)
import time
from tempfile import mkstemp
backup = mkstemp(".db")[1]
print "Database backed up to %s, just in case." % backup
os.system('mv malawi.db %s' % backup)
os.system('django-admin.py makemessages -l en --pythonpath=. --settings=settings')
os.system('django-admin.py compilemessages --pythonpath=. --settings=settings')
from django.contrib.auth import models as auth_app
from django.contrib.auth.management import create_superuser
from django.core.management import call_command
from django.db.models.signals import post_save, post_syncdb
# turn off asking about the super user
post_syncdb.disconnect(create_superuser, sender=auth_app, dispatch_uid = "django.contrib.auth.management.create_superuser")
# turn off user profiles for loaddata
from django.contrib.auth.models import User
from apps.sms.models.profile import Profile, create_profile
post_save.disconnect(create_profile, sender=User)
call_command("syncdb")
call_command("loaddata", "observations.json")
call_command("loaddata", "zones.json")
call_command("loaddata", "auth.json")
print "Database reset."