-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset.py
67 lines (53 loc) · 1.46 KB
/
reset.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
from sqlalchemy import create_engine
import secret
from app import configured_app
from config import db_name
from models.base_model import db
from models.board import Board
from models.topic import Topic
from models.user import User
from models.reply import Reply
from models.message import Messages
def reset_database():
url = 'mysql+pymysql://root:{}@localhost/?charset=utf8mb4'.format(
secret.database_password
)
e = create_engine(url, echo=True)
with e.connect() as c:
c.execute('DROP DATABASE IF EXISTS {}'.format(db_name))
c.execute('CREATE DATABASE {} CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci'.format(db_name))
c.execute('USE {}'.format(db_name))
db.metadata.create_all(bind=e)
def generate_fake_date():
form = dict(
username='test',
password='123'
)
u = User.register(form)
form = dict(
username='test2',
password='123123',
)
g = User.register(form)
form = dict(
title='all'
)
b = Board.new(form)
form = dict(
title='test'
)
b = Board.new(form)
with open('markdown_demo.md', encoding='utf8') as f:
content = f.read()
form = dict(
title='markdown demo',
board_id=b.id,
content=content,
)
Topic.add(form, u.id)
Topic.add(form, g.id)
if __name__ == '__main__':
app = configured_app()
with app.app_context():
reset_database()
generate_fake_date()