martian7777
feat: implement backend core with ORM models, authentication, and AI-driven telemetry diagnostics
e5be436 | """Declarative base and shared column mixins for ORM models.""" | |
| from __future__ import annotations | |
| import uuid | |
| from datetime import datetime | |
| from sqlalchemy import DateTime, Uuid, func | |
| from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column | |
| # Portable UUID column type: native ``UUID`` on PostgreSQL, ``CHAR(32)`` on | |
| # other backends (e.g. SQLite used in tests). Single source of truth. | |
| GUID = Uuid(as_uuid=True) | |
| class Base(DeclarativeBase): | |
| """Declarative base for all ORM models.""" | |
| class UUIDMixin: | |
| id: Mapped[uuid.UUID] = mapped_column( | |
| GUID, | |
| primary_key=True, | |
| default=uuid.uuid4, | |
| ) | |
| class TimestampMixin: | |
| created_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), | |
| server_default=func.now(), | |
| nullable=False, | |
| ) | |
| updated_at: Mapped[datetime] = mapped_column( | |
| DateTime(timezone=True), | |
| server_default=func.now(), | |
| onupdate=func.now(), | |
| nullable=False, | |
| ) | |