cnc-service/src/models.py

44 lines
1.1 KiB
Python
Raw Normal View History

2020-07-20 17:09:05 +02:00
#!/usr/bin/env python3
import enum
from sqlalchemy.sql import func
from db import db
"""
SQLAlchemy models
"""
__author__ = '@tormakris'
__copyright__ = "Copyright 2020, Birbnetes Team"
__module_name__ = "models"
__version__text__ = "1"
class StatusEnum(enum.Enum):
online = "online"
offline = "offline"
class DeviceStatusEnum(StatusEnum):
error = "error"
class SensorStatusEnum(StatusEnum):
unknown = "unknown"
class Device(db.Model):
__tablename__ = 'device'
2020-07-20 18:19:31 +02:00
id = db.Column(db.Integer, primary_key=True)
sensorid = db.Column(db.UUID, nullable=False)
2020-07-20 17:09:05 +02:00
status = db.Column(db.Enum(DeviceStatusEnum), nullable=False)
url = db.Column(db.String, nullable=False)
lastupdate = db.Column(db.TIMESTAMP, nullable=False, server_default=func.now(), onupdate=func.current_timestamp())
sensors = db.relationship("Sensor", nullable=True)
class Sensor(db.Model):
__tablename__ = 'sensor'
id = db.Column(db.UUID, primary_key=True)
status = db.Column(db.Enum(SensorStatusEnum), nullable=False)
device_id = db.Column(db.UUID, db.ForeignKey('device.id'))