-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
55 lines (37 loc) · 1.52 KB
/
model.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
from peewee import *
#db = MySQLDatabase('iNP', user='root', passwd='********')
#db = SqliteDatabase('database.db', pragmas={'foreign_keys': 1})
db = MySQLDatabase("test_0105", host=os.getenv('MySQL_RDS'), port=3306,
user=os.getenv('MySQL_USER'), passwd=os.getenv('MySQL_PASS'))
class BaseModel(Model):
class Meta:
database = db
class User(BaseModel):
username = CharField(unique=True)
password = CharField()
class Invitation(BaseModel):
inviter = ForeignKeyField(User, on_delete='CASCADE')
invitee = ForeignKeyField(User, on_delete='CASCADE')
class Friend(BaseModel):
user = ForeignKeyField(User, on_delete='CASCADE')
friend = ForeignKeyField(User, on_delete='CASCADE')
class Post(BaseModel):
user = ForeignKeyField(User, on_delete='CASCADE')
message = CharField()
class Follow(BaseModel):
follower = ForeignKeyField(User, on_delete='CASCADE')
followee = ForeignKeyField(User, on_delete='CASCADE')
class Token(BaseModel):
token = CharField(unique=True)
owner = ForeignKeyField(User, on_delete='CASCADE')
##################### New Tables #####################
class Group(BaseModel):
group = CharField()
user = ForeignKeyField(User, on_delete='CASCADE')
class App_Server(BaseModel):
server = CharField()
user = ForeignKeyField(User, on_delete='CASCADE')
#####################################################
if __name__ == '__main__':
db.connect()
db.create_tables([User, Invitation, Friend, Post, Follow, Token, Group, App_Server])