-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.py
49 lines (39 loc) · 1.27 KB
/
sample.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
import psycopg2
import os
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gndata_api.settings")
from gndata_api import settings
from django.core.management import call_command
from metadata.tests.assets import Assets as MA
from ephys.tests.assets import Assets as EA
# connect to the database
db = settings.DATABASES['default']
try:
conn = psycopg2.connect(
"dbname='%s' host='%s' user='%s' password='%s'" % (
db['NAME'], db['HOST'], db['USER'], db['PASSWORD']
)
)
cur = conn.cursor()
except:
print "Unable to connect to the database"
# (re)-create database schema
try:
cur.execute("""drop schema public cascade;""")
except:
cur.connection.rollback()
finally:
cur.execute("""create schema public;""")
cur.connection.commit()
# create tables for the new schema
call_command('syncdb')
if settings.DEBUG: # count as Dev environment
# create test users
call_command('loaddata', 'users')
# create test metadata
MA().fill()
# create test ephys objects
EA().fill()
else:
# create test users
call_command('loaddata', 'production_users')