-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
49 lines (40 loc) · 1.45 KB
/
manage.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
import click
import uvicorn
import os
from app.config import conf
import sentry_sdk
if not conf.debug and conf.sentry_dsn is not None and conf.sentry_dsn != "":
sentry_sdk.init(
dsn=conf.sentry_dsn,
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=1.0,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0,
)
@click.group(context_settings={'max_content_width': 150})
def cli():
pass
@cli.command()
@click.option('--host', default='127.0.0.1', help="Host, default=127.0.0.1")
@click.option('--port', default=3000, help="Port, default=3000")
def runserver(host, port):
uvicorn.run(
"app.main:app", host=host, port=port, reload=conf.debug,
log_level="debug"
)
@cli.command()
def gen_db_classes():
# This command can only support the SQLAlchemy < 2.0
# pip install --force-reinstall 'sqlalchemy<2.0.0'
# And after it:
# pip update sqlalchemy
url = f"mysql+pymysql://{conf.tidb_user}:{conf.tidb_password}@{conf.tidb_host}:{conf.tidb_port}" \
f"/{conf.tidb_db_name}"
if not conf.debug:
url += "?ssl_verify_cert=True&ssl_verify_identity=True"
os.system(f"sqlacodegen --generator dataclasses --outfile ./app/db/gen_instances.py {url}")
if __name__ == '__main__':
cli()