-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-schema.py
265 lines (196 loc) · 9.11 KB
/
update-schema.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
from peewee import *
from playhouse.migrate import *
from api.models import *
from api.config import load_config
here = os.path.dirname(__file__)
cfg = load_config(os.path.join(here, 'api/config.yaml'))
# db = os.path.join(here,cfg['databases']['dynamic'])
# print("db", db)
# mainDB = SqliteDatabase(cfg['databases']['dev'])
# my_db = SqliteDatabase(db,
# pragmas = ( ('busy_timeout', 100),
# ('journal_mode', 'WAL')
# ),
# threadlocals = True
# )
mainDB = MySQLDatabase ("urcpp_flask_v2", host = "db", user = "urcpp-flask", passwd = "DanforthLabor123!")
# Creates the class that will be used by Peewee to store the database
class dbModel (Model):
class Meta:
database = mainDB
migrator = MySQLMigrator(mainDB)
############# ADDING DIFFERENT COLUMNS - UNCOMMENT EACH LINE AT A TIME #################################################################
#########################################################################################################################################
try:
migrate(
migrator.add_column('parameters', 'ProposalOpenDate', DateTimeField(null=True))
)
except Exception as e:
print(e)
print("Column ProposalOpenDate in table parameters already exists")
try:
migrate(
migrator.add_column('parameters', 'ProposalAcceptanceDate', DateTimeField(null=True))
)
except:
print("Column ProposalAcceptanceDate in table parameters already exists")
try:
migrate(
migrator.add_column('parameters', 'ProposalClosedDate', DateTimeField(null=True))
)
except:
print("Column ProposalCloseddate in table parameters already exists")
try:
migrate(
migrator.add_column('parameters', 'AbstractnarrativesAcceptanceDate', DateTimeField(null=True))
)
except:
print("Column AbstractnarrativesAcceptanceDate in table parameters already exists")
try:
migrate(
migrator.add_column('parameters', 'AllSubmissionsClosedDate', DateTimeField(null=True))
)
except:
print("Column AllSubmissionsClosedDate in table parameters already exists")
try:
migrate(
migrator.add_column('parameters', 'IRBchair_id', ForeignKeyField(LDAPFaculty, to_field = LDAPFaculty.username, null=True))
)
except:
print("Column IRBchair_id in table parameters already exists")
try:
migrate(
migrator.add_column('parameters', 'currentchair_id', ForeignKeyField(LDAPFaculty, to_field = LDAPFaculty.username, null=True))
)
except:
print("Column currentchair_id in table parameters already exists")
try:
migrate(
migrator.add_column('parameters', 'staffsupport_id', ForeignKeyField(LDAPFaculty, to_field = LDAPFaculty.username, null=True))
)
except:
print("Column staffsupport_id in table parameters already exists")
##########################################################################################################################################
# my_db.drop_tables([RoomPreferences])
#TODO: make a function & wrap it up in try/catch statement so it doesn't break when tables are already there/aren't there
# def dropTables():
# tables = [Rooms, Building, EducationTech, RoomPreferences, CourseChange, ScheduleDays, Course]
# for table in tables:
# try:
# my_db.drop_tables([table])
# except:
# pass
# class TermStates(dbModel):
# csID = PrimaryKeyField()
# number = IntegerField(null = False)
# name = CharField(null = False)
# order = IntegerField(null = False)
# display_name = CharField(null = False)
# To add states to Temstates table
# state_1 = TermStates(number = 0, order = 0, name = "term_created", display_name = "Term Created").save()
# state_2 = TermStates(number = 1, order = 1, name = "schedule_opened", display_name = "Open Scheduling").save()
# state_3 = TermStates(number = 2, order = 2, name = "schedule_closed", display_name = "Lock Scheduling").save()
# state_3 = TermStates(number = 3, order = 3, name = "roomprefrences_opened", display_name = "Open Room Preferences").save()
# state_4 = TermStates(number = 4, order = 4, name = "roomprefrences_closed", display_name = "Lock Room Preferences").save()
# state_5 = TermStates(number = 5, order = 5, name = "rooms_assigned", display_name = "Assign Rooms").save()
# state_6 = TermStates(number = 6, order = 6, name = "term_finished", display_name = "Finish").save()
# state_7 = TermStates(number = 7, order = 7, name = "term_archived", display_name = "Archive").save()
# '''
# t = Term.select()
# for term in t:
# term.algorithm_running = False
# term.save()
# '''
# my_db.drop_tables([RoomPreferences])
# my_db.drop_tables([Building, EducationTech])
# my_db.drop_tables([Building, Rooms, EducationTech, RoomPreferences])
#TODO: make a function & wrap it up in try/catch statement so it doesn't break when tables are already there/aren't there
# def dropTables():
# tables = [Rooms, Building, EducationTech, RoomPreferences, CourseChange, ScheduleDays, Course]
# for table in tables:
# try:
# my_db.drop_tables([table])
# except:
# pass
# q = Course.select()
# for course in q:
# course.rid = None
# course.save()
# q = SpecialTopicCourse.select()
# for course in q:
# course.rid = None
# course.save()
#my_db.create_tables([RoomPreferences, EducationTech, Building, Rooms, Course, CourseChange, ScheduleDays])
#Add these columns to existing tables in the production
#Building column add
# migrate(
# migrator.add_column('Building', 'shortName', TextField(default='')),
# )
# #Rooms Column Add
# migrate(
# #migrator.add_column('Rooms', 'maxCapacity', IntegerField(null=False)), #update already exists
# migrator.add_column('Rooms', 'visualAcc', CharField(null=True)),
# migrator.add_column('Rooms', 'audioAcc', CharField(null=True)),
# migrator.add_column('Rooms', 'physicalAcc',CharField(null=True)),
# migrator.add_column('Rooms', 'educationTech_id', ForeignKeyField(EducationTech, to_field = EducationTech.eId, related_name='rooms', null=True)),
# migrator.add_column('Rooms', 'specializedEq', CharField(null=True)),
# migrator.add_column('Rooms', 'specialFeatures', CharField(null=True)),
# migrator.add_column('Rooms', 'movableFurniture', BooleanField(default=False)),
# )
# migrate(
# migrator.drop_column("Course", "rid"),
# migrator.add_column("Course", "rid_id", ForeignKeyField(Rooms, to_field = Rooms.rID, null = True, related_name='courses_rid'))
# )
# my_db.drop_tables([ScheduleDays])
# class ScheduleDays(dbModel):
# sdID = PrimaryKeyField()
# schedule = ForeignKeyField(BannerSchedule, null = True, related_name='course_schedule_days')
# day = CharField(null=True)
# my_db.create_tables([BuildingManager])
# bmanager = BuildingManager( username = "stamperf",
# bmid = 6
# ).save()
# migrate(
# migrator.add_column('Rooms', 'lastModified', CharField(null=True))
# migrator.add_column('RoomPreferences', 'priority', IntegerField(default=6)),
# migrator.add_column('Course', 'days_id', ForeignKeyField(ScheduleDays, to_field = ScheduleDays.sdID , null = True, related_name='course_days'))
# my_db.create_tables([ScheduleDays])
# my_db.create_tables([RoomPreferences])
# migrate(
# migrator.add_column('RoomPreferences', 'priority', IntegerField(default=6))
# # migrator.add_column('Course', 'days_id', ForeignKeyField(ScheduleDays, to_field = ScheduleDays.sdID , null = True, related_name='course_days'))
# # migrator.drop_not_null('CourseChange','rid')
# )
# my_db.drop_tables([ScheduleDays])
# class ScheduleDays(dbModel):
# sdID = PrimaryKeyField()
# schedule = ForeignKeyField(BannerSchedule, null = True, related_name='course_schedule_days')
# day = CharField(null=True)
# migrate(
# # migrator.add_column('RoomPreferences', 'priority', IntegerField(default=6)),
# # migrator.drop_column("Term", "state"),
# migrator.add_column('Term', 'term_state_id', ForeignKeyField(TermStates, to_field = TermStates.csID , default = 1, related_name='term_states')),
# # migrator.add_column('Term', 'algorithm_running', BooleanField(null = False, default = False))
# migrator.add_column('Term', 'editable', BooleanField(null = False, default = True))
# # migrator.drop_not_null('CourseChange','rid')
# )
# t = Term.select()
# for term in t:
# term.algorithm_running = False
# term.save()
# q = Course.select()
# for course in q:
# course.rid = None
# course.save()
# q = SpecialTopicCourse.select()
# for course in q:
# course.rid = None
# course.save()
# PART OF PR 265
# migrate(
# migrator.add_column("rooms", "lastModified", CharField(null = True)))
# try:
# mainDB.create_tables([CrossListed])
# except:
# print("Table Crosslisted already exists")
#