-
Notifications
You must be signed in to change notification settings - Fork 97
/
db_sync.py
54 lines (46 loc) · 1.7 KB
/
db_sync.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
50
51
52
53
54
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Contact : [email protected]
Author : shenshuo
Date : 2018/12/24
Desc :
"""
from models.alert import Base as alert_base
from models.fault_mg import Base as falut_base
from models.project_mg import Base as project_base
from models.event_record import Base as event_record_base
from models.paid_mg import Base as paid_base
from models.zabbix_mg import Base as zabbix_base
from models.ops_tools import Base as ops_tools_base
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():
alert_base.metadata.create_all(engine)
falut_base.metadata.create_all(engine)
project_base.metadata.create_all(engine)
event_record_base.metadata.create_all(engine)
paid_base.metadata.create_all(engine)
zabbix_base.metadata.create_all(engine)
ops_tools_base.metadata.create_all(engine)
print('[Success] 表结构创建成功!')
def drop():
alert_base.metadata.drop_all(engine)
falut_base.metadata.drop_all(engine)
project_base.metadata.drop_all(engine)
event_record_base.metadata.drop_all(engine)
paid_base.metadata.drop_all(engine)
zabbix_base.metadata.drop_all(engine)
ops_tools_base.metadata.drop_all(engine)
if __name__ == '__main__':
create()