-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatedb.py
More file actions
executable file
·86 lines (65 loc) · 1.86 KB
/
createdb.py
File metadata and controls
executable file
·86 lines (65 loc) · 1.86 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from common.db_schema import db
import argparse
from api import create_app
from flask_migrate import stamp
parser = argparse.ArgumentParser(description='Set up a fresh ClassClock database.')
parser.add_argument('--demo', action='store_true',
help='Add some demo data to the database after creation')
args = parser.parse_args()
print("Beginning database creation...")
with create_app().app_context():
print("Creating tables...")
db.create_all()
print("Committing...")
db.session.commit()
# then, load the migration configuration and generate the
# version table, "stamping" it with the most recent rev:
print("Stamping db version for future upgrades...")
stamp()
print("Done creating DB.")
if args.demo:
print("Loading Demo Data...")
from common.db_schema import *
import datetime
import time
def today_plus(sch, num_days):
return BellScheduleDate(date=datetime.date.today() + datetime.timedelta(days=num_days))
s = School(owner_id="1234567890", full_name="Demonstration High School", acronym="DHS")
sc1 = BellSchedule(
full_name="Even Day",
display_name= "Even",
dates=[
today_plus(s.id, 0),
today_plus(s.id, 2),
today_plus(s.id, 4)
]
)
sc2 = BellSchedule(
full_name="Odd Day",
display_name="Odd",
dates=[
today_plus(s.id, 1),
today_plus(s.id, 3)
]
)
s.schedules = [sc1,sc2]
sc1.meeting_times = [
BellScheduleMeetingTime(
bell_schedule_id =sc1.id,
name="First Period",
start_time=datetime.time(hour=8, minute=25, second=0, microsecond=0),
end_time=datetime.time(9,25)
)
]
sc2.meeting_times = [
BellScheduleMeetingTime(
bell_schedule_id =sc2.id,
name="First Period",
start_time=datetime.time(8,45),
end_time=datetime.time(9,45)
)
]
db.session.add(s)
db.session.commit()
print("Done loading demo data.")
print("Done")