-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_struct.py
More file actions
138 lines (106 loc) · 4.75 KB
/
Copy pathdb_struct.py
File metadata and controls
138 lines (106 loc) · 4.75 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
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
import datetime
import json
import pytz
from connection import *
book_lib_text = "booklib:"
book_lib_content_text = "booklibcontent:"
class useridpool(Base):
__tablename__ = 'useridpool'
user_id = Column(Integer, primary_key=True, autoincrement=True)
is_lock = Column(BOOLEAN, default=False)
class authoridpool(Base):
__tablename__ = 'authoridpool'
author_id = Column(Integer, primary_key=True, autoincrement=True)
is_lock = Column(BOOLEAN, default=False)
class rootbookidpool(Base):
__tablename__ = 'rootbookidpool'
b_id = Column(Integer, primary_key=True, autoincrement=True)
class bookidpool(Base):
__tablename__ = 'bookidpool'
b_id = Column(Integer, primary_key=True, autoincrement=True)
class users(Base):
__tablename__ = 'users'
user_id = Column(Integer, primary_key=True)
user_name = Column(String(32), nullable=False)
picture = Column(String(128), nullable=True)
age = Column(Integer, nullable=True)
gender = Column(String(8), nullable=True)
phone_number = Column(String(16), nullable=True)
email = Column(String(32), nullable=True)
birthday = Column(DATE, nullable=True)
area = Column(String(128), nullable=True)
user_describe = Column(String(128), default=None)
activate_time = Column(DATETIME, nullable=False)
password = Column(String(64), nullable=False)
following_count = Column(Integer, default=0) # 关注数
class authores(Base):
__tablename__ = 'authores'
author_id = Column(Integer, primary_key=True)
author_name = Column(String(32), nullable=False)
author_describe = Column(String(128), default=None)
picture = Column(String(64), nullable=True)
age = Column(Integer, nullable=True)
gender = Column(String(8), nullable=True)
phone_number = Column(String(16), nullable=True)
email = Column(String(128), nullable=True)
birthday = Column(DATE, nullable=True)
area = Column(String(64), nullable=True)
password = Column(String(64), nullable=False)
follower_count = Column(Integer, default=0) # 粉丝数
works_count = Column(Integer, default=0) # 作品数
class bookclass(Base):
__tablename__ = 'bookclass'
bookclass_id = Column(Integer, primary_key=True, autoincrement=True)
class_name = Column(String(32), nullable=False)
class languages(Base):
__tablename__ = 'languages'
lang_id = Column(Integer, primary_key=True, autoincrement=True)
lang_name = Column(String(16), nullable=False)
class rootbooklib():
def __init__(self, root_b_id, orgin_b_id, info):
self.root_b_id = root_b_id
self.orgin_b_id = orgin_b_id
self.info = info
pass
def add2redis(self):
r0.lpush(book_lib_text + str(self.root_b_id), self.root_b_id)
r0.lpush(book_lib_text + str(self.root_b_id), self.orgin_b_id)
r0.lpush(book_lib_text + str(self.root_b_id), json.dumps(self.info))
class booklib(Base):
__tablename__ = 'booklib'
b_id = Column(Integer, primary_key=True)
author_id = Column(Integer, ForeignKey(authores.author_id))
lang_id = Column(Integer, ForeignKey(languages.lang_id))
bc_id = Column(Integer, ForeignKey(bookclass.bookclass_id))
rootbookid = Column(Integer, nullable=False)
name = Column(String(54), nullable=False)
desc = Column(String(1024), default=None)
cover_path = Column(String(64))
create_time = Column(DATETIME, nullable=False, default=str(
datetime.datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(pytz.timezone("Asia/Shanghai"))))
is_original = Column(String(64), nullable=False)
class user_barrage(Base):
__tablename__ = 'user_barrage'
user_id = Column(Integer, ForeignKey(users.user_id), primary_key=True)
barrage = Column(String(1024))
create_time = Column(DATETIME, nullable=False, default=str(
datetime.datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(pytz.timezone("Asia/Shanghai"))),
primary_key=True)
class user_books_barrage(Base):
__tablename__ = 'user_books_barrage'
user_id = Column(Integer, ForeignKey(users.user_id), primary_key=True)
book_id = Column(Integer, ForeignKey(booklib.b_id), primary_key=True)
barrage = Column(String(1024))
create_time = Column(DATETIME, nullable=False, default=str(
datetime.datetime.utcnow().replace(tzinfo=pytz.utc).astimezone(pytz.timezone("Asia/Shanghai"))),
primary_key=True)
class fan(Base):
__tablename__ = 'fan'
fan_id = Column(Integer, primary_key=True, autoincrement=True)
user_id = Column(Integer, ForeignKey(users.user_id))
author_id = Column(Integer, ForeignKey(authores.author_id))
if __name__ == '__main__':
print("清除数据库并新建")
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
r0.flushdb()