Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init db in "migrate" cli command #12

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ def create_app():
connect_db(app.config)
# 注册api蓝本
register_apis(app)
# 初始化插件
babel.init_app(app)
apikit.init_app(app)

logger.info("-" * 50)
logger.info("站点支持语言: " + str([str(i) for i in babel.list_translations()]))
oss.init(app.config) # 文件储存

return app


def init_db(app: Flask):
# 初始化角色,语言
from app.models.language import Language
from app.models.project import ProjectRole
Expand All @@ -100,22 +112,9 @@ def create_app():
ProjectRole.init_system_roles()
Language.init_system_languages()
SiteSetting.init_site_setting()
# 初始化插件
babel.init_app(app)
apikit.init_app(app)

logger.info("-" * 50)
logger.info("站点支持语言: " + str([str(i) for i in babel.list_translations()]))
oss.init(app.config) # 文件储存

admin_user = create_or_override_default_admin(app)
create_default_team(admin_user)

# from app.tasks.ocr import recover_ocr_tasks

# recover_ocr_tasks()
return app


def create_celery() -> Celery:
# 为celery创建app
Expand Down
22 changes: 17 additions & 5 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@

import click

from app import create_app
import logging

from app import create_app, init_db

logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s %(name)s %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S%z",
force=True,
)

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


@click.group()
Expand All @@ -19,12 +31,12 @@ def docs():


@click.command()
def run():
def migrate():
"""
运行开发服务器
Initialize the database
"""
app = create_app()
app.run(host="0.0.0.0", port=5001)
init_db(app)


@click.command()
Expand Down Expand Up @@ -79,9 +91,9 @@ def local(action):
)


main.add_command(run)
main.add_command(local)
main.add_command(docs)
main.add_command(migrate)

if __name__ == "__main__":
main()