Пример #1
0
    group_uid = generate_uuid(size=6)
    group = db.session.query(db.func.count(Group.id)) \
        .filter(Group.groupID == group_uid).scalar()
    if group:
        group_uid = random_group_uid()
    return group_uid


GroupDevice = db.Table(
    'groups_devices',
    db.Column('deviceIntID',
              db.Integer,
              db.ForeignKey('devices.id',
                            onupdate="CASCADE",
                            ondelete="CASCADE"),
              primary_key=True),
    db.Column('groupID',
              db.String(6),
              db.ForeignKey('groups.groupID'),
              primary_key=True),
)

CertDevice = db.Table(
    'certs_devices',
    db.Column('deviceIntID',
              db.Integer,
              db.ForeignKey('devices.id',
                            onupdate="CASCADE",
                            ondelete="CASCADE"),
              primary_key=True),
Пример #2
0
def get_default_device_count():
    """ Get the number of devices that tenant can manage """

    base_config = BaseConfig()
    default_devices_limit = base_config.config['DEFAULT_DEVICES_LIMIT']
    return str(default_devices_limit)


UserGroup = db.Table(
    'users_groups',
    db.Column('userIntID',
              db.Integer,
              db.ForeignKey('users.id', onupdate="CASCADE",
                            ondelete="CASCADE"),
              primary_key=True),
    db.Column('groupID',
              db.String(6),
              db.ForeignKey('groups.groupID',
                            onupdate="CASCADE",
                            ondelete="CASCADE"),
              primary_key=True),
)


class User(BaseModel):
    __tablename__ = 'users'
    username = db.Column(db.String(50))  # 用户名
    nickname = db.Column(db.String(50))  # 昵称
    email = db.Column(db.String(50), unique=True)  # 邮箱
    department = db.Column(db.String(50))  # 部门
    phone = db.Column(db.String(50))  # 电话
Пример #3
0
from sqlalchemy.dialects.postgresql.json import JSONB

from actor_libs.database.orm import BaseModel, db

__all__ = ['RuleAction', 'Rule', 'Action']

RuleAction = db.Table(
    'rules_actions',
    db.Column(
        'ruleIntID', db.Integer,
        db.ForeignKey('rules.id', onupdate="CASCADE", ondelete="CASCADE")),
    db.Column('actionIntID', db.Integer, db.ForeignKey('actions.id')),
)


class Rule(BaseModel):
    __tablename__ = 'rules'
    ruleName = db.Column(db.String(50))
    remark = db.Column(db.String(50))
    enable = db.Column(db.SmallInteger, default=1)
    sql = db.Column(db.String)
    fromTopics = db.Column(JSONB)
    scopeData = db.Column(JSONB)
    ruleType = db.Column(db.SmallInteger)
    userIntID = db.Column(db.Integer, db.ForeignKey('users.id'))
    tenantID = db.Column(
        db.String,
        db.ForeignKey('tenants.tenantID',
                      onupdate="CASCADE",
                      ondelete="CASCADE"))
Пример #4
0
    productID = db.Column(db.String(6), default=random_product_uid, unique=True)  # 产品标识
    productName = db.Column(db.String(50))  # 产品名称
    description = db.Column(db.String(300))  # 产品描述
    cloudProtocol = db.Column(db.SmallInteger, server_default='1')  # 云端协议, 网关类型产品显示为上联协议
    gatewayProtocol = db.Column(db.Integer)  # 网关协议
    productType = db.Column(db.SmallInteger, server_default='1')  # 产品类型1:设备,2:网关
    userIntID = db.Column(db.Integer, db.ForeignKey('users.id'))
    devices = db.relationship('Device', backref='products', lazy='dynamic')


StreamPoint = db.Table(
    'streams_points',
    db.Column('dataPointIntID',
              db.Integer,
              db.ForeignKey('data_points.id'), primary_key=True),
    db.Column('dataStreamIntID',
              db.Integer,
              db.ForeignKey('data_streams.id',
                            onupdate="CASCADE",
                            ondelete="CASCADE"), primary_key=True),
)


class DataStream(BaseModel):
    __tablename__ = 'data_streams'
    streamID = db.Column(db.String(50))  # data stream identifier
    streamName = db.Column(db.String(50))
    streamType = db.Column(db.SmallInteger)  # 1:deviceUp, 2:deviceDown
    topic = db.Column(db.String(500))
    description = db.Column(db.String(300))
    dataPoints = db.relationship('DataPoint', secondary=StreamPoint,
Пример #5
0
    """ Generate a 6-bit app identifier """

    app_uid = generate_uuid(size=6)
    application = db.session.query(func.count(Application.id)) \
        .filter(Application.appID == app_uid).scalar()
    if application:
        app_uid = random_app_uid()
    return app_uid


ApplicationGroup = db.Table(
    'applications_groups',
    db.Column(
        'applicationIntID', db.Integer,
        db.ForeignKey('applications.id',
                      onupdate="CASCADE",
                      ondelete="CASCADE")),
    db.Column(
        'groupID', db.String,
        db.ForeignKey('groups.groupID', onupdate="CASCADE",
                      ondelete="CASCADE")),
)


class Application(BaseModel):
    __tablename__ = 'applications'
    appID = db.Column(db.String(6), default=random_app_uid, unique=True)
    appName = db.Column(db.String(50))
    appToken = db.Column(db.String(100), default=generate_uuid)  # 32-bit
    expiredAt = db.Column(db.DateTime)  # app token expired time
    description = db.Column(db.String(300))
    appStatus = db.Column(db.Integer)  # 0:blocked,1:run