2022-03-03 13:49:26 +01:00
|
|
|
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
|
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
|
|
|
|
from .database import Base
|
|
|
|
|
|
|
|
|
|
|
|
class User(Base):
|
|
|
|
__tablename__ = "user_accounts"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
|
|
email = Column(String, unique=True, index=True)
|
2022-04-04 01:02:29 +02:00
|
|
|
username = Column(String, unique=True, index=True)
|
2022-04-13 04:24:06 +02:00
|
|
|
hashed_password = Column(String) # TODO: make not null
|
2022-03-16 20:29:34 +01:00
|
|
|
passwd_salt = Column(String)
|
2022-03-03 13:49:26 +01:00
|
|
|
is_active = Column(Boolean, default=True)
|
|
|
|
|
2022-03-16 20:29:34 +01:00
|
|
|
authorized_devices = relationship("IotEntity", secondary= 'user_iot_link')
|
2022-03-03 13:49:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
class IotEntity(Base):
|
|
|
|
__tablename__ = "iot_entities"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
|
|
description = Column(String, index=True)
|
2022-03-06 14:13:50 +01:00
|
|
|
owner_id = Column(Integer, ForeignKey("user_accounts.id"))
|
2022-03-03 13:49:26 +01:00
|
|
|
|
2022-03-16 20:29:34 +01:00
|
|
|
authorized_users = relationship("User", secondary= 'user_iot_link')
|
|
|
|
|
|
|
|
class UserAuthToIoTDev(Base):
|
|
|
|
__tablename__ = "user_iot_link"
|
|
|
|
|
2022-04-03 14:51:36 +02:00
|
|
|
user_id = Column(Integer, ForeignKey('user_accounts.id'), primary_key=True, index=True)
|
|
|
|
iot_entity_id = Column(Integer, ForeignKey('iot_entities.id'), primary_key=True, index=True)
|