1 Star 0 Fork 45

SoftwareDevTest/codo-cmdb

forked from opendevops/codo-cmdb 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
db_sync.py 996 Bytes
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Author : shenshuo
Date : 2018/12/24
Desc :
"""
from models.server import Base
from models.db import Base as ABase
from websdk.consts import const
from settings import settings as app_settings
# ORM创建表结构
from sqlalchemy import create_engine
default_configs = app_settings[const.DB_CONFIG_ITEM][const.DEFAULT_DB_KEY]
engine = create_engine('mysql+pymysql://%s:%s@%s:%s/%s?charset=utf8' % (
default_configs.get(const.DBUSER_KEY),
default_configs.get(const.DBPWD_KEY),
default_configs.get(const.DBHOST_KEY),
default_configs.get(const.DBPORT_KEY),
default_configs.get(const.DBNAME_KEY),
), encoding='utf-8', echo=True)
def create():
Base.metadata.create_all(engine)
ABase.metadata.create_all(engine)
print('[Success] 表结构创建成功!')
def drop():
Base.metadata.drop_all(engine)
ABase.metadata.drop_all(engine)
if __name__ == '__main__':
create()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/cloud-devops-softwareluke/codo-cmdb.git
[email protected]:cloud-devops-softwareluke/codo-cmdb.git
cloud-devops-softwareluke
codo-cmdb
codo-cmdb
master

搜索帮助