-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreset_database.py
105 lines (85 loc) · 2.46 KB
/
reset_database.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
# coding=utf-8
__author__ = 'smallfly'
from app.mod_interaction.models import *
# 建立一些测试用途的数据
def generate_test_data():
# 一些测试数据
import json
photo_list = {
"photo_list":[
{
"size_big": "https://xiaofud.me/img/746ff7890c10e100.jpg",
"size_small": "https://xiaofud.me/img/746ff7890c10e100.jpg"
},
{
"size_big": "https://xiaofud.me/img/img0082.jpg",
"size_small": "https://xiaofud.me/img/img0082.jpg"
}
]
}
photo_list_json = json.dumps(photo_list, ensure_ascii=True)
xiaofud = {
"account": "14xfdeng",
"nickname": "晓拂",
# "birthday": "1995-12-23",
"gender": 1,
"profile": "hello world"
}
user = User(**xiaofud)
db.session.add(user)
db.session.commit()
post_info = {
"post_type": 1,
"uid": user.id,
# "title": "this is title",
"content": "this is content" * 100,
"description": "this is description",
"photo_list_json": photo_list_json
}
post = Post(**post_info)
db.session.add(post)
db.session.commit()
for i in range(5):
user_info = {
"account": "14xfdeng " + str(i),
"nickname": "xiaofud" + str(i),
"birthday": "1995-12-23",
"gender": 1,
"profile": "hello world"
}
user = User(**user_info)
db.session.add(user)
db.session.commit()
post_info = {
"post_type": 1,
"uid": user.id,
# "title": "this is title",
"content": "this is content %d\n" % i ,
"description": "this is description",
"photo_list_json": photo_list_json
}
post = Post(**post_info)
db.session.add(post)
db.session.commit()
comment_info = {
"post_id": post.id,
"uid": user.id,
"comment": "hello world" * 8
}
comment = Comment(**comment_info)
db.session.add(comment)
db.session.commit()
like_info = {
"uid": user.id,
"post_id": post.id
}
like = ThumbUp(**like_info)
db.session.add(like)
db.session.commit()
# print("called")
# db.drop_all()
# db.create_all()
# generate_test_data()
if __name__ == "__main__":
db.drop_all()
db.create_all()