cnc-service/src/models.py
Torma Kristóf ef6a2861bd
All checks were successful
continuous-integration/drone/push Build is passing
fix relationship
2020-08-06 20:53:27 +02:00

44 lines
1.1 KiB
Python

#!/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 DeviceStatusEnum(enum.Enum):
error = "error"
online = "online"
offline = "offline"
class SensorStatusEnum(enum.Enum):
unknown = "unknown"
online = "online"
offline = "offline"
class Device(db.Model):
__tablename__ = 'device'
id = db.Column(db.Integer, primary_key=True)
deviceid = db.Column(db.String, nullable=False)
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")
class Sensor(db.Model):
__tablename__ = 'sensor'
id = db.Column(db.Integer, primary_key=True)
sensorid = db.Column(db.String, nullable=False)
status = db.Column(db.Enum(SensorStatusEnum), nullable=False)
device_id = db.Column(db.Integer, db.ForeignKey('device.id'))