-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_db.py
executable file
·69 lines (48 loc) · 1.44 KB
/
init_db.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
import logging
import argparse
from main import app
from db_model import db
from db_model import User, Race, Checkpoint, CheckpointTime
logger = logging.getLogger(__name__)
def add_test_data():
u = User('foo')
db.session.add(u)
u2 = User('bar')
db.session.add(u2)
c1 = Checkpoint('start')
c2 = Checkpoint('finish')
db.session.add(c1)
db.session.add(c2)
db.session.commit()
r = Race([u])
db.session.add(r)
db.session.commit()
t = CheckpointTime(r, c1, u, 0)
db.session.add(t)
t = CheckpointTime(r, c2, u, 0)
db.session.add(t)
t = CheckpointTime(r, c1, u, 1)
db.session.add(t)
t = CheckpointTime(r, c2, u, 1)
db.session.add(t)
t = CheckpointTime(r, c1, u2, 0)
db.session.add(t)
t = CheckpointTime(r, c2, u2, 0)
db.session.add(t)
db.session.commit()
def main():
parser = argparse.ArgumentParser(description="")
parser.add_argument('-c', '--create-db', action='store_true', help='create database')
parser.add_argument('-d', '--drop-db', action='store_true', help='drop database')
parser.add_argument('-t', '--test-data', action='store_true', help='add test data')
args = parser.parse_args()
with app.app_context():
if args.drop_db:
db.drop_all()
if args.create_db:
db.create_all()
if args.test_data:
add_test_data()
if __name__ == '__main__':
main()