Build and Push / build (release) Successful in 1m16s
- Add PostgreSQL database with async SQLAlchemy - Add Alembic migrations for schema management - Add User, Role, UserPreferences, ApiKey models - Add auth endpoints: /auth/me, /auth/users, /auth/users/sync-from-authentik - Add token validation via Authentik userinfo endpoint - Add bulk user sync from Authentik admin API - Add database health check to diagnostics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
"""
|
|
User Preferences Model
|
|
|
|
Stores user-specific settings like theme and default room.
|
|
"""
|
|
import uuid
|
|
|
|
from sqlalchemy import String, ForeignKey
|
|
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from src.db.database import Base
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from src.db.models.user import User
|
|
|
|
|
|
class UserPreferences(Base):
|
|
"""
|
|
User preferences model
|
|
|
|
Stores user-specific settings that persist across sessions.
|
|
Extended settings stored in preferences_json for flexibility.
|
|
"""
|
|
|
|
__tablename__ = "user_preferences"
|
|
|
|
user_id: Mapped[uuid.UUID] = mapped_column(
|
|
UUID(as_uuid=True),
|
|
ForeignKey("users.id", ondelete="CASCADE"),
|
|
primary_key=True,
|
|
)
|
|
theme: Mapped[str] = mapped_column(
|
|
String(20),
|
|
default="system",
|
|
nullable=False,
|
|
comment="Theme preference: system, light, dark",
|
|
)
|
|
default_room: Mapped[str] = mapped_column(
|
|
String(50),
|
|
default="front-hall",
|
|
nullable=False,
|
|
comment="Default room for housekeeping features",
|
|
)
|
|
preferences_json: Mapped[dict] = mapped_column(
|
|
JSONB,
|
|
default=dict,
|
|
nullable=False,
|
|
comment="Extended preferences as JSON",
|
|
)
|
|
|
|
# Relationships
|
|
user: Mapped["User"] = relationship(
|
|
"User",
|
|
back_populates="preferences",
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<UserPreferences user_id={self.user_id}>"
|