-
Notifications
You must be signed in to change notification settings - Fork 1
/
migrateDatabase.py
173 lines (146 loc) · 5.49 KB
/
migrateDatabase.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
import sys, os
from app.models import *
import MySQLdb
import datetime
# this function populates the database with the information found in the old system of cas
# change this to cas server if working outside of c9
from create_tables import *
if os.getenv('C9_USER'):
USER = os.getenv('C9_USER')
db = MySQLdb.connect(host = '127.0.0.1',
user = USER,
passwd = '',
db = 'c9',
port = 3306)
os.system('mysql -h localhost -u {username} < create_mysql_db.sql'.format(username=USER))
cur = db.cursor()
#This updates the division
cur.execute("SELECT * FROM division")
for row in cur.fetchall():
# print row[1]
division = Division(dID = row[0],
name = row[1])
division.save(force_insert= True)
#this updates the programs
cur.execute("select * FROM program")
for row in cur.fetchall():
# print row[1], row[3]
program = Program(pID = row[0],
name = row[1],
division = row[3])
program.save(force_insert = True)
cur.execute("SELECT * FROM userprofile")
for row in cur.fetchall():
# print row[0], row[1], row[2], row[3], row[4]
admin = 0
if int(row[5]) == 4:
admin = 1
users = User(username = row[0],
firstName = row[1],
lastName = row[2],
email = row[3],
bNumber = row[4],
isAdmin = admin,
lastVisted = None)
users.save(force_insert = True)
# This will update the subjects
cur.execute("SELECT * FROM subjects")
for row in cur.fetchall():
# print row[0], row[1], row[2]
subject = Subject(prefix = row[0],
pid = int(row[1]),
webname = row[2])
subject.save(force_insert = True)
# this updates the bannerCourses
cur.execute("select * from bannerschedules")
for row in cur.fetchall():
# print row[0], row[1], row[2], row[3], row[4], row[5]
schedule = BannerSchedule(letter = row[0],
days = row[1],
startTime = (datetime.datetime.min + row[2]).time(),
endTime = (datetime.datetime.min + row[3]).time(),
sid = row[4],
order = int(row[5])).save(force_insert=True)
#this populates the banner courses
cur.execute("select * from bannercourses")
for row in cur.fetchall():
# print row[0], row[1], row[2], row[4]
bannercourse = BannerCourses(reFID = row[0],
subject = row[1],
number = row[2],
ctitle = row[4]).save(force_insert= True)
# this gets the terms
cur.execute("select * from term")
for row in cur.fetchall():
# print row[0], row[1], row[2], row[3]
term = Term(name = row[1],
termCode = row[2],
state = row[3]).save(force_insert=True)
# This populates the courses
cur.execute("select * from course")
cur2 = db.cursor()
for row in cur.fetchall():
#print row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10]
cur2.execute("select subject from bannercourses where refID = {0}".format(row[1]))
for subject in cur2.fetchall():
sub = subject[0]
cur2.execute("select term_code from term where TID = {}".format(row[2]))
for term in cur2.fetchall():
termCode = term[0]
capacity = row[4]
# if row[4] is None:
# capacity = 0
schedule = row[3]
# if row[3] is None:
# schedule = 'ZZZ'
room = row[9]
# if row[9] is None:
# room = ''
print row[0]
course = Course(cId = int(row[0]),
bannerRef = int(row[1]),
term = int(termCode),
schedule = schedule,
capacity = capacity,
specialTopicName = row[6],
notes = room,
lastEditBy = row[10],
crossListed = 0,
prefix = str(sub)).save(force_insert = True)
# this populates the programs
cur.execute("select * from program")
cur3 = db.cursor()
for row in cur.fetchall():
cur3.execute("select username from userprofile where UID = {}".format(row[2]))
for user in cur3.fetchall():
username = user[0]
# print row[1], username
programChair = ProgramChair(username = username,
pid = row[0]).save()
# this populates the divisions
cur.execute("select * from division")
cur4 = db.cursor()
for row in cur.fetchall():
cur4.execute("select username from userprofile where UID = {}".format(row[2]))
for user in cur4.fetchall():
username = user[0]
# print row[1], username
divisionChair = DivisionChair(username = username,
did = row[0]).save()
# this populates the instructs
cur.execute("select * from instructors2")
cur5 = db.cursor()
for row in cur.fetchall():
cur5.execute("select username from userprofile where UID = {}".format(row[1]))
for user in cur5.fetchall():
username = user[0]
instructorCourse = InstructorCourse(username = username,
course = row[2]).save()
cur.execute("select * from rooms")
for row in cur.fetchall():
room = Rooms(rID = row[0],
building = row[1],
number = row[2],
maxCapacity = row[3],
roomType = row[4]).save(force_insert = True)
db.close()