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
2020-08-06 16:57:40 +02:00
from sqlalchemy.dialects.postgresql import UUID
2020-07-20 17:09:05 +02:00
from sqlalchemy.sql import func
from db import db
"""
SQLAlchemy models
"""
__author__ = '@tormakris'
__copyright__ = "Copyright 2020, Birbnetes Team"
__module_name__ = "models"
__version__text__ = "1"
2020-08-06 16:37:44 +02:00
class DeviceStatusEnum(enum.Enum):
error = "error"
2020-07-20 17:09:05 +02:00
online = "online"
offline = "offline"
2020-08-06 16:37:44 +02:00
class SensorStatusEnum(enum.Enum):
2020-07-20 17:09:05 +02:00
unknown = "unknown"
2020-08-06 16:37:44 +02:00
online = "online"
offline = "offline"
2020-07-20 17:09:05 +02:00
class Device(db.Model):
__tablename__ = 'device'
2020-07-20 18:19:31 +02:00
id = db.Column(db.Integer, primary_key=True)
2020-08-06 19:57:16 +02:00
sensorid = db.Column(UUID(as_uuid=True), nullable=True)
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())
2020-08-06 19:57:16 +02:00
sensors = db.relationship("Sensor")
2020-07-20 17:09:05 +02:00
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'))