mirror of
https://github.com/veops/cmdb.git
synced 2025-08-07 22:17:37 +08:00
add command cmdb-index-table-upgrade
This commit is contained in:
@@ -5,6 +5,9 @@ from flask.cli import with_appcontext
|
||||
@click.command()
|
||||
@with_appcontext
|
||||
def init_acl():
|
||||
"""
|
||||
acl init
|
||||
"""
|
||||
from api.models.acl import Role
|
||||
from api.models.acl import App
|
||||
from api.tasks.acl import role_rebuild
|
||||
|
@@ -29,6 +29,7 @@ from api.lib.perm.acl.role import RoleCRUD
|
||||
from api.lib.perm.acl.user import UserCRUD
|
||||
from api.models.acl import App
|
||||
from api.models.acl import ResourceType
|
||||
from api.models.cmdb import Attribute
|
||||
from api.models.cmdb import CI
|
||||
from api.models.cmdb import CIRelation
|
||||
from api.models.cmdb import CIType
|
||||
@@ -200,6 +201,9 @@ def del_user(user):
|
||||
@click.command()
|
||||
@with_appcontext
|
||||
def cmdb_counter():
|
||||
"""
|
||||
Dashboard calculations
|
||||
"""
|
||||
from api.lib.cmdb.cache import CMDBCounterCache
|
||||
|
||||
while True:
|
||||
@@ -217,6 +221,9 @@ def cmdb_counter():
|
||||
@click.command()
|
||||
@with_appcontext
|
||||
def cmdb_trigger():
|
||||
"""
|
||||
Trigger execution
|
||||
"""
|
||||
current_day = datetime.datetime.today().strftime("%Y-%m-%d")
|
||||
trigger2cis = dict()
|
||||
trigger2completed = dict()
|
||||
@@ -259,3 +266,33 @@ def cmdb_trigger():
|
||||
|
||||
i += 1
|
||||
time.sleep(10)
|
||||
|
||||
|
||||
@click.command()
|
||||
@with_appcontext
|
||||
def cmdb_index_table_upgrade():
|
||||
"""
|
||||
Migrate data from tables c_value_integers, c_value_floats, and c_value_datetime
|
||||
"""
|
||||
for attr in Attribute.get_by(to_dict=False):
|
||||
if attr.value_type not in {ValueTypeEnum.TEXT, ValueTypeEnum.JSON}:
|
||||
attr.update(is_index=True)
|
||||
|
||||
from api.models.cmdb import CIValueInteger, CIIndexValueInteger
|
||||
from api.models.cmdb import CIValueFloat, CIIndexValueFloat
|
||||
from api.models.cmdb import CIValueDateTime, CIIndexValueDateTime
|
||||
|
||||
for i in CIValueInteger.get_by(to_dict=False):
|
||||
CIIndexValueInteger.create(ci_id=i.ci_id, attr_id=i.attr_id, value=i.value, commit=False)
|
||||
i.delete(commit=False)
|
||||
db.session.commit()
|
||||
|
||||
for i in CIValueFloat.get_by(to_dict=False):
|
||||
CIIndexValueFloat.create(ci_id=i.ci_id, attr_id=i.attr_id, value=i.value, commit=False)
|
||||
i.delete(commit=False)
|
||||
db.session.commit()
|
||||
|
||||
for i in CIValueDateTime.get_by(to_dict=False):
|
||||
CIIndexValueDateTime.create(ci_id=i.ci_id, attr_id=i.attr_id, value=i.value, commit=False)
|
||||
i.delete(commit=False)
|
||||
db.session.commit()
|
||||
|
@@ -19,7 +19,7 @@ class InitEmployee(object):
|
||||
|
||||
def import_user_from_acl(self):
|
||||
"""
|
||||
从ACL导入用户
|
||||
Import users from ACL
|
||||
"""
|
||||
|
||||
acl = ACLManager('acl')
|
||||
@@ -149,7 +149,7 @@ class InitDepartment(object):
|
||||
@with_appcontext
|
||||
def init_import_user_from_acl():
|
||||
"""
|
||||
从ACL导入用户
|
||||
Import users from ACL
|
||||
"""
|
||||
InitEmployee().import_user_from_acl()
|
||||
|
||||
@@ -158,7 +158,7 @@ def init_import_user_from_acl():
|
||||
@with_appcontext
|
||||
def init_department():
|
||||
"""
|
||||
初始化 部门
|
||||
Department initialization
|
||||
"""
|
||||
InitDepartment().init()
|
||||
InitDepartment().create_acl_role_with_department()
|
||||
|
Reference in New Issue
Block a user