30 lines
851 B
Python
30 lines
851 B
Python
"""Database models."""
|
|
|
|
from typing import TYPE_CHECKING
|
|
from sqlalchemy import Column, Integer, String, DateTime, Boolean
|
|
from datetime import datetime
|
|
|
|
if TYPE_CHECKING:
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
|
|
Base = DeclarativeBase
|
|
else:
|
|
from baby_monitor.repositories.dependencies.get_database import Base
|
|
|
|
|
|
class User(Base):
|
|
"""User database model."""
|
|
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
username = Column(String, unique=True, index=True, nullable=False)
|
|
hashed_password = Column(String, nullable=False)
|
|
is_admin = Column(Boolean, default=False, nullable=False)
|
|
created_at = Column(
|
|
DateTime(timezone=True), default=datetime.utcnow, nullable=False
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<User(id={self.id}, username='{self.username}')>"
|