|
@@ -0,0 +1,34 @@
|
|
|
+from sqlalchemy import create_engine
|
|
|
+from sqlalchemy_utils import database_exists, create_database
|
|
|
+
|
|
|
+from app import Config
|
|
|
+from app.modle import Base
|
|
|
+from app.webapp import application
|
|
|
+
|
|
|
+
|
|
|
+@application.cli.command('dbinit')
|
|
|
+def dbinit():
|
|
|
+ """初始化数据库,存入任务模板参数"""
|
|
|
+
|
|
|
+ print('initialize db ...')
|
|
|
+
|
|
|
+ config = Config()
|
|
|
+
|
|
|
+ uri = f'postgresql+psycopg2://{config.database.USER}:{config.database.PASSWORD}@{config.database.HOST}:{config.database.PORT}/{config.database.DB}'
|
|
|
+
|
|
|
+ engine = create_engine(uri)
|
|
|
+
|
|
|
+ # 判断数据库是否存在,如果不存在则创建一个
|
|
|
+ if not database_exists(engine.url):
|
|
|
+ create_database(engine.url)
|
|
|
+
|
|
|
+ Base.metadata.create_all(engine)
|
|
|
+
|
|
|
+ print('initialize db ok ...\n')
|
|
|
+
|
|
|
+ print('Please Enter Ctrl+C to exit ...')
|
|
|
+
|
|
|
+
|
|
|
+@application.cli.command('ceshi')
|
|
|
+def ceshi():
|
|
|
+ print('this is a test')
|