Skip to content

Commit

Permalink
Merge pull request #12 from jokester/cli-add-migrate-command
Browse files Browse the repository at this point in the history
init db in "migrate" cli command
  • Loading branch information
jokester authored Apr 22, 2024
2 parents 13eb0f1 + 20d329b commit 7158d81
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
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()

0 comments on commit 7158d81

Please sign in to comment.