signal-tracker / models.py
vumichien's picture
up
7e6b994
raw
history blame
1.72 kB
from sqlalchemy import Column, Integer, String, Float, DateTime, Boolean
import uuid
from pydantic import BaseModel
from typing import List
from database import Base
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
username = Column(String, unique=True, index=True)
email = Column(String, unique=True, index=True)
password = Column(String)
is_admin = Column(Boolean, default=False)
last_login = Column(DateTime, nullable=True)
is_active = Column(Boolean, default=True)
class StatusRecord(Base):
__tablename__ = "status_records"
id = Column(Integer, primary_key=True, index=True)
uuid = Column(String, unique=True, default=lambda: str(uuid.uuid4()))
device_id = Column(String, index=True)
latitude = Column(Float)
longitude = Column(Float)
timestamp = Column(DateTime)
connect_status = Column(Integer) # 0 or 1
class SystemSetting(Base):
__tablename__ = "system_settings"
id = Column(Integer, primary_key=True, index=True)
check_connect_period = Column(Integer, default=10)
data_sync_period = Column(Integer, default=3600)
get_config_period = Column(Integer, default=60)
point_distance = Column(Integer, default=5)
class Device(Base):
__tablename__ = "devices"
id = Column(Integer, primary_key=True, index=True)
name = Column(String)
description = Column(String)
device_id = Column(String, unique=True, index=True)
password = Column(String)
class StatusRecordCreate(BaseModel):
uuid: str
latitude: float
longitude: float
timestamp: str
connect_status: int
class StatusRecordBatch(BaseModel):
records: List[StatusRecordCreate]