You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
3.5 KiB
75 lines
3.5 KiB
from minibase.app import db
|
|
from datetime import datetime
|
|
|
|
class nbiotDevice(db.Model):
|
|
__tablename__ = 'nbiotDevice'
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
name = db.Column(db.String(50), nullable=False)
|
|
model = db.Column(db.String(50), nullable=False)
|
|
serial_no = db.Column(db.String(50), nullable=False)
|
|
device_id = db.Column(db.String(30), nullable=False)
|
|
imsi = db.Column(db.String(30), nullable=False)
|
|
iccid = db.Column(db.String(50), nullable=False)
|
|
ip = db.Column(db.String(20), nullable=True)
|
|
port = db.Column(db.String(20), nullable=True)
|
|
registration_date = db.Column(db.DateTime, nullable=True)
|
|
activation_date = db.Column(db.DateTime, nullable=True)
|
|
deactivation_date = db.Column(db.DateTime, nullable=True)
|
|
image_file = db.Column(db.String(20), nullable=False, default='def_sensor.png')
|
|
created = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
|
|
updated = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
status_id = db.Column(db.Integer, db.ForeignKey('nbiotDeviceStatus.id'), nullable=False)
|
|
type_id = db.Column(db.Integer, db.ForeignKey('nbiotDeviceType.id'), nullable=False)
|
|
area_id = db.Column(db.Integer, db.ForeignKey('nbiotDeviceArea.id'), nullable=False)
|
|
|
|
# Foreign Keys
|
|
company_manufacturer_id = db.Column(db.Integer, db.ForeignKey('companies.id'))
|
|
company_owner_id = db.Column(db.Integer, db.ForeignKey('companies.id'))
|
|
device_user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
|
device_owner_id = db.Column(db.Integer, db.ForeignKey('users.id'))
|
|
|
|
# Relationships
|
|
company_manufacturer = db.relationship("Companies", foreign_keys=[company_manufacturer_id], back_populates="manufactured_devices")
|
|
company_owner = db.relationship("Companies", foreign_keys=[company_owner_id], back_populates="owned_devices")
|
|
device_user = db.relationship("Users", foreign_keys=[device_user_id], back_populates="used_devices")
|
|
device_owner = db.relationship("Users", foreign_keys=[device_owner_id], back_populates="owned_devices")
|
|
|
|
class nbiotDeviceStatus(db.Model):
|
|
__tablename__ = 'nbiotDeviceStatus'
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
name = db.Column(db.String(50), nullable=False)
|
|
description = db.Column(db.String(300), nullable=False)
|
|
devices = db.relationship('nbiotDevice', backref='status', lazy='dynamic')
|
|
|
|
|
|
class nbiotDeviceType(db.Model):
|
|
__tablename__ = 'nbiotDeviceType'
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
name = db.Column(db.String(50), nullable=False)
|
|
description = db.Column(db.String(300), nullable=False)
|
|
devices = db.relationship('nbiotDevice', backref='type', lazy='dynamic')
|
|
|
|
|
|
class nbiotDeviceArea(db.Model):
|
|
__tablename__ = 'nbiotDeviceArea'
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
name = db.Column(db.String(50), nullable=False)
|
|
description = db.Column(db.String(300), nullable=False)
|
|
devices = db.relationship('nbiotDevice', backref='area', lazy='dynamic')
|
|
|
|
|
|
class waterDetector(db.Model):
|
|
__tablename__ = 'waterDetector'
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
pins = db.Column(db.Integer, nullable=True)
|
|
alarms = db.Column(db.Integer, nullable=True)
|
|
voltage = db.Column(db.Integer, nullable=True)
|
|
signal = db.Column(db.Integer, nullable=True)
|
|
sleepTime = db.Column(db.Integer, nullable=True)
|
|
scanTime = db.Column(db.Integer, nullable=True)
|
|
holdTime = db.Column(db.Integer, nullable=True)
|
|
timeStamp = db.Column(db.DateTime, nullable=False)
|
|
|