-
Notifications
You must be signed in to change notification settings - Fork 1
/
mysql_migration.py
88 lines (68 loc) · 2.5 KB
/
mysql_migration.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
from app.loadConfig import *
from peewee import *
import os
import datetime
################################################################################################
# This file is for migrating from SQLite to MySql. This is the file that creates the structure
def getDB():
dir_name = os.path.dirname(__file__) # Return the directory name of pathname _file_
cfg = load_config(os.path.join(dir_name, 'app/secret_config.yaml'))
db_name = cfg['db']['db_name']
host = cfg['db']['host']
username = cfg['db']['username']
password = cfg['db']['password']
theDB = MySQLDatabase ( db_name, host = host, user = username, passwd = password)
return theDB
mainDB = getDB()
class baseModel(Model):
class Meta:
database = mainDB
# CLASSES WITH NO FOREIGN KEY FIELD
class Semesters (baseModel):
SEID = PrimaryKeyField()
year = IntegerField()
term = CharField()
def __str__(self):
return str(self.SEID)
class Divisions (baseModel):
DID = PrimaryKeyField()
name = CharField()
def __str__(self):
return str(self.DID)
# CLASSES WITH FOREIGN KEY FIELDS
class Programs (baseModel):
PID = PrimaryKeyField()
name = CharField()
DID = ForeignKeyField(Divisions)
def __str__(self):
return str(self.PID)
class Users (baseModel):
username = CharField(primary_key=True)
firstName = CharField()
lastName = CharField()
email = CharField()
isAdmin = BooleanField(default = False)
PID = ForeignKeyField(Programs, null = True)
DID = ForeignKeyField(Divisions, null = True)
def __str__(self):
return self.username
class Courses (baseModel):
CID = PrimaryKeyField()
prefix = CharField()
number = CharField()
section = CharField()
PID = ForeignKeyField(Programs)
SEID = ForeignKeyField(Semesters)
filePath = TextField(null = True)
lastModified = TextField(null = True)
def __str__(self):
return str(self.CID)
class UsersCourses (baseModel):
UCID = PrimaryKeyField()
username = ForeignKeyField(Users)
CID = ForeignKeyField(Courses)
class Deadline(baseModel):
description = TextField()
date = DateField()
# Enter all the tables here
mainDB.create_tables([Semesters, Divisions, Programs, Users, Courses, UsersCourses, Deadline])