mirror of https://github.com/veops/cmdb.git
废弃3个表: c_value_datetime c_value_floats c_value_integers, time类型属性值增加写入校验
This commit is contained in:
parent
341e687987
commit
83e9172722
|
@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
|
@ -31,7 +32,8 @@ class ValueTypeMap(object):
|
||||||
ValueTypeEnum.INT: string2int,
|
ValueTypeEnum.INT: string2int,
|
||||||
ValueTypeEnum.FLOAT: float,
|
ValueTypeEnum.FLOAT: float,
|
||||||
ValueTypeEnum.TEXT: lambda x: escape(x).encode('utf-8').decode('utf-8'),
|
ValueTypeEnum.TEXT: lambda x: escape(x).encode('utf-8').decode('utf-8'),
|
||||||
ValueTypeEnum.TIME: lambda x: escape(x).encode('utf-8').decode('utf-8'),
|
ValueTypeEnum.TIME: lambda x: re.compile(r'\d\d:\d\d:\d\d').findall(
|
||||||
|
escape(x).encode('utf-8').decode('utf-8'))[0],
|
||||||
ValueTypeEnum.DATETIME: str2datetime,
|
ValueTypeEnum.DATETIME: str2datetime,
|
||||||
ValueTypeEnum.DATE: str2datetime,
|
ValueTypeEnum.DATE: str2datetime,
|
||||||
ValueTypeEnum.JSON: lambda x: json.loads(x) if isinstance(x, six.string_types) and x else x,
|
ValueTypeEnum.JSON: lambda x: json.loads(x) if isinstance(x, six.string_types) and x else x,
|
||||||
|
@ -61,15 +63,11 @@ class ValueTypeMap(object):
|
||||||
ValueTypeEnum.INT: model.IntegerChoice,
|
ValueTypeEnum.INT: model.IntegerChoice,
|
||||||
ValueTypeEnum.FLOAT: model.FloatChoice,
|
ValueTypeEnum.FLOAT: model.FloatChoice,
|
||||||
ValueTypeEnum.TEXT: model.TextChoice,
|
ValueTypeEnum.TEXT: model.TextChoice,
|
||||||
|
ValueTypeEnum.TIME: model.TextChoice,
|
||||||
}
|
}
|
||||||
|
|
||||||
table = {
|
table = {
|
||||||
ValueTypeEnum.INT: model.CIValueInteger,
|
|
||||||
ValueTypeEnum.TEXT: model.CIValueText,
|
ValueTypeEnum.TEXT: model.CIValueText,
|
||||||
ValueTypeEnum.DATETIME: model.CIValueDateTime,
|
|
||||||
ValueTypeEnum.DATE: model.CIValueDateTime,
|
|
||||||
ValueTypeEnum.TIME: model.CIValueText,
|
|
||||||
ValueTypeEnum.FLOAT: model.CIValueFloat,
|
|
||||||
ValueTypeEnum.JSON: model.CIValueJson,
|
ValueTypeEnum.JSON: model.CIValueJson,
|
||||||
'index_{0}'.format(ValueTypeEnum.INT): model.CIIndexValueInteger,
|
'index_{0}'.format(ValueTypeEnum.INT): model.CIIndexValueInteger,
|
||||||
'index_{0}'.format(ValueTypeEnum.TEXT): model.CIIndexValueText,
|
'index_{0}'.format(ValueTypeEnum.TEXT): model.CIIndexValueText,
|
||||||
|
@ -81,12 +79,7 @@ class ValueTypeMap(object):
|
||||||
}
|
}
|
||||||
|
|
||||||
table_name = {
|
table_name = {
|
||||||
ValueTypeEnum.INT: 'c_value_integers',
|
|
||||||
ValueTypeEnum.TEXT: 'c_value_texts',
|
ValueTypeEnum.TEXT: 'c_value_texts',
|
||||||
ValueTypeEnum.DATETIME: 'c_value_datetime',
|
|
||||||
ValueTypeEnum.DATE: 'c_value_datetime',
|
|
||||||
ValueTypeEnum.TIME: 'c_value_texts',
|
|
||||||
ValueTypeEnum.FLOAT: 'c_value_floats',
|
|
||||||
ValueTypeEnum.JSON: 'c_value_json',
|
ValueTypeEnum.JSON: 'c_value_json',
|
||||||
'index_{0}'.format(ValueTypeEnum.INT): 'c_value_index_integers',
|
'index_{0}'.format(ValueTypeEnum.INT): 'c_value_index_integers',
|
||||||
'index_{0}'.format(ValueTypeEnum.TEXT): 'c_value_index_texts',
|
'index_{0}'.format(ValueTypeEnum.TEXT): 'c_value_index_texts',
|
||||||
|
@ -117,8 +110,11 @@ class TableMap(object):
|
||||||
@property
|
@property
|
||||||
def table(self):
|
def table(self):
|
||||||
attr = AttributeCache.get(self.attr_name) if not self.attr else self.attr
|
attr = AttributeCache.get(self.attr_name) if not self.attr else self.attr
|
||||||
if self.is_index is None:
|
if attr.value_type != ValueTypeEnum.TEXT and attr.value_type != ValueTypeEnum.JSON:
|
||||||
|
self.is_index = True
|
||||||
|
elif self.is_index is None:
|
||||||
self.is_index = attr.is_index
|
self.is_index = attr.is_index
|
||||||
|
|
||||||
i = "index_{0}".format(attr.value_type) if self.is_index else attr.value_type
|
i = "index_{0}".format(attr.value_type) if self.is_index else attr.value_type
|
||||||
|
|
||||||
return ValueTypeMap.table.get(i)
|
return ValueTypeMap.table.get(i)
|
||||||
|
@ -126,8 +122,11 @@ class TableMap(object):
|
||||||
@property
|
@property
|
||||||
def table_name(self):
|
def table_name(self):
|
||||||
attr = AttributeCache.get(self.attr_name) if not self.attr else self.attr
|
attr = AttributeCache.get(self.attr_name) if not self.attr else self.attr
|
||||||
if self.is_index is None:
|
if attr.value_type != ValueTypeEnum.TEXT and attr.value_type != ValueTypeEnum.JSON:
|
||||||
|
self.is_index = True
|
||||||
|
elif self.is_index is None:
|
||||||
self.is_index = attr.is_index
|
self.is_index = attr.is_index
|
||||||
|
|
||||||
i = "index_{0}".format(attr.value_type) if self.is_index else attr.value_type
|
i = "index_{0}".format(attr.value_type) if self.is_index else attr.value_type
|
||||||
|
|
||||||
return ValueTypeMap.table_name.get(i)
|
return ValueTypeMap.table_name.get(i)
|
||||||
|
|
|
@ -249,26 +249,26 @@ class CIIndexValueDateTime(Model):
|
||||||
__table_args__ = (db.Index("datetime_attr_value_index", "attr_id", "value"),)
|
__table_args__ = (db.Index("datetime_attr_value_index", "attr_id", "value"),)
|
||||||
|
|
||||||
|
|
||||||
class CIValueInteger(Model):
|
# class CIValueInteger(Model):
|
||||||
__tablename__ = "c_value_integers"
|
# __tablename__ = "c_value_integers"
|
||||||
|
#
|
||||||
ci_id = db.Column(db.Integer, db.ForeignKey('c_cis.id'), nullable=False)
|
# ci_id = db.Column(db.Integer, db.ForeignKey('c_cis.id'), nullable=False)
|
||||||
attr_id = db.Column(db.Integer, db.ForeignKey('c_attributes.id'), nullable=False)
|
# attr_id = db.Column(db.Integer, db.ForeignKey('c_attributes.id'), nullable=False)
|
||||||
value = db.Column(db.Integer, nullable=False)
|
# value = db.Column(db.Integer, nullable=False)
|
||||||
|
#
|
||||||
ci = db.relationship("CI", backref="c_value_integers.ci_id")
|
# ci = db.relationship("CI", backref="c_value_integers.ci_id")
|
||||||
attr = db.relationship("Attribute", backref="c_value_integers.attr_id")
|
# attr = db.relationship("Attribute", backref="c_value_integers.attr_id")
|
||||||
|
#
|
||||||
|
#
|
||||||
class CIValueFloat(Model):
|
# class CIValueFloat(Model):
|
||||||
__tablename__ = "c_value_floats"
|
# __tablename__ = "c_value_floats"
|
||||||
|
#
|
||||||
ci_id = db.Column(db.Integer, db.ForeignKey('c_cis.id'), nullable=False)
|
# ci_id = db.Column(db.Integer, db.ForeignKey('c_cis.id'), nullable=False)
|
||||||
attr_id = db.Column(db.Integer, db.ForeignKey('c_attributes.id'), nullable=False)
|
# attr_id = db.Column(db.Integer, db.ForeignKey('c_attributes.id'), nullable=False)
|
||||||
value = db.Column(DOUBLE, nullable=False)
|
# value = db.Column(DOUBLE, nullable=False)
|
||||||
|
#
|
||||||
ci = db.relationship("CI", backref="c_value_floats.ci_id")
|
# ci = db.relationship("CI", backref="c_value_floats.ci_id")
|
||||||
attr = db.relationship("Attribute", backref="c_value_floats.attr_id")
|
# attr = db.relationship("Attribute", backref="c_value_floats.attr_id")
|
||||||
|
|
||||||
|
|
||||||
class CIValueText(Model):
|
class CIValueText(Model):
|
||||||
|
@ -282,15 +282,15 @@ class CIValueText(Model):
|
||||||
attr = db.relationship("Attribute", backref="c_value_texts.attr_id")
|
attr = db.relationship("Attribute", backref="c_value_texts.attr_id")
|
||||||
|
|
||||||
|
|
||||||
class CIValueDateTime(Model):
|
# class CIValueDateTime(Model):
|
||||||
__tablename__ = "c_value_datetime"
|
# __tablename__ = "c_value_datetime"
|
||||||
|
#
|
||||||
ci_id = db.Column(db.Integer, db.ForeignKey('c_cis.id'), nullable=False)
|
# ci_id = db.Column(db.Integer, db.ForeignKey('c_cis.id'), nullable=False)
|
||||||
attr_id = db.Column(db.Integer, db.ForeignKey('c_attributes.id'), nullable=False)
|
# attr_id = db.Column(db.Integer, db.ForeignKey('c_attributes.id'), nullable=False)
|
||||||
value = db.Column(db.DateTime, nullable=False)
|
# value = db.Column(db.DateTime, nullable=False)
|
||||||
|
#
|
||||||
ci = db.relationship("CI", backref="c_value_datetime.ci_id")
|
# ci = db.relationship("CI", backref="c_value_datetime.ci_id")
|
||||||
attr = db.relationship("Attribute", backref="c_value_datetime.attr_id")
|
# attr = db.relationship("Attribute", backref="c_value_datetime.attr_id")
|
||||||
|
|
||||||
|
|
||||||
class CIValueJson(Model):
|
class CIValueJson(Model):
|
||||||
|
|
Loading…
Reference in New Issue